00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COIN_SOSUBENGINE_H
00021 #define COIN_SOSUBENGINE_H
00022
00023 #include <Inventor/SbName.h>
00024 #include <Inventor/SoType.h>
00025 #include <Inventor/engines/SoEngine.h>
00026 #include <Inventor/engines/SoOutputData.h>
00027 #include <Inventor/fields/SoFieldData.h>
00028 #include <assert.h>
00029
00030
00031
00032
00033
00034 #define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
00035 public: \
00036 static SoType getClassTypeId(void); \
00037 virtual SoType getTypeId(void) const; \
00038 private: \
00039 static SoType classTypeId
00040
00041 #define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
00042 PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
00043 protected: \
00044 static const SoFieldData ** getInputDataPtr(void); \
00045 static const SoEngineOutputData ** getOutputDataPtr(void); \
00046 public: \
00047 virtual const SoFieldData * getFieldData(void) const; \
00048 virtual const SoEngineOutputData * getOutputData(void) const; \
00049 private: \
00050 static unsigned int classinstances; \
00051 static SoFieldData * inputdata; \
00052 static const SoFieldData ** parentinputdata; \
00053 static SoEngineOutputData * outputdata; \
00054 static const SoEngineOutputData ** parentoutputdata
00055
00056 #define SO_ENGINE_HEADER(_classname_) \
00057 SO_ENGINE_ABSTRACT_HEADER(_classname_); \
00058 public: \
00059 static void * createInstance(void)
00060
00061
00062 #define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
00063 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
00064 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
00065 \
00066 \
00067 SoType _class_::classTypeId
00068
00069 #define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
00070 PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
00071 \
00072 unsigned int _class_::classinstances = 0; \
00073 SoFieldData * _class_::inputdata = NULL; \
00074 const SoFieldData ** _class_::parentinputdata = NULL; \
00075 SoEngineOutputData * _class_::outputdata = NULL; \
00076 const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
00077 \
00078 const SoFieldData ** \
00079 _class_::getInputDataPtr(void) \
00080 { \
00081 return (const SoFieldData **)&_class_::inputdata; \
00082 } \
00083 \
00084 const SoFieldData * \
00085 _class_::getFieldData(void) const \
00086 { \
00087 return _class_::inputdata; \
00088 } \
00089 \
00090 const SoEngineOutputData ** \
00091 _class_::getOutputDataPtr(void) \
00092 { \
00093 return (const SoEngineOutputData**)&_class_::outputdata; \
00094 } \
00095 \
00096 const SoEngineOutputData * \
00097 _class_::getOutputData(void) const \
00098 { \
00099 return _class_::outputdata; \
00100 }
00101
00102 #define SO_ENGINE_SOURCE(_class_) \
00103 SO_ENGINE_ABSTRACT_SOURCE(_class_); \
00104 \
00105 void * \
00106 _class_::createInstance(void) \
00107 { \
00108 return new _class_; \
00109 }
00110
00111 #define SO_ENGINE_IS_FIRST_INSTANCE() \
00112 (classinstances == 1)
00113
00114 #define SO_ENGINE_CONSTRUCTOR(_class_) \
00115 do { \
00116 _class_::classinstances++; \
00117 \
00118 assert(_class_::classTypeId != SoType::badType()); \
00119 \
00120 if (!_class_::inputdata) { \
00121 _class_::inputdata = \
00122 new SoFieldData(_class_::parentinputdata ? \
00123 *_class_::parentinputdata : NULL); \
00124 _class_::outputdata = \
00125 new SoEngineOutputData(_class_::parentoutputdata ? \
00126 *_class_::parentoutputdata : NULL); \
00127 } \
00128
00129
00130 \
00131 this->isBuiltIn = FALSE; \
00132 } while (0)
00133
00134
00135 #define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
00136 do { \
00137 \
00138 assert(_class_::classTypeId == SoType::badType()); \
00139 \
00140 assert(_parentclass_::getClassTypeId() != SoType::badType()); \
00141 \
00142 \
00143 _class_::classTypeId = \
00144 SoType::createType(_parentclass_::getClassTypeId(), \
00145 _classname_, \
00146 _createfunc_); \
00147 \
00148 \
00149 _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
00150 _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
00151 } while (0)
00152
00153
00154 #define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
00155 do { \
00156 const char * classname = SO__QUOTE(_class_); \
00157 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
00158 } while (0)
00159
00160
00161 #define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
00162 do { \
00163 const char * classname = SO__QUOTE(_class_); \
00164 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
00165 } while (0)
00166
00167
00168 #define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
00169 do { \
00170 this->_input_.setValue _defaultval_;\
00171 this->_input_.setContainer(this); \
00172 if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
00173 inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
00174 } \
00175 } while (0)
00176
00177 #define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
00178 do { \
00179 if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
00180 outputdata->addOutput(this, SO__QUOTE(_output_), \
00181 &this->_output_, \
00182 _type_::getClassTypeId()); \
00183 } \
00184 this->_output_.setContainer(this); \
00185 } while(0)
00186
00187
00188 #define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
00189 do { \
00190 if (SO_ENGINE_IS_FIRST_INSTANCE()) \
00191 inputdata->addEnumValue(SO__QUOTE(_enumname_), \
00192 SO__QUOTE(_enumval_), _enumval_); \
00193 } while (0)
00194
00195 #define SO_ENGINE_OUTPUT(_outmember_,_outtype_,_outval_) \
00196 do { \
00197 if (_outmember_.isEnabled()) \
00198 for (int SO_ENGINE_OUTPUT_i = 0; \
00199 SO_ENGINE_OUTPUT_i < _outmember_.getNumConnections(); \
00200 SO_ENGINE_OUTPUT_i++) { \
00201 _outtype_ * field = (_outtype_*) _outmember_[SO_ENGINE_OUTPUT_i]; \
00202 if (!field->isReadOnly()) \
00203 ((_outtype_ *)_outmember_[SO_ENGINE_OUTPUT_i])->_outval_; \
00204 } \
00205 } while (0)
00206
00207 #define SO_COMPOSE__HEADER(_name_) \
00208 SO_ENGINE_HEADER(_name_); \
00209 private: \
00210 virtual void evaluate(); \
00211 protected: \
00212 ~_name_();\
00213 public: \
00214 _name_(); \
00215 static void initClass()
00216
00217 #endif // !COIN_SOSUBENGINE_H