Open Inventor Reference
SoSubNode.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * Further, this software is distributed without any warranty that it is
16  * free of the rightful claim of any third person regarding infringement
17  * or the like. Any license provided herein, whether implied or
18  * otherwise, applies only to this software file. Patent licenses, if
19  * any, provided herein do not apply to combinations of this program with
20  * other software, or any other product whatsoever.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27  * Mountain View, CA 94043, or:
28  *
29  * http://www.sgi.com
30  *
31  * For further information regarding this notice, see:
32  *
33  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34  *
35  */
36 
37 
38 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Description:
47  | This file defines some macros that implement things common to
48  | many subclasses of SoNode. They may be used to make SoNode
49  | subclassing easier. In all of the macros, the "className"
50  | parameter refers to the name of the node subclass.
51  |
52  | Methods containing the word "ABSTRACT" are to be used for
53  | abstract subclasses in place of the corresponding regular
54  | macro. Note that abstract classes may not have fields (you
55  | cannot call ADD_FIELD in their constructor).
56  |
57  | Defined macros:
58  |
59  | Within class header:
60  |
61  | SO_NODE_HEADER(className)
62  | SO_NODE_ABSTRACT_HEADER(className)
63  |
64  | Within class source:
65  |
66  | At file scope:
67  |
68  | SO_NODE_SOURCE(className)
69  | SO_NODE_ABSTRACT_SOURCE(className)
70  |
71  | Class initialization (initClass):
72  |
73  | SO_NODE_INIT_CLASS()
74  | SO_NODE_INIT_ABSTRACT_CLASS()
75  |
76  | Constructor initialization:
77  |
78  | SO_NODE_CONSTRUCTOR(className)
79  | SO_NODE_ADD_FIELD(fieldMember,(defaultValue))
80  | SO_NODE_DEFINE_ENUM_VALUE(enumType,enumValue)
81  | SO_NODE_IS_FIRST_INSTANCE() //!< a boolean value
82  |
83  | //!< the following are defined in <fields/So[SM]fEnum.h>:
84  | SO_NODE_SET_SF_ENUM_TYPE(fieldName,enumType)
85  | SO_NODE_SET_MF_ENUM_TYPE(fieldName,enumType)
86  |
87  | Author(s) : Paul S. Strauss, Gavin Bell, Ronen Barzel
88  |
89  ______________ S I L I C O N G R A P H I C S I N C . ____________
90  _______________________________________________________________________
91  */
92 
93 #ifndef _SO_SUB_NODE_
94 #define _SO_SUB_NODE_
95 
96 #include <memory>
97 #include <stdlib.h>
101 #include <Inventor/nodes/SoNode.h>
102 
103 
107 
112 #ifdef DEBUG
113 #define SO__NODE_CHECK_INIT(className) { \
114  if (classTypeId == SoType::badType()) { \
115  SoDebugError::post("SO_NODE_CONSTRUCTOR", \
116  "Can't construct a node of type " \
117  SO__QUOTE(className) \
118  " until initClass() has been called"); \
119  return; \
120  } \
121 }
122 
123 #define SO__NODE_CHECK_CONSTRUCT(where) { \
124  if (fieldData == NULL) { \
125  SoDebugError::post(where, \
126  "Instance not properly constructed.\n" \
127  "Did you forget to put SO_NODE_CONSTRUCTOR()" \
128  " in the constructor?"); \
129  fieldDataStorage = \
130  std::make_unique<SoFieldData>(parentFieldData ? *parentFieldData : NULL); \
131  fieldData = fieldDataStorage.get(); \
132  } \
133  }
134 
135 #else
136 #define SO__NODE_CHECK_INIT(className) { }
137 #define SO__NODE_CHECK_CONSTRUCT(where) { }
138 #endif
139 
145 
151 
152 #define SO_NODE_ABSTRACT_HEADER(className) \
153  public: \
154  typedef className InventorThisClass; \
155  static SoType getClassTypeId() /* Returns class type id */ \
156  { return classTypeId; } \
157  virtual SoType getTypeId() const; /* Returns type id */ \
158  protected: \
159  virtual const SoFieldData *getFieldData() const; \
160  static const SoFieldData **getFieldDataPtr() \
161  { return const_cast<const SoFieldData **>(&fieldData); } \
162  private: \
163  static SoType classTypeId; /* Type id */ \
164  static bool firstInstance; /* true until 2nd c'tor call */ \
165  static SoFieldData *fieldData; \
166  static std::unique_ptr<SoFieldData> fieldDataStorage; \
167  static const SoFieldData **parentFieldData
168 
173 #define SO_NODE_HEADER(className) \
174  SO_NODE_ABSTRACT_HEADER(className); \
175  static void *createInstance()
176 
181 
187 
188 #define SO__NODE_ABSTRACT_VARS(className) \
189  SoType className::classTypeId; \
190  SoFieldData *className::fieldData; \
191  std::unique_ptr<SoFieldData> className::fieldDataStorage; \
192  const SoFieldData **className::parentFieldData; \
193  bool className::firstInstance = TRUE
194 
198 #define SO__NODE_VARS(className) \
199  SO__NODE_ABSTRACT_VARS(className)
200 
205 
206 #define SO__NODE_ABSTRACT_METHODS(className) \
207  \
208  SoType \
209  className::getTypeId() const \
210  { \
211  return classTypeId; \
212  } \
213  \
214  const SoFieldData * \
215  className::getFieldData() const \
216  { \
217  SO__NODE_CHECK_CONSTRUCT(SO__QUOTE(className)); \
218  return fieldData; \
219  }
220 
226 
227 #define SO__NODE_METHODS(className) \
228  \
229  SO__NODE_ABSTRACT_METHODS(className) \
230  \
231  void * \
232  className::createInstance() \
233  { \
234  return static_cast<void *>(new className); \
235  }
236 
237 
243 
244 #define SO_NODE_SOURCE(className) \
245  SO__NODE_VARS(className); \
246  SO__NODE_METHODS(className)
247 
248 #define SO_NODE_ABSTRACT_SOURCE(className) \
249  SO__NODE_ABSTRACT_VARS(className); \
250  SO__NODE_ABSTRACT_METHODS(className)
251 
252 
257 
258 #define SO__NODE_INIT_CLASS(className,classPrintName,parentClass) { \
259  if ((SoNode::nextActionMethodIndex < 0) || \
260  (SoNode::nextActionMethodIndex > 32767)){ \
261  SoDebugError::post("SO__NODE_INIT_CLASS", \
262  "Overflow of SoNode::nextActionMethodIndex"); \
263  abort(); \
264  } \
265  classTypeId = \
266  SoType::createType(parentClass::getClassTypeId(), \
267  classPrintName, \
268  &className::createInstance, \
269  static_cast<short>(SoNode::nextActionMethodIndex++)); \
270  parentFieldData = parentClass::getFieldDataPtr(); \
271 }
272 
273 #define SO__NODE_INIT_ABSTRACT_CLASS(className,classPrintName,parentClass) { \
274  if ((SoNode::nextActionMethodIndex < 0) || \
275  (SoNode::nextActionMethodIndex > 32767)){ \
276  SoDebugError::post("SO__NODE_INIT_ABSTRACT_CLASS", \
277  "Overflow of SoNode::nextActionMethodIndex"); \
278  abort(); \
279  } \
280  classTypeId = \
281  SoType::createType(parentClass::getClassTypeId(), \
282  classPrintName, \
283  NULL, \
284  static_cast<short>(SoNode::nextActionMethodIndex++)); \
285  parentFieldData = parentClass::getFieldDataPtr(); \
286 }
287 
295 
296 #define SO_NODE_INIT_CLASS(className,parentClass,parentPrintClass) { \
297  if ((SoNode::nextActionMethodIndex < 0) || \
298  (SoNode::nextActionMethodIndex > 32767)){ \
299  SoDebugError::post("SO_NODE_INIT_CLASS", \
300  "Overflow of SoNode::nextActionMethodIndex"); \
301  abort(); \
302  } \
303  classTypeId = \
304  SoType::createType(SoType::fromName(parentPrintClass), \
305  SO__QUOTE(className), \
306  &className::createInstance, \
307  static_cast<short>(SoNode::nextActionMethodIndex++)); \
308  parentFieldData = parentClass::getFieldDataPtr(); \
309 }
310 
311 #define SO_NODE_INIT_ABSTRACT_CLASS(className, parentClass, parentPrintClass) { \
312  if ((SoNode::nextActionMethodIndex < 0) || \
313  (SoNode::nextActionMethodIndex > 32767)){ \
314  SoDebugError::post("SO_NODE_INIT_ABSTRACT_CLASS", \
315  "Overflow of SoNode::nextActionMethodIndex"); \
316  abort(); \
317  } \
318  classTypeId = \
319  SoType::createType(SoType::fromName(parentPrintClass), \
320  SO__QUOTE(className), \
321  NULL, \
322  static_cast<short>(SoNode::nextActionMethodIndex++)); \
323  parentFieldData = parentClass::getFieldDataPtr(); \
324 }
325 
331 
332 #define SO_NODE_CONSTRUCTOR(className) { \
333  SO__NODE_CHECK_INIT(className); \
334  if (fieldData == NULL) \
335  { \
336  fieldDataStorage = \
337  std::make_unique<SoFieldData>(parentFieldData ? *parentFieldData : NULL); \
338  fieldData = fieldDataStorage.get(); \
339  } \
340  else \
341  firstInstance = FALSE; \
342  isBuiltIn = FALSE; \
343 }
344 
350 
351 #define SO_NODE_IS_FIRST_INSTANCE() \
352  (firstInstance == TRUE)
353 
358 #define SO_NODE_ADD_REMOVED_FIELD(fieldName) {\
359  if (firstInstance) \
360  fieldData->addRemovedFieldName(SO__QUOTE(fieldName)); \
361  }
362 
378 
379 #define SO_NODE_ADD_FIELD(fieldName,defValue) { \
380  SO__NODE_CHECK_CONSTRUCT(__FILE__); \
381  if (firstInstance) \
382  fieldData->addField(this, SO__QUOTE(fieldName), \
383  &this->fieldName); \
384  this->fieldName.setValue defValue; \
385  this->fieldName.setContainer(this); \
386  }
387 
395 #define SO_NODE_ADD_ENUM_FIELD(field, type, defaultValue) \
396  SO_NODE_SET_SF_ENUM_TYPE(field, type);\
397  SO_NODE_ADD_FIELD(field, (defaultValue));
398 
420 
421 #define SO_NODE_DEFINE_ENUM_VALUE(enumType,enumValue) { \
422  SO__NODE_CHECK_CONSTRUCT(__FILE__); \
423  if (firstInstance) \
424  fieldData->addEnumValue(SO__QUOTE(enumType), \
425  SO__QUOTE(enumValue), \
426  enumValue); \
427  }
428 
453 
454 #define SO_NODE_DEFINE_ENUM_VALUE_NAMED(enumType,enumValue,enumValueName) { \
455  SO__NODE_CHECK_CONSTRUCT(__FILE__); \
456  if (firstInstance) \
457  fieldData->addEnumValue(SO__QUOTE(enumType), \
458  enumValueName, \
459  enumValue); \
460  }
461 
485 
486 #define SO_NODE_DEFINE_ENUM_VALUE_SCOPED(enumScope,enumType,enumValue) { \
487  SO__NODE_CHECK_CONSTRUCT(__FILE__); \
488  if (firstInstance) \
489  fieldData->addEnumValue(SO__QUOTE(enumScope) "::" SO__QUOTE(enumType),\
490  SO__QUOTE(enumValue), \
491  enumScope::enumValue); \
492  }
493 
494 
495 #endif /* _SO_SUB_NODE_ */
496