Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoSubEngine.h
1#ifndef COIN_SOSUBENGINE_H
2#define COIN_SOSUBENGINE_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#include <cassert>
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>
43
44// *************************************************************************
45
46//
47// FIXME: document macros. pederb, 20000309
48//
49
50#define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
51public: \
52 static SoType getClassTypeId(void); \
53 virtual SoType getTypeId(void) const; \
54private: \
55 static SoType classTypeId
56
57#define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
58 PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
59protected: \
60 static const SoFieldData ** getInputDataPtr(void); \
61 static const SoEngineOutputData ** getOutputDataPtr(void); \
62public: \
63 virtual const SoFieldData * getFieldData(void) const; \
64 virtual const SoEngineOutputData * getOutputData(void) const; \
65private: \
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)
72
73#define SO_ENGINE_HEADER(_classname_) \
74 SO_ENGINE_ABSTRACT_HEADER(_classname_); \
75 public: \
76 static void * createInstance(void)
77
78// *************************************************************************
79
80#define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
81 \
82
85 \
86SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
87 \
88
92 \
93SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
94SoType _class_::classTypeId STATIC_SOTYPE_INIT
95
96#define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
97PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
98 \
99unsigned int _class_::classinstances = 0; \
100SoFieldData * _class_::inputdata = NULL; \
101const SoFieldData ** _class_::parentinputdata = NULL; \
102SoEngineOutputData * _class_::outputdata = NULL; \
103const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
104 \
105
108 \
109const SoFieldData ** \
110_class_::getInputDataPtr(void) \
111{ \
112 return const_cast<const SoFieldData **>(&_class_::inputdata); \
113} \
114 \
115
118 \
119const SoFieldData * \
120_class_::getFieldData(void) const \
121{ \
122 return _class_::inputdata; \
123} \
124 \
125
128 \
129const SoEngineOutputData ** \
130_class_::getOutputDataPtr(void) \
131{ \
132 return const_cast<const SoEngineOutputData**>(&_class_::outputdata); \
133} \
134 \
135
138 \
139const SoEngineOutputData * \
140_class_::getOutputData(void) const \
141{ \
142 return _class_::outputdata; \
143} \
144 \
145void \
146_class_::atexit_cleanup(void) \
147{ \
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; \
158}
159
160#define SO_ENGINE_SOURCE(_class_) \
161SO_ENGINE_ABSTRACT_SOURCE(_class_); \
162 \
163
165 \
166void * \
167_class_::createInstance(void) \
168{ \
169 return new _class_; \
170}
171
172// *************************************************************************
173
174#define SO_ENGINE_IS_FIRST_INSTANCE() \
175 (classinstances == 1)
176
177#define SO_ENGINE_CONSTRUCTOR(_class_) \
178 do { \
179 SoBase::staticDataLock(); \
180 _class_::classinstances++; \
181 /* Catch attempts to use an engine class which has not been initialized. */ \
182 assert(_class_::classTypeId != SoType::badType()); \
183 /* Initialize a inputdata container for the class only once. */ \
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); \
191 } \
192 /* Extension classes from the application programmers should not be */ \
193 /* considered native. This is important to get the export code to do */ \
194 /* the Right Thing. */ \
195 this->isBuiltIn = FALSE; \
196 SoBase::staticDataUnlock(); \
197 } WHILE_0
198
199// *************************************************************************
200
201#define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
202 do { \
203 /* Make sure we only initialize once. */ \
204 assert(_class_::classTypeId == SoType::badType()); \
205 /* Make sure superclass gets initialized before subclass. */ \
206 assert(_parentclass_::getClassTypeId() != SoType::badType()); \
207 \
208 /* Set up entry in the type system. */ \
209 _class_::classTypeId = \
210 SoType::createType(_parentclass_::getClassTypeId(), \
211 _classname_, \
212 _createfunc_); \
213 \
214 /* Store parent's data pointers for later use in the constructor. */ \
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)); \
219 } WHILE_0
220
221
222#define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
223 do { \
224 const char * classname = SO__QUOTE(_class_); \
225 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
226 } WHILE_0
227
228#define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
229 do { \
230 const char * classname = SO__QUOTE(_class_); \
231 PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
232 } WHILE_0
233
234// *************************************************************************
235
236#define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
237 do { \
238 this->_input_.setValue _defaultval_;\
239 this->_input_.setContainer(this); \
240 inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
241 } WHILE_0
242
243#define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
244 do { \
245 outputdata->addOutput(this, SO__QUOTE(_output_), \
246 &this->_output_, \
247 _type_::getClassTypeId()); \
248 this->_output_.setContainer(this); \
249 } WHILE_0
250
251// *************************************************************************
252
253#define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
254 do { \
255 inputdata->addEnumValue(SO__QUOTE(_enumname_), \
256 SO__QUOTE(_enumval_), _enumval_); \
257 } WHILE_0
258
259#define SO_ENGINE_OUTPUT(_engineout_, _fieldtype_, _writeop_) \
260 do { \
261 if (_engineout_.isEnabled()) { \
262 /* No fields can be added or removed during this loop, as it */ \
263 /* is a "closed" operation. (The fields are disabled for */ \
264 /* notification while the loop runs). */ \
265 int SO_ENGINE_OUTPUT_numconnections = _engineout_.getNumConnections(); \
266 /* The reason we use the perverted variable names is to */ \
267 /* avoid the possibility of getting _extremely_ hard */ \
268 /* to find bugs when _writeop_ contains the same variable */ \
269 /* names we are using internally in the macro. */ \
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_; } \
274 } \
275 /* paranoid assertion */ \
276 assert(_engineout_.getNumConnections() == SO_ENGINE_OUTPUT_numconnections); \
277 } \
278 } WHILE_0
279
280// *************************************************************************
281
282#define SO_COMPOSE__HEADER(_name_) \
283 SO_ENGINE_HEADER(_name_); \
284 private: \
285 virtual void evaluate(); \
286 protected: \
287 virtual ~_name_();\
288 public: \
289 _name_(); \
290 static void initClass()
291
292// *************************************************************************
293
294#endif // !COIN_SOSUBENGINE_H