event.H

Go to the documentation of this file.
00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #ifndef ARCHON_X3D_EVENT_H
00021 #define ARCHON_X3D_EVENT_H
00022 
00029 #include <archon/x3d/server/type.H>
00030 #include <archon/x3d/server/node.H>
00031 
00032 namespace Archon
00033 {
00034   namespace X3D
00035   {
00036     struct Event;
00037 
00038 
00042     struct RouteTail: RefObjectBase
00043     {
00044       virtual void cascadeEvent(const Event *) const = 0;
00045 
00046       const BackRef<NodeBase> sourceNode;
00047       const FieldBase *const sourceField;
00048 
00049       virtual bool match(const RouteTail *) const = 0;
00050 
00051     protected:
00052       RouteTail(Ref<NodeBase> n, const FieldBase *f):
00053         sourceNode(n), sourceField(f) {}
00054 
00055       unsigned long getTailCountNoLock() { return getUseCountNoLock(); }
00056     };
00057 
00061     struct RouteHead: virtual RefObjectBase
00062     {
00063       const BackRef<NodeBase> targetNode;
00064       const FieldBase *const targetField;
00065 
00066       virtual Ref<NodeBase> getSourceNode() const = 0;
00067       virtual const FieldBase *getSourceField() const = 0;
00068 
00069     protected:
00070       RouteHead(Ref<NodeBase> n, const FieldBase *f):
00071         targetNode(n), targetField(f) {}
00072 
00073       unsigned long getHeadCountNoLock() { return getUseCountNoLock(); }
00074     };
00075 
00076     struct Route: RouteTail, RouteHead
00077     {
00082       struct AccessException: Exception
00083       {
00084         AccessException(string l): Exception(l) {}
00085       };
00090       struct TypeException: Exception
00091       {
00092         TypeException(string l): Exception(l) {}
00093       };
00098       struct ContextException: Exception
00099       {
00100         ContextException(string l): Exception(l) {}
00101       };
00102 
00103       void cascadeEvent(const Event *e) const;
00104 
00105       virtual Ref<NodeBase> getSourceNode() const;
00106       virtual const FieldBase *getSourceField() const;
00107 
00108       static void add(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00109                       Ref<NodeBase> targetNode, const FieldBase *targetField)
00110         throw(AccessException, TypeException, ContextException);
00111 
00112       static bool del(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00113                       Ref<NodeBase> targetNode, const FieldBase *targetField)
00114         throw(ContextException);
00115 
00116       void refDispose(Mutex::Lock &l);
00117 
00118       ~Route();
00119 
00120     private:
00121       Route(Ref<NodeBase> sourceNode, const FieldBase *sourceField,
00122             Ref<NodeBase> targetNode, const FieldBase *targetField);
00123 
00124       bool match(const RouteTail *) const;
00125     };
00126 
00127 
00128 
00129 
00130     struct ValueBase: virtual RefObjectBase
00131     {
00132       const FieldType *getFieldType() const { return fieldType; }
00133 
00134     protected:
00135       ValueBase(const FieldType *fieldType): fieldType(fieldType) {}
00136 
00137     private:
00138       const FieldType *fieldType;
00139     };
00140 
00141     struct SimpleValueBase: ValueBase
00142     {
00146       virtual const void *getValuePtr() const = 0;
00147 
00148     protected:
00149       SimpleValueBase(const FieldType *fieldType): ValueBase(fieldType) {}
00150     };
00151 
00152     template<typename T>
00153     struct SimpleValue: SimpleValueBase
00154     {
00155       SimpleValue(const FieldType *fieldType, const T &value):
00156         SimpleValueBase(fieldType), value(value) {}
00157 
00158       SimpleValue(const FieldType *fieldType):
00159         SimpleValueBase(fieldType) {}
00160 
00161       const void *getValuePtr() const { return &value; }
00162 
00163       T value;
00164     };
00165 
00166     struct NodeValue: ValueBase
00167     {
00168       NodeValue(const FieldType *fieldType, NodeBase *value):
00169         ValueBase(fieldType), value(value) {}
00170       NodeValue(const FieldType *fieldType, Ref<NodeBase> value):
00171         ValueBase(fieldType), value(value) {}
00172 
00173       Ref<NodeBase> value;
00174     };
00175 
00176     struct NodeSequenceValue: ValueBase
00177     {
00178       NodeSequenceValue(const FieldType *fieldType):
00179         ValueBase(fieldType) {}
00180 
00181       vector<Ref<NodeBase> > value;
00182 
00183       typedef vector<Ref<NodeBase> >::const_iterator ConstIterator;
00184 
00185       ConstIterator begin() const { return value.begin(); }
00186       ConstIterator end()   const { return value.end();   }
00187     };
00188 
00189     struct Event
00190     {
00191       Event(Ref<const ValueBase> value, const Time &time): value(value), time(time) {}
00192 
00193       const Ref<const ValueBase> value;
00194       const Time time;
00195     };
00196   }
00197 }
00198 
00199 #endif // ARCHON_X3D_EVENT_H

Generated on Sun Jul 30 22:55:46 2006 for Archon by  doxygen 1.4.4