OMKExtension.h

Go to the documentation of this file.
00001 
00002 /************************************************************************/
00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00004 /* 1993-2007, thereinafter the Software                                 */
00005 /*                                                                      */
00006 /* The Software has been developped within the Siames Project.          */
00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00008 /* property rights                                                      */
00009 /*                                                                      */
00010 /* The Software has been registered with the Agence pour la Protection  */
00011 /* des Programmes (APP) under registration number                       */
00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00013 /*                                                                      */
00014 /* This file may be distributed under the terms of the Q Public License */
00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00016 /* the file LICENSE.QPL included in the packaging of this file.         */
00017 /*                                                                      */
00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00019 /* Universite Rennes 1 for the software may use this file in            */
00020 /* acordance with that specific license                                 */
00021 /************************************************************************/
00022                 
00023 #if !defined OMK_EXTENSION_H
00024 #define OMK_EXTENSION_H
00025 
00026 #include "OMKSimulatedObject.h"
00027 #include "OBTPrototypeFactory.h"
00028 
00039 #define DECLARE_EXTENSION_FACTORY( ExtensionClass ) \
00040 public: \
00041  \
00042   friend class OMK::ExtensionCreatorT< ExtensionClass > ; \
00043  \
00044   static OMK::Name OMK_CLASS_ID ; \
00045  \
00046   static const bool REGISTERED_IN_EXTENSION_FACTORY ; \
00047 protected: \
00048  \
00050    ExtensionClass( OMK::ExtensibleSimulatedObject* owner, const OMK::Name& id, bool registerExtension = true ) ; \
00051 public: \
00052         virtual ~ExtensionClass() 
00053   
00060 #define DECLARE_TEMPLATE_EXTENSION_FACTORY( ExtensionClass, Type ) \
00061 public: \
00062  \
00063   friend class OMK::ExtensionCreatorT< ExtensionClass< Type > > ; \
00064  \
00065   static OMK::Name OMK_CLASS_ID ; \
00066  \
00067   static const bool REGISTERED_IN_EXTENSION_FACTORY ; \
00068 protected: \
00069  \
00071    ExtensionClass( OMK::ExtensibleSimulatedObject* owner, const OMK::Name& id, bool registerExtension = true ) ; \
00072 public: \
00073   virtual ~ExtensionClass() 
00074 
00081 #define REGISTER_EXTENSION_FACTORY( ExtensionClass, Id )\
00082   /* Factory */ \
00083   Name ExtensionClass::OMK_CLASS_ID( Id ) ; \
00084   const bool ExtensionClass::REGISTERED_IN_EXTENSION_FACTORY( OMK::ExtensionFactory::getInstance().registerCreator< OMK::ExtensionCreatorT< ExtensionClass > >( Id ) )  
00085 
00091 #define REGISTER_TEMPLATE_EXTENSION_FACTORY( ExtensionClass, Id )\
00092   /* Factory */ \
00093   template <> Name ExtensionClass::OMK_CLASS_ID( Id ) ; \
00094   template <> const bool ExtensionClass::REGISTERED_IN_EXTENSION_FACTORY( OMK::ExtensionFactory::getInstance().registerCreator< OMK::ExtensionCreatorT< ExtensionClass > >( Id ) )
00095 
00096 
00097 namespace OMK  
00098 {
00099 // Predefined classes
00100 class ExtensibleSimulatedObject ;
00101 //-------------------------------------------------------------------------
00102 
00116 class OMK_API Extension
00117 {
00119 
00120 protected:
00128   Extension( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension = true ) ;
00129 public:
00131   virtual ~Extension() {}
00133 public:
00135 
00136 
00137   const Name& getId() const { return _id ; }
00139 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151   virtual bool loadObjectParameters( const ConfigurationParameterDescriptor * node ) ;
00162   virtual bool loadExtensionParameters( const ConfigurationParameterDescriptor * node ) ;
00164 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179   virtual void preComputeParameters() {}
00191   virtual void postComputeParameters() {}
00193 
00195   Name _id ;
00196 } ;
00197 
00198 //-----------------------------------------------------------------------------
00216 template< class SimulatedObjectType >
00217 class ExtensionT : public Extension
00218 {
00220 
00221 protected:
00223         ExtensionT( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension = true ) ;
00225 public:
00226   virtual ~ExtensionT() {}
00228 
00229 protected:
00233   SimulatedObjectType* _owner ;
00234 public:
00235   SimulatedObjectType* getOwner() const { return _owner ; }
00236 } ;
00237 
00238 //-----------------------------------------------------------------------------
00246 class ExtensionCreator
00247 {
00248 public:
00249   virtual ~ExtensionCreator(){}
00250   virtual Extension* operator()( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension = true ) const
00251   {
00252     OMERROR( "Creator is not registered for \"" << id << "\"" ) ;
00253     throw Exception( "Creator is not registered" ) ;
00254     return 0 ;
00255   }
00256 } ;
00257 
00258 //-----------------------------------------------------------------------------
00264 template <class T>
00265 class ExtensionCreatorT : public ExtensionCreator
00266 {
00267 public:
00268 
00269         typedef T object_to_create ;
00270   virtual ~ExtensionCreatorT(){}
00271   Extension* operator()( ExtensibleSimulatedObject* owner, const Name& id, bool registerExtension = true ) const
00272         {
00273                 return new T( owner, id, registerExtension ) ;
00274         }
00275 } ;
00276 }// namespace OMK
00277 
00278 #include "OMKExtension.inl"
00279 namespace OMK
00280 {
00281 //-----------------------------------------------------------------------------
00305 typedef OBT::Singleton< OBT::PrototypeFactory< OMK::Name, ExtensionCreator > > ExtensionFactory ;
00306 }// namespace OMK
00307 
00308 template class OMK_API OBT::PrototypeFactory< OMK::Name, OMK::ExtensionCreator > ;
00309 template class OMK_API OBT::Singleton< OBT::PrototypeFactory< OMK::Name, OMK::ExtensionCreator > > ;
00310 
00311 #endif // defined OMK_EXTENSION_H

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007