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