00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _SO_SUB_NODE_
00053 #define _SO_SUB_NODE_
00054
00055 #include <Inventor/errors/SoDebugError.h>
00056 #include <Inventor/fields/SoFieldData.h>
00057 #include <Inventor/threads/SbThreadLocalStorage.h>
00058 #include <Inventor/threads/SbThreadMutex.h>
00059 #if defined(_DEBUG)
00060 #include <Inventor/SoDB.h>
00061 #endif
00062
00063
00064
00065
00066
00068
00069
00070
00071 #if defined(_DEBUG)
00072 #define SO__NODE_CHECK_INIT(className) { \
00073 if (classTypeId.isBad()) { \
00074 SoDebugError::post("SO_NODE_CONSTRUCTOR", \
00075 "Can't construct a node of type " \
00076 SO__QUOTE(className) \
00077 " until initClass() has been called"); \
00078 className::initClass(); \
00079 } \
00080 SoTypedObject::checkDatabase(SO__QUOTE(className), this, className::getClassTypeId(), classTypeId); \
00081 }
00082
00083 #define SO__NODE_CHECK_CONSTRUCT(where) { \
00084 if (fieldData == NULL) { \
00085 SoDebugError::post(where, \
00086 "Instance not properly constructed.\n" \
00087 "Did you forget to put SO_NODE_CONSTRUCTOR()" \
00088 " in the constructor?"); \
00089 fieldData = new SoFieldData(parentFieldData ? *parentFieldData : NULL); \
00090 } \
00091 }
00092
00093 #else
00094 #define SO__NODE_CHECK_INIT(className) { \
00095 if (classTypeId.isBad()) { \
00096 className::initClass(); \
00097 } \
00098 }
00099
00100 #define SO__NODE_CHECK_CONSTRUCT(where) { \
00101 if (fieldData == NULL) { \
00102 fieldData = new SoFieldData(parentFieldData ? *parentFieldData : NULL); \
00103 } \
00104 }
00105 #endif
00106
00108
00109
00110
00111
00112
00114
00115
00116
00117
00118
00119 #define SO_NODE_ABSTRACT_HEADER(className) \
00120 public: \
00121 \
00122 static SoType getClassTypeId() \
00123 { return classTypeId; } \
00124 \
00125 virtual SoType getTypeId() const; \
00126 private: \
00127 virtual SbBool getIsBuiltIn() const ; \
00128 virtual const SoFieldData *getFieldData() const; \
00129 private: \
00130 static const SoFieldData **getFieldDataPtr(); \
00131 private: \
00132 static SbThreadMutex classMutex; \
00133 static SoType classTypeId; \
00134 static SbBool isBuiltIn; \
00135 static SbBool firstInstance; \
00136 static SoFieldData *fieldData; \
00137 static const SoFieldData **parentFieldData
00138
00139
00140
00141
00142
00143 #define SO_NODE_HEADER(className) \
00144 SO_NODE_ABSTRACT_HEADER(className); \
00145 static void *createInstance(SoType* dynamicType = NULL)
00146
00148
00149
00150
00151
00153
00154
00155
00156
00157
00158 #define SO__NODE_ABSTRACT_VARS(className) \
00159 SbThreadMutex className::classMutex; \
00160 SoType className::classTypeId; \
00161 SbBool className::isBuiltIn = FALSE; \
00162 SoFieldData *className::fieldData = NULL; \
00163 const SoFieldData **className::parentFieldData = NULL; \
00164 SbBool className::firstInstance = TRUE;
00165
00166
00167
00168
00169 #define SO__NODE_VARS(className) \
00170 SO__NODE_ABSTRACT_VARS(className)
00171
00173
00174
00175
00176
00177 #define SO__NODE_ABSTRACT_METHODS(className) \
00178 \
00179 SoType \
00180 className::getTypeId() const \
00181 { \
00182 return classTypeId; \
00183 } \
00184 \
00185 const SoFieldData * \
00186 className::getFieldData() const \
00187 { \
00188 classMutex.lock(); \
00189 SO__NODE_CHECK_CONSTRUCT(SO__QUOTE(className)); \
00190 SoFieldData * result = fieldData; \
00191 classMutex.unlock(); \
00192 return result; \
00193 } \
00194 \
00195 SbBool className::getIsBuiltIn() const \
00196 { \
00197 return isBuiltIn; \
00198 } \
00199 \
00200 const SoFieldData **className::getFieldDataPtr() \
00201 { \
00202 classMutex.lock(); \
00203 const SoFieldData **result = (const SoFieldData **)&fieldData; \
00204 classMutex.unlock(); \
00205 return result; \
00206 }
00207
00209
00210
00211
00212
00213
00214 #define SO__NODE_METHODS(className) \
00215 \
00216 SO__NODE_ABSTRACT_METHODS(className) \
00217 \
00218 void * \
00219 className::createInstance(SoType *) \
00220 { \
00221 return (void *)(new className); \
00222 }
00223
00224
00225
00227
00228
00229
00230
00231
00232 #define SO_NODE_SOURCE(className) \
00233 SO__NODE_VARS(className); \
00234 SO__NODE_METHODS(className)
00235
00236 #define SO_NODE_ABSTRACT_SOURCE(className) \
00237 SO__NODE_ABSTRACT_VARS(className); \
00238 SO__NODE_ABSTRACT_METHODS(className)
00239
00240
00242
00243
00244
00245
00246 #if defined(_DEBUG)
00247 #define SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass) \
00248 if (parentClass::getClassTypeId().isBad()) { \
00249 SoDebugError::post( SO__QUOTE(className)"::initClass", \
00250 SO__QUOTE(className)" initialized before parent class " \
00251 SO__QUOTE(parentClass)"\n"); \
00252 parentClass::initClass(); \
00253 }
00254 #else
00255 #define SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass) \
00256 if (parentClass::getClassTypeId().isBad()) \
00257 parentClass::initClass()
00258 #endif
00259
00260 #define SO__NODE_INIT_CLASS_INTERNAL(className,classPrintName,parentClass) \
00261 classMutex.lock(); \
00262 SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass); \
00263 classTypeId = SoType::createType( parentClass::getClassTypeId(), \
00264 classPrintName, \
00265 &className::createInstance, \
00266 (short)SoNode::getNextActionMethodIndex()); \
00267 if (parentFieldData == NULL) \
00268 SoNode::incNextActionMethodIndex(); \
00269 parentFieldData = parentClass::getFieldDataPtr(); \
00270 classMutex.unlock();
00271
00272 #define SO__NODE_INIT_CLASS(className,classPrintName,parentClass) \
00273 SO__NODE_INIT_CLASS_INTERNAL(className,classPrintName,parentClass)
00274
00275 #define SO__NODE_INIT_ABSTRACT_CLASS_INTERNAL(className,classPrintName,parentClass) \
00276 classMutex.lock(); \
00277 SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass); \
00278 classTypeId = SoType::createType( parentClass::getClassTypeId(), \
00279 classPrintName, \
00280 NULL, \
00281 (short)SoNode::getNextActionMethodIndex()); \
00282 if (parentFieldData == NULL) \
00283 SoNode::incNextActionMethodIndex(); \
00284 parentFieldData = parentClass::getFieldDataPtr(); \
00285 classMutex.unlock();
00286
00287 #define SO__NODE_INIT_ABSTRACT_CLASS(className,classPrintName,parentClass) \
00288 SO__NODE_INIT_ABSTRACT_CLASS_INTERNAL(className,classPrintName,parentClass)
00289
00290 #if defined(_DEBUG)
00291 #define SO__NODE_EXIT_CLASS(className) \
00292 if (! SoType::removeType(classTypeId.getName())) { \
00293 SoDebugError::post(SO__QUOTE(className)"::exitClass", \
00294 "Unable to remove type (%s) for this class. Check exitClass() " \
00295 "method is implemented and is called only once.\n", \
00296 classTypeId.getName().getString() ); \
00297 } \
00298 else \
00299 { \
00300 classTypeId = SoType::badType(); \
00301 if (fieldData != NULL) \
00302 { \
00303 delete fieldData; \
00304 fieldData = NULL; \
00305 } \
00306 parentFieldData = NULL; \
00307 firstInstance = TRUE; \
00308 }
00309 #else
00310 #define SO__NODE_EXIT_CLASS(className) \
00311 SoType::removeType(classTypeId.getName()); \
00312 classTypeId = SoType::badType(); \
00313 if (fieldData != NULL) \
00314 { \
00315 delete fieldData; \
00316 fieldData = NULL; \
00317 } \
00318 parentFieldData = NULL; \
00319 firstInstance = TRUE
00320 #endif
00321
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 #define SO_THREAD_NODE_INIT_CLASS(className,structName) \
00337 \
00338 SB_THREAD_INIT_CLASS(className,structName)
00339
00340 #define SO_THREAD_NODE_EXIT_CLASS(className) \
00341 \
00342 SB_THREAD_EXIT_CLASS(className)
00343
00344 #define LOCAL_THREAD_VAR(_className_, _structName_, _varName_) \
00345 \
00346 GET_THREAD_LOCAL_VAR(_className_, _structName_, _varName_)
00347
00348 #define LOCAL_THREAD_STORAGE(_className_) \
00349 \
00350 GET_THREAD_LOCAL_STORAGE(_className_)
00351
00352
00354
00355
00356
00357
00358
00359
00360 #define SO_NODE_INIT_CLASS_INTERNAL(className,parentClass,parentPrintClass) \
00361 classMutex.lock(); \
00362 SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass); \
00363 classTypeId = SoType::createType( SoType::fromName(parentPrintClass), \
00364 SO__QUOTE(className), \
00365 &className::createInstance, \
00366 (short)SoNode::getNextActionMethodIndex()); \
00367 if (parentFieldData == NULL) \
00368 SoNode::incNextActionMethodIndex(); \
00369 parentFieldData = parentClass::getFieldDataPtr(); \
00370 classMutex.unlock();
00371
00372 #define SO_NODE_INIT_CLASS(className,parentClass,parentPrintClass) \
00373 \
00374 SO_NODE_INIT_CLASS_INTERNAL(className,parentClass,parentPrintClass)
00375
00376 #define SO_NODE_INIT_ABSTRACT_CLASS_INTERNAL(className, parentClass, parentPrintClass) \
00377 classMutex.lock(); \
00378 SO_NODE_INIT_CLASS_CHECK_PARENT(className, parentClass); \
00379 classTypeId = SoType::createType( SoType::fromName(parentPrintClass), \
00380 SO__QUOTE(className), \
00381 NULL, \
00382 (short)SoNode::getNextActionMethodIndex()); \
00383 if (parentFieldData == NULL) \
00384 SoNode::incNextActionMethodIndex(); \
00385 parentFieldData = parentClass::getFieldDataPtr(); \
00386 classMutex.unlock();
00387
00388 #define SO_NODE_INIT_ABSTRACT_CLASS(className, parentClass, parentPrintClass) \
00389 \
00390 SO_NODE_INIT_ABSTRACT_CLASS_INTERNAL(className,parentClass,parentPrintClass)
00391
00396 #define SO_NODE_CONSTRUCTOR(className) \
00397 SoBaseInitializer sbi(this); \
00398 classMutex.lock(); \
00399 SO__NODE_CHECK_INIT(className); \
00400 if (fieldData == NULL) \
00401 fieldData = new SoFieldData(parentFieldData ? \
00402 (SoFieldData *)*parentFieldData : \
00403 (SoFieldData *)NULL); \
00404 else \
00405 firstInstance = FALSE; \
00406 classMutex.unlock()
00407
00408
00412 #define SO_NODE_IS_FIRST_INSTANCE() \
00413 \
00414 (firstInstance == TRUE)
00415
00416
00417
00433 #if defined(_DEBUG)
00434
00435 #define CHECK_FIELD_INIT(fieldName)
00436
00437
00438
00439 #define CHECK_MFIELD_INIT(fieldName) \
00440 if ( dynamic_cast<SoSField*>(&this->fieldName) != NULL) \
00441 SoDebugError::post("SO_NODE_ADD_MFIELD","Used for a SoSFField.")
00442 #else
00443 #define CHECK_FIELD_INIT(fieldName)
00444 #define CHECK_MFIELD_INIT(fieldName)
00445 #endif
00446
00447 #define SO_NODE_ADD_FIELD(fieldName,defValue) { \
00448 classMutex.lock(); \
00449 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00450 if (firstInstance) \
00451 fieldData->addField(this, SO__QUOTE(fieldName), \
00452 &this->fieldName); \
00453 this->fieldName.setValue defValue; \
00454 this->fieldName.setContainer(this); \
00455 this->fieldName.setFieldType(SoField::EXPOSED_FIELD); \
00456 CHECK_FIELD_INIT(fieldName); \
00457 classMutex.unlock(); \
00458 }
00459
00461
00462
00463
00464
00465 #define SO_NODE_ADD_NAMED_FIELD(fieldName,memberName,defValue) { \
00466 classMutex.lock(); \
00467 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00468 if (firstInstance) \
00469 fieldData->addField(this, SO__QUOTE(fieldName), \
00470 &this->memberName); \
00471 this->memberName.setValue defValue; \
00472 this->memberName.setContainer(this); \
00473 this->memberName.setFieldType(SoField::EXPOSED_FIELD); \
00474 classMutex.unlock(); \
00475 }
00476
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 #define SO_NODE_ADD_MFIELD(fieldName) { \
00494 classMutex.lock(); \
00495 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00496 if (firstInstance) \
00497 fieldData->addField(this, SO__QUOTE(fieldName), \
00498 &this->fieldName); \
00499 this->fieldName.setContainer(this); \
00500 this->fieldName.setFieldType(SoField::EXPOSED_FIELD); \
00501 CHECK_MFIELD_INIT(fieldName); \
00502 classMutex.unlock(); \
00503 }
00504
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 #define SO_NODE_ADD_PRIVATEFIELD(fieldName,defValue) { \
00522 classMutex.lock(); \
00523 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00524 if (firstInstance) \
00525 fieldData->addField(this, SO__QUOTE(fieldName), &this->fieldName); \
00526 this->fieldName.setValue defValue; \
00527 this->fieldName.setContainer(this); \
00528 this->fieldName.setFieldType(SoField::HIDDEN_FIELD); \
00529 classMutex.unlock(); \
00530 }
00531
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 #define SO_NODE_ADD_PRIVATEMFIELD(fieldName) { \
00549 classMutex.lock(); \
00550 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00551 if (firstInstance) \
00552 fieldData->addField(this, SO__QUOTE(fieldName), \
00553 &this->fieldName); \
00554 this->fieldName.setContainer(this); \
00555 this->fieldName.setFieldType(SoField::HIDDEN_FIELD); \
00556 classMutex.unlock(); \
00557 }
00558
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 #define SO_NODE_ADD_EXPOSEDFIELD(fieldName,defValue) { \
00579 classMutex.lock(); \
00580 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00581 if (firstInstance) \
00582 fieldData->addField(this, SO__QUOTE(fieldName), \
00583 &this->fieldName); \
00584 this->fieldName.setValue defValue; \
00585 this->fieldName.setContainer(this); \
00586 this->fieldName.setFieldType(SoField::EXPOSED_FIELD); \
00587 classMutex.unlock(); \
00588 }
00589
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603 #define SO_NODE_ADD_EVENTIN(fieldName) { \
00604 classMutex.lock(); \
00605 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00606 if (firstInstance) \
00607 fieldData->addField(this, SO__QUOTE(fieldName), \
00608 &this->fieldName); \
00609 this->fieldName.setContainer(this); \
00610 this->fieldName.setFieldType(SoField::EVENTIN_FIELD); \
00611 classMutex.unlock(); \
00612 }
00613
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 #define SO_NODE_ADD_EVENTOUT(fieldName, defValue) { \
00628 classMutex.lock(); \
00629 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00630 if (firstInstance) \
00631 fieldData->addField(this, SO__QUOTE(fieldName), \
00632 &this->fieldName); \
00633 this->fieldName.setValue defValue; \
00634 this->fieldName.setContainer(this); \
00635 this->fieldName.setFieldType(SoField::EVENTOUT_FIELD); \
00636 classMutex.unlock(); \
00637 }
00638
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652 #define SO_NODE_ADD_HIDDEN_FIELD(fieldName, defValue) { \
00653 classMutex.lock(); \
00654 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00655 if (firstInstance) \
00656 fieldData->addField(this, SO__QUOTE(fieldName), \
00657 &this->fieldName); \
00658 this->fieldName.setValue defValue; \
00659 this->fieldName.setContainer(this); \
00660 this->fieldName.setFieldType(SoField::INTERNAL_FIELD); \
00661 classMutex.unlock(); \
00662 }
00663
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675 #define SO_NODE_ADD_FIELD_EVENTIN(fieldName, defValue) { \
00676 classMutex.lock(); \
00677 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00678 if (firstInstance) \
00679 fieldData->addField(this, SO__QUOTE(fieldName), \
00680 &this->fieldName); \
00681 this->fieldName.setValue defValue; \
00682 this->fieldName.setContainer(this); \
00683 this->fieldName.setFieldType(SoField::FIELD_EVENTIN_FIELD); \
00684 classMutex.unlock(); \
00685 }
00686
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709 #define SO_NODE_DEFINE_ENUM_VALUE(enumType,enumValue) { \
00710 classMutex.lock(); \
00711 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00712 if (firstInstance) \
00713 fieldData->addEnumValue(SO__QUOTE(enumType), \
00714 SO__QUOTE(enumValue), \
00715 enumValue); \
00716 classMutex.unlock(); \
00717 }
00718
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 #define SO__NODE_DEFINE_ENUM_VALUE(enumType,enumValueName,enumValue) { \
00744 classMutex.lock(); \
00745 SO__NODE_CHECK_CONSTRUCT(__FILE__); \
00746 if (firstInstance) \
00747 fieldData->addEnumValue(SO__QUOTE(enumType), \
00748 enumValueName, \
00749 enumValue); \
00750 classMutex.unlock(); \
00751 }
00752
00753 #endif
00754
00755