Main Page Modules Class Hierarchy Alphabetical List Compound List File List Compound Members

# SoSubEngine.h

    00001 /**************************************************************************\
    00002  *
    00003  *  This file is part of the Coin 3D visualization library.
    00004  *  Copyright (C) 1998-2003 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     _class_::classinstances++; \
    00121     /* Catch attempts to use an engine class which has not been initialized. */ \
    00122     assert(_class_::classTypeId != SoType::badType()); \
    00123     /* Initialize a inputdata container for the class only once. */ \
    00124     if (!_class_::inputdata) { \
    00125       _class_::inputdata = \
    00126         new SoFieldData(_class_::parentinputdata ? \
    00127                         *_class_::parentinputdata : NULL); \
    00128       _class_::outputdata = \
    00129         new SoEngineOutputData(_class_::parentoutputdata ? \
    00130                                *_class_::parentoutputdata : NULL); \
    00131     } \
    00132     /* Extension classes from the application programmers should not be */ \
    00133     /* considered native. This is important to get the export code to do */ \
    00134     /* the Right Thing. */ \
    00135     this->isBuiltIn = FALSE; \
    00136   } while (0)
    00137
    00138
    00139 #define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
    00140   do { \
    00141     /* Make sure we only initialize once. */ \
    00142     assert(_class_::classTypeId == SoType::badType()); \
    00143     /* Make sure superclass gets initialized before subclass. */ \
    00144     assert(_parentclass_::getClassTypeId() != SoType::badType()); \
    00145  \
    00146     /* Set up entry in the type system. */ \
    00147     _class_::classTypeId = \
    00148       SoType::createType(_parentclass_::getClassTypeId(), \
    00149                          _classname_, \
    00150                          _createfunc_); \
    00151  \
    00152     /* Store parent's data pointers for later use in the constructor. */ \
    00153     _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
    00154     _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
    00155   } while (0)
    00156
    00157
    00158 #define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
    00159   do { \
    00160     const char * classname = SO__QUOTE(_class_); \
    00161     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
    00162   } while (0)
    00163
    00164
    00165 #define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
    00166   do { \
    00167     const char * classname = SO__QUOTE(_class_); \
    00168     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
    00169   } while (0)
    00170
    00171
    00172 #define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
    00173   do { \
    00174     this->_input_.setValue _defaultval_;\
    00175     this->_input_.setContainer(this); \
    00176     if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
    00177       inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
    00178     } \
    00179   } while (0)
    00180
    00181 #define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
    00182   do { \
    00183     if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
    00184       outputdata->addOutput(this, SO__QUOTE(_output_), \
    00185                             &this->_output_, \
    00186                             _type_::getClassTypeId()); \
    00187     } \
    00188     this->_output_.setContainer(this); \
    00189   } while(0)
    00190
    00191
    00192 #define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
    00193   do { \
    00194     if (SO_ENGINE_IS_FIRST_INSTANCE()) \
    00195       inputdata->addEnumValue(SO__QUOTE(_enumname_), \
    00196                               SO__QUOTE(_enumval_), _enumval_); \
    00197   } while (0)
    00198
    00199 #define SO_ENGINE_OUTPUT(_engineout_, _fieldtype_, _writeop_) \
    00200   do { \
    00201     if (_engineout_.isEnabled()) { \
    00202       /* No fields can be added or removed during this loop, as it */ \
    00203       /* is a "closed" operation. (The fields are disabled for */ \
    00204       /* notification while the loop runs). */ \
    00205       int SO_ENGINE_OUTPUT_numconnections = _engineout_.getNumConnections(); \
    00206       /* The reason we use the perverted variable names is to */ \
    00207       /* avoid the possibility of getting _extremely_ hard */ \
    00208       /* to find bugs when _writeop_ contains the same variable */ \
    00209       /* names we are using internally in the macro. */ \
    00210       for (int SO_ENGINE_OUTPUT_i = 0; SO_ENGINE_OUTPUT_i < SO_ENGINE_OUTPUT_numconnections; SO_ENGINE_OUTPUT_i++) { \
    00211         _fieldtype_ * SO_ENGINE_OUTPUT_field = (_fieldtype_*) _engineout_[SO_ENGINE_OUTPUT_i]; \
    00212         if (!SO_ENGINE_OUTPUT_field->isReadOnly()) { SO_ENGINE_OUTPUT_field->_writeop_; } \
    00213       } \
    00214       /* paranoid assertion */ \
    00215       assert(_engineout_.getNumConnections() == SO_ENGINE_OUTPUT_numconnections); \
    00216     } \
    00217   } while (0)
    00218
    00219 #define SO_COMPOSE__HEADER(_name_) \
    00220   SO_ENGINE_HEADER(_name_); \
    00221   private: \
    00222     virtual void evaluate(); \
    00223   protected: \
    00224     ~_name_();\
    00225   public: \
    00226    _name_(); \
    00227     static void initClass()
    00228
    00229 #endif // !COIN_SOSUBENGINE_H