node.H

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_PROXY_NODE_H
00021 #define ARCHON_X3D_PROXY_NODE_H
00022 
00023 #include <archon/x3d/proxy/context.H>
00024 
00025 namespace Archon
00026 {
00027   namespace X3D
00028   {
00029     namespace Proxy
00030     {
00031       struct Session;
00032       struct ExecutionContext;
00033 
00037       struct NodeBase: virtual RefObjectBase
00038       {
00039         Ref<Session> getSession() const { return session; }
00040 
00041       protected:
00042         friend struct Session;
00043         friend struct ExecutionContext;
00044         friend struct Field;
00045         template<typename F> friend struct FieldGet;
00046         template<typename F> friend struct FieldSeqGet;
00047         template<typename F> friend struct FieldSet;
00048         template<typename F> friend struct FieldSeqSet;
00049 
00050         NodeBase() {} // Dummy
00051 
00052         NodeBase(Session *s, unsigned long id):
00053           session(s), id(id), transCount(0) {}
00054 
00055         ~NodeBase() {{ session->destroyNode(this); }}
00056 
00057         template<typename T>
00058         static Ref<T> create(ExecutionContext *c,
00059                              unsigned long nodeTypeIndex)
00060         {
00061           Ref<NodeBase> n = c->session->createNode(c, nodeTypeIndex);
00062           return dynamic_cast<T *>(n.get());
00063         }
00064 
00065         const Ref<Session> session;
00066 
00067       private:
00068         unsigned long id;
00069         unsigned long transCount;
00070 
00071         void importValue(unsigned long id,
00072                          x3d::sai::Value &w, void *v) const
00073         {
00074           session->im(id, w, v);
00075         }
00076 
00077         void exportValue(unsigned long id,
00078                          const void *v, x3d::sai::Value &w) const
00079         {
00080           session->ex(id, v, w);
00081         }
00082 
00083         x3d::sai::Value *fieldGet(unsigned long id);
00084         x3d::sai::Value *fieldGetAt(unsigned long id, unsigned long index);
00085 
00086         void fieldSet(unsigned long id, x3d::sai::Value &);
00087         void fieldSetAt(unsigned long id, x3d::sai::Value &,
00088                         unsigned long index);
00089         void fieldAdd(unsigned long id, x3d::sai::Value &);
00090         void fieldDel(unsigned long id, x3d::sai::Value &);
00091 
00092         void registerFieldInterest(unsigned long fi,
00093                                    EventHandlerBase *h, bool destroy)
00094         {
00095           session->registerFieldInterest(id, fi, h, destroy);
00096         }
00097       };
00098     }
00099   }
00100 }
00101 
00102 #endif // ARCHON_X3D_PROXY_NODE_H

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