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

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