Coin Logo http://www.sim.no/
http://www.coin3d.org/

SoSubEngine.h
1 #ifndef COIN_SOSUBENGINE_H
2 #define COIN_SOSUBENGINE_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) by Kongsberg Oil & Gas Technologies.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Kongsberg Oil & Gas Technologies
18  * about acquiring a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <assert.h>
28 #include <Inventor/SbName.h>
29 #include <Inventor/SoType.h>
30 #include <Inventor/C/tidbits.h>
31 #include <Inventor/engines/SoEngine.h>
32 #include <Inventor/engines/SoOutputData.h>
33 #include <Inventor/fields/SoFieldData.h>
34 
35 // *************************************************************************
36 
37 //
38 // FIXME: document macros. pederb, 20000309
39 //
40 
41 #define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
42 public: \
43  static SoType getClassTypeId(void); \
44  virtual SoType getTypeId(void) const; \
45 private: \
46  static SoType classTypeId
47 
48 #define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
49  PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
50 protected: \
51  static const SoFieldData ** getInputDataPtr(void); \
52  static const SoEngineOutputData ** getOutputDataPtr(void); \
53 public: \
54  virtual const SoFieldData * getFieldData(void) const; \
55  virtual const SoEngineOutputData * getOutputData(void) const; \
56 private: \
57  static unsigned int classinstances; \
58  static SoFieldData * inputdata; \
59  static const SoFieldData ** parentinputdata; \
60  static SoEngineOutputData * outputdata; \
61  static const SoEngineOutputData ** parentoutputdata; \
62  static void atexit_cleanup(void)
63 
64 #define SO_ENGINE_HEADER(_classname_) \
65  SO_ENGINE_ABSTRACT_HEADER(_classname_); \
66  public: \
67  static void * createInstance(void)
68 
69 // *************************************************************************
70 
71 #define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
72 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
73 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
74 SoType _class_::classTypeId STATIC_SOTYPE_INIT
75 
76 #define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
77 PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
78  \
79 unsigned int _class_::classinstances = 0; \
80 SoFieldData * _class_::inputdata = NULL; \
81 const SoFieldData ** _class_::parentinputdata = NULL; \
82 SoEngineOutputData * _class_::outputdata = NULL; \
83 const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
84  \
85 const SoFieldData ** \
86 _class_::getInputDataPtr(void) \
87 { \
88  return const_cast<const SoFieldData **>(&_class_::inputdata); \
89 } \
90  \
91 const SoFieldData * \
92 _class_::getFieldData(void) const \
93 { \
94  return _class_::inputdata; \
95 } \
96  \
97 const SoEngineOutputData ** \
98 _class_::getOutputDataPtr(void) \
99 { \
100  return const_cast<const SoEngineOutputData**>(&_class_::outputdata); \
101 } \
102  \
103 const SoEngineOutputData * \
104 _class_::getOutputData(void) const \
105 { \
106  return _class_::outputdata; \
107 } \
108  \
109 void \
110 _class_::atexit_cleanup(void) \
111 { \
112  delete _class_::inputdata; \
113  delete _class_::outputdata; \
114  _class_::inputdata = NULL; \
115  _class_::outputdata = NULL; \
116  _class_::parentinputdata = NULL; \
117  _class_::parentoutputdata = NULL; \
118  assert(_class_::classTypeId != SoType::badType()); \
119  SoType::removeType(_class_::classTypeId.getName()); \
120  _class_::classTypeId STATIC_SOTYPE_INIT; \
121  _class_::classinstances = 0; \
122 }
123 
124 #define SO_ENGINE_SOURCE(_class_) \
125 SO_ENGINE_ABSTRACT_SOURCE(_class_); \
126  \
127 void * \
128 _class_::createInstance(void) \
129 { \
130  return new _class_; \
131 }
132 
133 // *************************************************************************
134 
135 #define SO_ENGINE_IS_FIRST_INSTANCE() \
136  (classinstances == 1)
137 
138 #define SO_ENGINE_CONSTRUCTOR(_class_) \
139  do { \
140  SoBase::staticDataLock(); \
141  _class_::classinstances++; \
142  /* Catch attempts to use an engine class which has not been initialized. */ \
143  assert(_class_::classTypeId != SoType::badType()); \
144  /* Initialize a inputdata container for the class only once. */ \
145  if (!_class_::inputdata) { \
146  _class_::inputdata = \
147  new SoFieldData(_class_::parentinputdata ? \
148  *_class_::parentinputdata : NULL); \
149  _class_::outputdata = \
150  new SoEngineOutputData(_class_::parentoutputdata ? \
151  *_class_::parentoutputdata : NULL); \
152  } \
153  /* Extension classes from the application programmers should not be */ \
154  /* considered native. This is important to get the export code to do */ \
155  /* the Right Thing. */ \
156  this->isBuiltIn = FALSE; \
157  SoBase::staticDataUnlock(); \
158  } while (0)
159 
160 // *************************************************************************
161 
162 #define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
163  do { \
164  /* Make sure we only initialize once. */ \
165  assert(_class_::classTypeId == SoType::badType()); \
166  /* Make sure superclass gets initialized before subclass. */ \
167  assert(_parentclass_::getClassTypeId() != SoType::badType()); \
168  \
169  /* Set up entry in the type system. */ \
170  _class_::classTypeId = \
171  SoType::createType(_parentclass_::getClassTypeId(), \
172  _classname_, \
173  _createfunc_); \
174  \
175  /* Store parent's data pointers for later use in the constructor. */ \
176  _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
177  _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
178  cc_coin_atexit_static_internal \
179  (reinterpret_cast<coin_atexit_f*>(_class_::atexit_cleanup)); \
180  } while (0)
181 
182 
183 #define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
184  do { \
185  const char * classname = SO__QUOTE(_class_); \
186  PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
187  } while (0)
188 
189 #define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
190  do { \
191  const char * classname = SO__QUOTE(_class_); \
192  PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
193  } while (0)
194 
195 // *************************************************************************
196 
197 #define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
198  do { \
199  this->_input_.setValue _defaultval_;\
200  this->_input_.setContainer(this); \
201  inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
202  } while (0)
203 
204 #define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
205  do { \
206  outputdata->addOutput(this, SO__QUOTE(_output_), \
207  &this->_output_, \
208  _type_::getClassTypeId()); \
209  this->_output_.setContainer(this); \
210  } while(0)
211 
212 // *************************************************************************
213 
214 #define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
215  do { \
216  inputdata->addEnumValue(SO__QUOTE(_enumname_), \
217  SO__QUOTE(_enumval_), _enumval_); \
218  } while (0)
219 
220 #define SO_ENGINE_OUTPUT(_engineout_, _fieldtype_, _writeop_) \
221  do { \
222  if (_engineout_.isEnabled()) { \
223  /* No fields can be added or removed during this loop, as it */ \
224  /* is a "closed" operation. (The fields are disabled for */ \
225  /* notification while the loop runs). */ \
226  int SO_ENGINE_OUTPUT_numconnections = _engineout_.getNumConnections(); \
227  /* The reason we use the perverted variable names is to */ \
228  /* avoid the possibility of getting _extremely_ hard */ \
229  /* to find bugs when _writeop_ contains the same variable */ \
230  /* names we are using internally in the macro. */ \
231  for (int SO_ENGINE_OUTPUT_i = 0; SO_ENGINE_OUTPUT_i < SO_ENGINE_OUTPUT_numconnections; SO_ENGINE_OUTPUT_i++) { \
232  _fieldtype_ * SO_ENGINE_OUTPUT_field = \
233  static_cast<_fieldtype_*>(_engineout_[SO_ENGINE_OUTPUT_i]); \
234  if (!SO_ENGINE_OUTPUT_field->isReadOnly()) { SO_ENGINE_OUTPUT_field->_writeop_; } \
235  } \
236  /* paranoid assertion */ \
237  assert(_engineout_.getNumConnections() == SO_ENGINE_OUTPUT_numconnections); \
238  } \
239  } while (0)
240 
241 // *************************************************************************
242 
243 #define SO_COMPOSE__HEADER(_name_) \
244  SO_ENGINE_HEADER(_name_); \
245  private: \
246  virtual void evaluate(); \
247  protected: \
248  virtual ~_name_();\
249  public: \
250  _name_(); \
251  static void initClass()
252 
253 // *************************************************************************
254 
255 #endif // !COIN_SOSUBENGINE_H

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

Generated on Fri Sep 9 2016 for Coin by Doxygen 1.8.5.