1#ifndef COIN_SOSUBENGINE_H
2#define COIN_SOSUBENGINE_H
37#include <Inventor/SbName.h>
38#include <Inventor/SoType.h>
39#include <Inventor/C/tidbits.h>
40#include <Inventor/engines/SoEngine.h>
41#include <Inventor/engines/SoOutputData.h>
42#include <Inventor/fields/SoFieldData.h>
50#define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
52 static SoType getClassTypeId(void); \
53 virtual SoType getTypeId(void) const; \
55 static SoType classTypeId
57#define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
58 PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
60 static const SoFieldData ** getInputDataPtr(void); \
61 static const SoEngineOutputData ** getOutputDataPtr(void); \
63 virtual const SoFieldData * getFieldData(void) const; \
64 virtual const SoEngineOutputData * getOutputData(void) const; \
66 static unsigned int classinstances; \
67 static SoFieldData * inputdata; \
68 static const SoFieldData ** parentinputdata; \
69 static SoEngineOutputData * outputdata; \
70 static const SoEngineOutputData ** parentoutputdata; \
71 static void atexit_cleanup(void)
73#define SO_ENGINE_HEADER(_classname_) \
74 SO_ENGINE_ABSTRACT_HEADER(_classname_); \
76 static void * createInstance(void)
80#define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
86SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
93SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
94SoType _class_::classTypeId STATIC_SOTYPE_INIT
96#define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
97PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
99unsigned int _class_::classinstances = 0; \
100SoFieldData * _class_::inputdata = NULL; \
101const SoFieldData ** _class_::parentinputdata = NULL; \
102SoEngineOutputData * _class_::outputdata = NULL; \
103const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
109const SoFieldData ** \
110_class_::getInputDataPtr(void) \
112 return const_cast<const SoFieldData **>(&_class_::inputdata); \
120_class_::getFieldData(void) const \
122 return _class_::inputdata; \
129const SoEngineOutputData ** \
130_class_::getOutputDataPtr(void) \
132 return const_cast<const SoEngineOutputData**>(&_class_::outputdata); \
139const SoEngineOutputData * \
140_class_::getOutputData(void) const \
142 return _class_::outputdata; \
146_class_::atexit_cleanup(void) \
148 delete _class_::inputdata; \
149 delete _class_::outputdata; \
150 _class_::inputdata = NULL; \
151 _class_::outputdata = NULL; \
152 _class_::parentinputdata = NULL; \
153 _class_::parentoutputdata = NULL; \
154 assert(_class_::classTypeId != SoType::badType()); \
155 SoType::removeType(_class_::classTypeId.getName()); \
156 _class_::classTypeId STATIC_SOTYPE_INIT; \
157 _class_::classinstances = 0; \
160#define SO_ENGINE_SOURCE(_class_) \
161SO_ENGINE_ABSTRACT_SOURCE(_class_); \
167_class_::createInstance(void) \
169 return new _class_; \
174#define SO_ENGINE_IS_FIRST_INSTANCE() \
175 (classinstances == 1)
177#define SO_ENGINE_CONSTRUCTOR(_class_) \
179 SoBase::staticDataLock(); \
180 _class_::classinstances++; \
182 assert(_class_::classTypeId != SoType::badType()); \
184 if (!_class_::inputdata) { \
185 _class_::inputdata = \
186 new SoFieldData(_class_::parentinputdata ? \
187 *_class_::parentinputdata : NULL); \
188 _class_::outputdata = \
189 new SoEngineOutputData(_class_::parentoutputdata ? \
190 *_class_::parentoutputdata : NULL); \
195 this->isBuiltIn = FALSE; \
196 SoBase::staticDataUnlock(); \
201#define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
204 assert(_class_::classTypeId == SoType::badType()); \
206 assert(_parentclass_::getClassTypeId() != SoType::badType()); \
209 _class_::classTypeId = \
210 SoType::createType(_parentclass_::getClassTypeId(), \
215 _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
216 _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
217 cc_coin_atexit_static_internal \
218 (reinterpret_cast<coin_atexit_f*>(_class_::atexit_cleanup)); \
222#define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
224 const char * classname = SO__QUOTE(_class_); \
225 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
228#define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
230 const char * classname = SO__QUOTE(_class_); \
231 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
236#define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
238 this->_input_.setValue _defaultval_;\
239 this->_input_.setContainer(this); \
240 inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
243#define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
245 outputdata->addOutput(this, SO__QUOTE(_output_), \
247 _type_::getClassTypeId()); \
248 this->_output_.setContainer(this); \
253#define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
255 inputdata->addEnumValue(SO__QUOTE(_enumname_), \
256 SO__QUOTE(_enumval_), _enumval_); \
259#define SO_ENGINE_OUTPUT(_engineout_, _fieldtype_, _writeop_) \
261 if (_engineout_.isEnabled()) { \
265 int SO_ENGINE_OUTPUT_numconnections = _engineout_.getNumConnections(); \
270 for (int SO_ENGINE_OUTPUT_i = 0; SO_ENGINE_OUTPUT_i < SO_ENGINE_OUTPUT_numconnections; SO_ENGINE_OUTPUT_i++) { \
271 _fieldtype_ * SO_ENGINE_OUTPUT_field = \
272 static_cast<_fieldtype_*>(_engineout_[SO_ENGINE_OUTPUT_i]); \
273 if (!SO_ENGINE_OUTPUT_field->isReadOnly()) { SO_ENGINE_OUTPUT_field->_writeop_; } \
276 assert(_engineout_.getNumConnections() == SO_ENGINE_OUTPUT_numconnections); \
282#define SO_COMPOSE__HEADER(_name_) \
283 SO_ENGINE_HEADER(_name_); \
285 virtual void evaluate(); \
290 static void initClass()