value.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 #ifndef ARCHON_X3D_PROXY_VALUE_H
00020 #define ARCHON_X3D_PROXY_VALUE_H
00021 
00022 #include <archon/x3d/proxy/field_type.H>
00023 #include <archon/x3d/proxy/sai.H>
00024 
00025 namespace Archon
00026 {
00027   namespace X3D
00028   {
00029     namespace Proxy
00030     {
00031       using namespace Utilities;
00032 
00033       struct NodeBase;
00034 
00035       struct Porter
00036       {
00037         struct TypeMismatchException: Exception
00038         {
00039           TypeMismatchException(string l): Exception(l) {}
00040         };
00041 
00042         struct IllegalNodeIdException: Exception
00043         {
00044           IllegalNodeIdException(string l): Exception(l) {}
00045         };
00046 
00047         virtual unsigned long node2id(Ref<NodeBase>) = 0;
00048 
00049         virtual Ref<NodeBase> id2node(unsigned long)
00050           throw(IllegalNodeIdException) = 0;
00051 
00052 
00053         void im(unsigned long type,
00054                 const x3d::sai::Value &source, void *target)
00055           throw(TypeMismatchException, IllegalNodeIdException)
00056         {
00057           if(type != source.type) ARCHON_THROW(TypeMismatchException);
00058           (this->*importers[type])(source, target);
00059         }
00060 
00061         void ex(unsigned long type,
00062                 const void *source, x3d::sai::Value &target)
00063         {
00064           (this->*exporters[type])(source, target);
00065           target.type = type;
00066         }
00067 
00068 
00069       protected:
00070         Porter();
00071         virtual ~Porter() {}
00072 
00073       private:
00074         typedef void (Porter::*Importer)
00075           (const x3d::sai::Value &source, void *target);
00076 
00077         typedef void (Porter::*Exporter)
00078           (const void *source, x3d::sai::Value &target);
00079 
00080 
00081         vector<Importer> importers;
00082         vector<Exporter> exporters;
00083 
00084 
00085         template<typename F> void imScalar(const x3d::sai::Value &, void *);
00086         template<typename F> void imTuple(const x3d::sai::Value &, void *);
00087         template<typename F> void imScalarSeq(const x3d::sai::Value &, void *);
00088         template<typename F> void imTupleSeq(const x3d::sai::Value &, void *);
00089 
00090         void imSFImage(const x3d::sai::Value &, void *);
00091         void imMFImage(const x3d::sai::Value &, void *);
00092 
00093         void imSFRotation(const x3d::sai::Value &, void *);
00094         void imMFRotation(const x3d::sai::Value &, void *);
00095 
00096         void imSFTime(const x3d::sai::Value &, void *);
00097         void imMFTime(const x3d::sai::Value &, void *);
00098 
00099 
00100         template<typename F> void exScalar(const void *, x3d::sai::Value &);
00101         template<typename F> void exTuple(const void *, x3d::sai::Value &);
00102         template<typename F> void exScalarSeq(const void *, x3d::sai::Value &);
00103         template<typename F> void exTupleSeq(const void *, x3d::sai::Value &);
00104 
00105         void exSFImage(const void *, x3d::sai::Value &);
00106         void exMFImage(const void *, x3d::sai::Value &);
00107 
00108         void exSFRotation(const void *, x3d::sai::Value &);
00109         void exMFRotation(const void *, x3d::sai::Value &);
00110 
00111         void exSFTime(const void *, x3d::sai::Value &);
00112         void exMFTime(const void *, x3d::sai::Value &);
00113       };
00114     }
00115   }
00116 }
00117 
00118 #endif // ARCHON_X3D_PROXY_VALUE_H

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