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

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages

SoSubEngine.h

00001 /**************************************************************************\
00002  *
00003  *  This file is part of the Coin 3D visualization library.
00004  *  Copyright (C) 1998-2004 by Systems in Motion.  All rights reserved.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  ("GPL") version 2 as published by the Free Software Foundation.
00009  *  See the file LICENSE.GPL at the root directory of this source
00010  *  distribution for additional information about the GNU GPL.
00011  *
00012  *  For using Coin with software that can not be combined with the GNU
00013  *  GPL, and for taking advantage of the additional benefits of our
00014  *  support services, please contact Systems in Motion about acquiring
00015  *  a Coin Professional Edition License.
00016  *
00017  *  See <URL:http://www.coin3d.org/> for more information.
00018  *
00019  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
00020  *  <URL:http://www.sim.no/>.
00021  *
00022 \**************************************************************************/
00023 
00024 #ifndef COIN_SOSUBENGINE_H
00025 #define COIN_SOSUBENGINE_H
00026 
00027 #include <Inventor/SbName.h>
00028 #include <Inventor/SoType.h>
00029 #include <Inventor/engines/SoEngine.h>
00030 #include <Inventor/engines/SoOutputData.h>
00031 #include <Inventor/fields/SoFieldData.h>
00032 #include <assert.h>
00033 
00034 //
00035 // FIXME: document macros. pederb, 20000309
00036 //
00037 
00038 #define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
00039 public: \
00040   static SoType getClassTypeId(void); \
00041   virtual SoType getTypeId(void) const; \
00042 private: \
00043   static SoType classTypeId
00044 
00045 #define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
00046   PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
00047 protected: \
00048   static const SoFieldData ** getInputDataPtr(void); \
00049   static const SoEngineOutputData ** getOutputDataPtr(void); \
00050 public: \
00051   virtual const SoFieldData * getFieldData(void) const; \
00052   virtual const SoEngineOutputData * getOutputData(void) const; \
00053 private: \
00054   static unsigned int classinstances; \
00055   static SoFieldData * inputdata; \
00056   static const SoFieldData ** parentinputdata; \
00057   static SoEngineOutputData * outputdata; \
00058   static const SoEngineOutputData ** parentoutputdata
00059 
00060 #define SO_ENGINE_HEADER(_classname_) \
00061     SO_ENGINE_ABSTRACT_HEADER(_classname_); \
00062   public: \
00063     static void * createInstance(void)
00064 
00065 
00066 #define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
00067 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
00068 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
00069 /* Don't set value explicitly to SoType::badType(), to avoid a bug in */ \
00070 /* Sun CC v4.0. (Bitpattern 0x0000 equals SoType::badType()). */ \
00071 SoType _class_::classTypeId
00072 
00073 #define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
00074 PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
00075  \
00076 unsigned int _class_::classinstances = 0; \
00077 SoFieldData * _class_::inputdata = NULL; \
00078 const SoFieldData ** _class_::parentinputdata = NULL; \
00079 SoEngineOutputData * _class_::outputdata = NULL; \
00080 const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
00081  \
00082 const SoFieldData ** \
00083 _class_::getInputDataPtr(void) \
00084 { \
00085   return (const SoFieldData **)&_class_::inputdata; \
00086 } \
00087  \
00088 const SoFieldData * \
00089 _class_::getFieldData(void) const \
00090 { \
00091   return _class_::inputdata; \
00092 } \
00093  \
00094 const SoEngineOutputData ** \
00095 _class_::getOutputDataPtr(void) \
00096 { \
00097   return (const SoEngineOutputData**)&_class_::outputdata; \
00098 } \
00099  \
00100 const SoEngineOutputData * \
00101 _class_::getOutputData(void) const \
00102 { \
00103   return _class_::outputdata; \
00104 }
00105 
00106 #define SO_ENGINE_SOURCE(_class_) \
00107 SO_ENGINE_ABSTRACT_SOURCE(_class_); \
00108  \
00109 void * \
00110 _class_::createInstance(void) \
00111 { \
00112   return new _class_; \
00113 }
00114 
00115 #define SO_ENGINE_IS_FIRST_INSTANCE() \
00116    (classinstances == 1) 
00117 
00118 #define SO_ENGINE_CONSTRUCTOR(_class_) \
00119   do { \
00120     SoBase::staticDataLock(); \
00121     _class_::classinstances++; \
00122     /* Catch attempts to use an engine class which has not been initialized. */ \
00123     assert(_class_::classTypeId != SoType::badType()); \
00124     /* Initialize a inputdata container for the class only once. */ \
00125     if (!_class_::inputdata) { \
00126       _class_::inputdata = \
00127         new SoFieldData(_class_::parentinputdata ? \
00128                         *_class_::parentinputdata : NULL); \
00129       _class_::outputdata = \
00130         new SoEngineOutputData(_class_::parentoutputdata ? \
00131                                *_class_::parentoutputdata : NULL); \
00132     } \
00133     /* Extension classes from the application programmers should not be */ \
00134     /* considered native. This is important to get the export code to do */ \
00135     /* the Right Thing. */ \
00136     this->isBuiltIn = FALSE; \
00137     SoBase::staticDataUnlock(); \
00138   } while (0)
00139 
00140 
00141 #define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
00142   do { \
00143     /* Make sure we only initialize once. */ \
00144     assert(_class_::classTypeId == SoType::badType()); \
00145     /* Make sure superclass gets initialized before subclass. */ \
00146     assert(_parentclass_::getClassTypeId() != SoType::badType()); \
00147  \
00148     /* Set up entry in the type system. */ \
00149     _class_::classTypeId = \
00150       SoType::createType(_parentclass_::getClassTypeId(), \
00151                          _classname_, \
00152                          _createfunc_); \
00153  \
00154     /* Store parent's data pointers for later use in the constructor. */ \
00155     _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
00156     _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
00157   } while (0)
00158 
00159 
00160 #define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
00161   do { \
00162     const char * classname = SO__QUOTE(_class_); \
00163     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
00164   } while (0)
00165 
00166 
00167 #define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
00168   do { \
00169     const char * classname = SO__QUOTE(_class_); \
00170     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
00171   } while (0)
00172 
00173 
00174 #define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
00175   do { \
00176     this->_input_.setValue _defaultval_;\
00177     this->_input_.setContainer(this); \
00178     inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
00179   } while (0)
00180 
00181 #define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
00182   do { \
00183     outputdata->addOutput(this, SO__QUOTE(_output_), \
00184                           &this->_output_, \
00185                           _type_::getClassTypeId()); \
00186     this->_output_.setContainer(this); \
00187   } while(0)
00188 
00189 
00190 #define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
00191   do { \
00192     inputdata->addEnumValue(SO__QUOTE(_enumname_), \
00193                             SO__QUOTE(_enumval_), _enumval_); \
00194   } while (0)
00195 
00196 #define SO_ENGINE_OUTPUT(_engineout_, _fieldtype_, _writeop_) \
00197   do { \
00198     if (_engineout_.isEnabled()) { \
00199       /* No fields can be added or removed during this loop, as it */ \
00200       /* is a "closed" operation. (The fields are disabled for */ \
00201       /* notification while the loop runs). */ \
00202       int SO_ENGINE_OUTPUT_numconnections = _engineout_.getNumConnections(); \
00203       /* The reason we use the perverted variable names is to */ \
00204       /* avoid the possibility of getting _extremely_ hard */ \
00205       /* to find bugs when _writeop_ contains the same variable */ \
00206       /* names we are using internally in the macro. */ \
00207       for (int SO_ENGINE_OUTPUT_i = 0; SO_ENGINE_OUTPUT_i < SO_ENGINE_OUTPUT_numconnections; SO_ENGINE_OUTPUT_i++) { \
00208         _fieldtype_ * SO_ENGINE_OUTPUT_field = (_fieldtype_*) _engineout_[SO_ENGINE_OUTPUT_i]; \
00209         if (!SO_ENGINE_OUTPUT_field->isReadOnly()) { SO_ENGINE_OUTPUT_field->_writeop_; } \
00210       } \
00211       /* paranoid assertion */ \
00212       assert(_engineout_.getNumConnections() == SO_ENGINE_OUTPUT_numconnections); \
00213     } \
00214   } while (0)
00215 
00216 #define SO_COMPOSE__HEADER(_name_) \
00217   SO_ENGINE_HEADER(_name_); \
00218   private: \
00219     virtual void evaluate(); \
00220   protected: \
00221     ~_name_();\
00222   public: \
00223    _name_(); \
00224     static void initClass()
00225 
00226 #endif // !COIN_SOSUBENGINE_H

Copyright © 1998-2004 by Systems in Motion AS. All rights reserved.

Generated on Sat Sep 3 10:55:24 2005 for Coin by Doxygen. 1.4.4