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-2002 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 Lesser General Public License
00008  *  version 2.1 as published by the Free Software Foundation. See the
00009  *  file LICENSE.LGPL at the root directory of the distribution for
00010  *  more details.
00011  *
00012  *  If you want to use Coin for applications not compatible with the
00013  *  LGPL, please contact SIM to acquire a Professional Edition license.
00014  *
00015  *  Systems in Motion, Prof Brochs gate 6, 7030 Trondheim, NORWAY
00016  *  http://www.sim.no support@sim.no Voice: +47 22114160 Fax: +47 22207097
00017  *
00018 \**************************************************************************/
00019 
00020 #ifndef COIN_SOSUBENGINE_H
00021 #define COIN_SOSUBENGINE_H
00022 
00023 #include <Inventor/SbName.h>
00024 #include <Inventor/SoType.h>
00025 #include <Inventor/engines/SoEngine.h>
00026 #include <Inventor/engines/SoOutputData.h>
00027 #include <Inventor/fields/SoFieldData.h>
00028 #include <assert.h>
00029 
00030 //
00031 // FIXME: document macros. pederb, 20000309
00032 //
00033 
00034 #define PRIVATE_ENGINE_TYPESYSTEM_HEADER( ) \
00035 public: \
00036   static SoType getClassTypeId(void); \
00037   virtual SoType getTypeId(void) const; \
00038 private: \
00039   static SoType classTypeId
00040 
00041 #define SO_ENGINE_ABSTRACT_HEADER(_classname_) \
00042   PRIVATE_ENGINE_TYPESYSTEM_HEADER(); \
00043 protected: \
00044   static const SoFieldData ** getInputDataPtr(void); \
00045   static const SoEngineOutputData ** getOutputDataPtr(void); \
00046 public: \
00047   virtual const SoFieldData * getFieldData(void) const; \
00048   virtual const SoEngineOutputData * getOutputData(void) const; \
00049 private: \
00050   static unsigned int classinstances; \
00051   static SoFieldData * inputdata; \
00052   static const SoFieldData ** parentinputdata; \
00053   static SoEngineOutputData * outputdata; \
00054   static const SoEngineOutputData ** parentoutputdata
00055 
00056 #define SO_ENGINE_HEADER(_classname_) \
00057     SO_ENGINE_ABSTRACT_HEADER(_classname_); \
00058   public: \
00059     static void * createInstance(void)
00060 
00061 
00062 #define PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_) \
00063 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
00064 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
00065 /* Don't set value explicitly to SoType::badType(), to avoid a bug in */ \
00066 /* Sun CC v4.0. (Bitpattern 0x0000 equals SoType::badType()). */ \
00067 SoType _class_::classTypeId
00068 
00069 #define SO_ENGINE_ABSTRACT_SOURCE(_class_) \
00070 PRIVATE_ENGINE_TYPESYSTEM_SOURCE(_class_); \
00071  \
00072 unsigned int _class_::classinstances = 0; \
00073 SoFieldData * _class_::inputdata = NULL; \
00074 const SoFieldData ** _class_::parentinputdata = NULL; \
00075 SoEngineOutputData * _class_::outputdata = NULL; \
00076 const SoEngineOutputData ** _class_::parentoutputdata = NULL; \
00077  \
00078 const SoFieldData ** \
00079 _class_::getInputDataPtr(void) \
00080 { \
00081   return (const SoFieldData **)&_class_::inputdata; \
00082 } \
00083  \
00084 const SoFieldData * \
00085 _class_::getFieldData(void) const \
00086 { \
00087   return _class_::inputdata; \
00088 } \
00089  \
00090 const SoEngineOutputData ** \
00091 _class_::getOutputDataPtr(void) \
00092 { \
00093   return (const SoEngineOutputData**)&_class_::outputdata; \
00094 } \
00095  \
00096 const SoEngineOutputData * \
00097 _class_::getOutputData(void) const \
00098 { \
00099   return _class_::outputdata; \
00100 }
00101 
00102 #define SO_ENGINE_SOURCE(_class_) \
00103 SO_ENGINE_ABSTRACT_SOURCE(_class_); \
00104  \
00105 void * \
00106 _class_::createInstance(void) \
00107 { \
00108   return new _class_; \
00109 }
00110 
00111 #define SO_ENGINE_IS_FIRST_INSTANCE() \
00112   (classinstances == 1)
00113 
00114 #define SO_ENGINE_CONSTRUCTOR(_class_) \
00115   do { \
00116     _class_::classinstances++; \
00117     /* Catch attempts to use an engine class which has not been initialized. */ \
00118     assert(_class_::classTypeId != SoType::badType()); \
00119     /* Initialize a inputdata container for the class only once. */ \
00120     if (!_class_::inputdata) { \
00121       _class_::inputdata = \
00122         new SoFieldData(_class_::parentinputdata ? \
00123                         *_class_::parentinputdata : NULL); \
00124       _class_::outputdata = \
00125         new SoEngineOutputData(_class_::parentoutputdata ? \
00126                                *_class_::parentoutputdata : NULL); \
00127     } \
00128     /* Extension classes from the application programmers should not be \
00129        considered native. This is important to get the export code to do \
00130        the Right Thing. */ \
00131     this->isBuiltIn = FALSE; \
00132   } while (0)
00133 
00134 
00135 #define PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, _classname_, _createfunc_, _parentclass_) \
00136   do { \
00137     /* Make sure we only initialize once. */ \
00138     assert(_class_::classTypeId == SoType::badType()); \
00139     /* Make sure superclass gets initialized before subclass. */ \
00140     assert(_parentclass_::getClassTypeId() != SoType::badType()); \
00141  \
00142     /* Set up entry in the type system. */ \
00143     _class_::classTypeId = \
00144       SoType::createType(_parentclass_::getClassTypeId(), \
00145                          _classname_, \
00146                          _createfunc_); \
00147  \
00148     /* Store parent's data pointers for later use in the constructor. */ \
00149     _class_::parentinputdata = _parentclass_::getInputDataPtr(); \
00150     _class_::parentoutputdata = _parentclass_::getOutputDataPtr(); \
00151   } while (0)
00152 
00153 
00154 #define SO_ENGINE_INIT_CLASS(_class_, _parentclass_, _parentname_) \
00155   do { \
00156     const char * classname = SO__QUOTE(_class_); \
00157     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, &_class_::createInstance, _parentclass_); \
00158   } while (0)
00159 
00160 
00161 #define SO_ENGINE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
00162   do { \
00163     const char * classname = SO__QUOTE(_class_); \
00164     PRIVATE_COMMON_ENGINE_INIT_CODE(_class_, classname, NULL, _parentclass_); \
00165   } while (0)
00166 
00167 
00168 #define SO_ENGINE_ADD_INPUT(_input_, _defaultval_) \
00169   do { \
00170     this->_input_.setValue _defaultval_;\
00171     this->_input_.setContainer(this); \
00172     if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
00173       inputdata->addField(this, SO__QUOTE(_input_), &this->_input_);\
00174     } \
00175   } while (0)
00176 
00177 #define SO_ENGINE_ADD_OUTPUT(_output_, _type_) \
00178   do { \
00179     if (SO_ENGINE_IS_FIRST_INSTANCE()) { \
00180       outputdata->addOutput(this, SO__QUOTE(_output_), \
00181                             &this->_output_, \
00182                             _type_::getClassTypeId()); \
00183     } \
00184     this->_output_.setContainer(this); \
00185   } while(0)
00186 
00187 
00188 #define SO_ENGINE_DEFINE_ENUM_VALUE(_enumname_, _enumval_) \
00189   do { \
00190     if (SO_ENGINE_IS_FIRST_INSTANCE()) \
00191       inputdata->addEnumValue(SO__QUOTE(_enumname_), \
00192                               SO__QUOTE(_enumval_), _enumval_); \
00193   } while (0)
00194 
00195 #define SO_ENGINE_OUTPUT(_outmember_,_outtype_,_outval_) \
00196   do { \
00197     if (_outmember_.isEnabled()) \
00198       for (int SO_ENGINE_OUTPUT_i = 0; \
00199            SO_ENGINE_OUTPUT_i < _outmember_.getNumConnections(); \
00200            SO_ENGINE_OUTPUT_i++) { \
00201         _outtype_ * field = (_outtype_*) _outmember_[SO_ENGINE_OUTPUT_i]; \
00202         if (!field->isReadOnly()) \
00203            ((_outtype_ *)_outmember_[SO_ENGINE_OUTPUT_i])->_outval_; \
00204       } \
00205   } while (0)
00206 
00207 #define SO_COMPOSE__HEADER(_name_) \
00208   SO_ENGINE_HEADER(_name_); \
00209   private: \
00210     virtual void evaluate(); \
00211   protected: \
00212     ~_name_();\
00213   public: \
00214    _name_(); \
00215     static void initClass()
00216 
00217 #endif // !COIN_SOSUBENGINE_H

Generated at Tue Mar 5 03:31:17 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001