1#ifndef COIN_SOSUBNODE_H
2#define COIN_SOSUBNODE_H
58#include <Inventor/SbBasic.h>
59#include <Inventor/SbName.h>
60#include <Inventor/SoType.h>
61#include <Inventor/fields/SoFieldData.h>
62#include <Inventor/nodes/SoNode.h>
63#include <Inventor/C/tidbits.h>
67#define PRIVATE_NODE_TYPESYSTEM_HEADER( ) \
69 static SoType getClassTypeId(void); \
70 virtual SoType getTypeId(void) const; \
72 static SoType classTypeId
75#define SO_NODE_ABSTRACT_HEADER(_class_) \
76 PRIVATE_NODE_TYPESYSTEM_HEADER(); \
78 static const SoFieldData ** getFieldDataPtr(void); \
79 virtual const SoFieldData * getFieldData(void) const; \
81 static void atexit_cleanup(void); \
82 static const SoFieldData ** parentFieldData; \
83 static SoFieldData * fieldData; \
86 static unsigned int classinstances
90#define SO_NODE_HEADER(_class_) \
91 SO_NODE_ABSTRACT_HEADER(_class_); \
93 static void * createInstance(void)
97#define PRIVATE_NODE_TYPESYSTEM_SOURCE(_class_) \
103SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
110SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
111SoType _class_::classTypeId STATIC_SOTYPE_INIT
115#define SO_NODE_ABSTRACT_SOURCE(_class_) \
116PRIVATE_NODE_TYPESYSTEM_SOURCE(_class_); \
118unsigned int _class_::classinstances = 0; \
119const SoFieldData ** _class_::parentFieldData = NULL; \
120SoFieldData * _class_::fieldData = NULL; \
128const SoFieldData ** \
129_class_::getFieldDataPtr(void) \
131 return const_cast<const SoFieldData **>(&_class_::fieldData); \
135_class_::getFieldData(void) const \
137 return _class_::fieldData; \
141_class_::atexit_cleanup(void) \
143 delete _class_::fieldData; \
144 _class_::fieldData = NULL; \
145 _class_::parentFieldData = NULL; \
146 SoType::removeType(_class_::classTypeId.getName()); \
147 _class_::classTypeId STATIC_SOTYPE_INIT; \
148 _class_::classinstances = 0; \
152#define SO_NODE_SOURCE(_class_) \
153SO_NODE_ABSTRACT_SOURCE(_class_) \
159_class_::createInstance(void) \
161 return new _class_; \
167#define SO_NODE_IS_FIRST_INSTANCE() \
168 (classinstances == 1)
171#define SO_NODE_CONSTRUCTOR_NOLOCK(_class_) \
173 _class_::classinstances++; \
175 assert(_class_::classTypeId != SoType::badType() && "you forgot init()!"); \
177 if (!_class_::fieldData) { \
180 _class_::fieldData = \
181 new SoFieldData(_class_::parentFieldData ? \
182 *_class_::parentFieldData : NULL); \
187 this->isBuiltIn = FALSE; \
191#define SO_NODE_CONSTRUCTOR(_class_) \
193 SoBase::staticDataLock(); \
194 SO_NODE_CONSTRUCTOR_NOLOCK(_class_); \
195 SoBase::staticDataUnlock(); \
208#define PRIVATE_COMMON_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
211 assert(_class_::classTypeId == SoType::badType() && "don't init() twice!"); \
213 assert(strcmp(SO__QUOTE(_parentclass_), "inherited")); \
214 SoType parentType(SoType::fromName(SO__QUOTE(_parentclass_))); \
215 assert(parentType != SoType::badType() && "you forgot init() on parentclass!"); \
218 _class_::classTypeId = \
219 SoType::createType(parentType, \
222 (uint16_t)SoNode::getNextActionMethodIndex()); \
223 SoNode::incNextActionMethodIndex(); \
226 _class_::parentFieldData = _parentclass_::getFieldDataPtr(); \
229 cc_coin_atexit_static_internal(_class_::atexit_cleanup); \
234#define SO_NODE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
236 const char * classname = SO__QUOTE(_class_); \
237 PRIVATE_COMMON_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
241#define SO_NODE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
243 const char * classname = SO__QUOTE(_class_); \
244 PRIVATE_COMMON_INIT_CODE(_class_, classname, NULL, _parentclass_); \
251#define SO_NODE_ADD_FIELD(_field_, _defaultval_) \
253 this->_field_.setValue _defaultval_;\
254 this->_field_.setContainer(this); \
255 fieldData->addField(this, SO__QUOTE(_field_), &this->_field_); \
259#define SO_NODE_ADD_EMPTY_MFIELD(_field_) \
261 this->_field_.setContainer(this); \
262 fieldData->addField(this, SO__QUOTE(_field_), &this->_field_);\
267#define SO_NODE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
269 fieldData->addEnumValue(SO__QUOTE(_enumname_), \
270 SO__QUOTE(_enumval_), _enumval_); \