Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SoSubElement.h
1 #ifndef COIN_SOSUBELEMENT_H
2 #define COIN_SOSUBELEMENT_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 /*
37  * This file contains macro definitions with common declarations and
38  * definitions used in Coin elements.
39  *
40  * FIXME: document macros and how they are used to set up a new
41  * user-extension skeleton element class (or just point to the example
42  * code in examples/advanced/elements/). 19991209 mortene.
43  *
44  */
45 
46 // *************************************************************************
47 
48 #include <Inventor/SbBasic.h> // for SO__QUOTE() definition
49 #include <Inventor/SbName.h>
50 #include <Inventor/C/tidbits.h>
51 #include <assert.h>
52 // Include SoElement.h to be Open Inventor compatible at compile-time.
53 #include <Inventor/elements/SoElement.h>
54 
55 // *************************************************************************
56 
57 #define SO_ELEMENT_ABSTRACT_HEADER(_class_) \
58 public: \
59  static SoType getClassTypeId(void); \
60  static int getClassStackIndex(void); \
61 protected: \
62  _class_(void); \
63 private: \
64  /* classStackIndex is protected in the OIV UNIX distribution in */ \
65  /* SoSubElement.h and private in the Win32 distribution. Since */ \
66  /* there is a getClassStackIndex() access method, it seems more */ \
67  /* sensible to keep it private. 20000808 mortene. */ \
68  static int classStackIndex; \
69  static SoType classTypeId; \
70  static void cleanupClass(void) { SoType::removeType(_class_::classTypeId.getName()); _class_::classTypeId STATIC_SOTYPE_INIT; }
71 
72 // *************************************************************************
73 
74 #define SO_ELEMENT_HEADER(_class_) \
75  SO_ELEMENT_ABSTRACT_HEADER(_class_); \
76 public: \
77  static void * createInstance(void)
78 
79 // *************************************************************************
80 
81 #define PRIVATE_SOELEMENT_VARIABLES(_class_) \
82 int _class_::classStackIndex; \
83 SoType _class_::classTypeId STATIC_SOTYPE_INIT; \
84 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
85 int _class_::getClassStackIndex(void) { return _class_::classStackIndex; }
86 
87 
88 #define SO_ELEMENT_ABSTRACT_SOURCE(_class_) \
89 PRIVATE_SOELEMENT_VARIABLES(_class_) \
90 _class_::_class_(void) { }
91 
92 #define SO_ELEMENT_SOURCE(_class_) \
93 PRIVATE_SOELEMENT_VARIABLES(_class_) \
94 _class_::_class_(void) { this->setTypeId(_class_::classTypeId); \
95  this->setStackIndex(_class_::classStackIndex); } \
96  \
97 void * _class_::createInstance(void) { return static_cast<void *>(new _class_); }
98 
99 /*
100  Specific to Coin. Added 2003-10-27.
101 */
102 #define SO_ELEMENT_CUSTOM_CONSTRUCTOR_SOURCE(_class_) \
103 PRIVATE_SOELEMENT_VARIABLES(_class_) \
104  \
105 void * _class_::createInstance(void) { return static_cast<void *>(new _class_); }
106 
107 // *************************************************************************
108 
109 #define PRIVATE_SOELEMENT_INIT(_class_, _parent_, _instantiate_) \
110  do { \
111  assert(_class_::classTypeId == SoType::badType()); \
112  assert(_parent_::getClassTypeId() != SoType::badType()); \
113  _class_::classTypeId = SoType::createType(_parent_::getClassTypeId(), \
114  SO__QUOTE(_class_), \
115  _instantiate_); \
116  if (_parent_::getClassStackIndex() < 0) _class_::classStackIndex = _class_::createStackIndex(_class_::classTypeId); \
117  else _class_::classStackIndex = _parent_::getClassStackIndex(); \
118  cc_coin_atexit_static_internal(reinterpret_cast<coin_atexit_f*>(_class_::cleanupClass)); \
119  } while (0)
120 
121 
122 #define SO_ELEMENT_INIT_ABSTRACT_CLASS(_class_, _parent_) \
123  PRIVATE_SOELEMENT_INIT(_class_, _parent_, NULL)
124 
125 #define SO_ELEMENT_INIT_CLASS(_class_, _parent_) \
126  PRIVATE_SOELEMENT_INIT(_class_, _parent_, &_class_::createInstance)
127 
128 // *************************************************************************
129 
130 #endif // !COIN_SOSUBELEMENT_H

Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated for Coin by Doxygen