OMKIConvertor.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-2002, 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_III_ICONVERTOR_H
00024 #define OMK_III_ICONVERTOR_H
00025 
00026 #include <vector>
00027 #include <map>
00028 #include "OBTPrototypeFactory.h"
00029 #include "OMKName.h"
00030 #include "OMKInteraction.h"
00031 #include "OMKTransform.h"
00032 #include "OMKException.h"
00033 #include "OMKConfigurationParameterDescriptor.h"
00034 
00035 namespace OMK  
00036 {
00037 class ConfigurationParameterDescriptor ;
00038 namespace Iii  
00039 {
00040 
00074 #define DECLARE_TEMPLATE_CONVERTOR_FACTORY( ConvertorClass, TypeOut, TypeIn ) \
00075 public: \
00076  \
00077   friend class OMK::Iii::ConvertorCreatorT< TypeOut, TypeIn, ConvertorClass< TypeOut > > ; \
00078  \
00079   static OMK::Name OMK_CLASS_ID ; \
00080  \
00081   static const bool REGISTERED_IN_CONVERTOR_FACTORY ; \
00082 protected: \
00083  \
00085         ConvertorClass( const ConfigurationParameterDescriptor* node ) ; \
00086 public: \
00087         virtual ~ConvertorClass() ; \
00088   virtual void convert( TypeOut& value, const TypeIn& newValue )
00089 
00105 #define DECLARE_CONVERTOR_FACTORY( ConvertorClass, TypeOut, TypeIn ) \
00106 public: \
00107  \
00108   friend class OMK::Iii::ConvertorCreatorT< TypeOut, TypeIn, ConvertorClass > ; \
00109  \
00110   static OMK::Name OMK_CLASS_ID ;                             \
00111  \
00112   static const bool REGISTERED_IN_CONVERTOR_FACTORY ; \
00113 protected: \
00114  \
00116   ConvertorClass( const OMK::ConfigurationParameterDescriptor* node ) ;  \
00117 public: \
00118   virtual ~ConvertorClass() ; \
00119   virtual void convert(  TypeOut& value, const TypeIn& newValue )
00120 
00144 #define REGISTER_TEMPLATE_CONVERTOR_FACTORY( ConvertorClass, TypeOut, TypeIn, Id )\
00145   /* Factory */ \
00146   template <> OMK::Name ConvertorClass::OMK_CLASS_ID( Id ) ;                \
00147   template <> const bool ConvertorClass::REGISTERED_IN_CONVERTOR_FACTORY( OBT::Singleton< OMK::Iii::ConvertorFactoryT< TypeOut, TypeIn > >::getInstance().registerCreator< OMK::Iii::ConvertorCreatorT< TypeOut, TypeIn, ConvertorClass > >( Id ) )
00148 
00166 #define REGISTER_CONVERTOR_FACTORY( ConvertorClass, TypeOut, TypeIn, Id )\
00167   /* Factory */ \
00168   OMK::Name ConvertorClass::OMK_CLASS_ID( Id ) ;                        \
00169   const bool ConvertorClass::REGISTERED_IN_CONVERTOR_FACTORY( OBT::Singleton< OMK::Iii::ConvertorFactoryT< TypeOut, TypeIn > >::getInstance().registerCreator< OMK::Iii::ConvertorCreatorT< TypeOut, TypeIn, ConvertorClass > >( Id ) )
00170 
00172 
00173 //-----------------------------------------------------------------
00174 
00196 template< typename TypeOut, typename TypeIn >
00197 class IConvertorT
00198 { 
00199 public:
00200   virtual ~IConvertorT() {}
00204   virtual void convert( TypeOut& value, const TypeIn& newValue ) = 0 ;
00207   static IConvertorT< TypeOut, TypeIn >* create( const ConfigurationParameterDescriptor* node ) ;
00208 } ;
00209 //-----------------------------------------------------------------
00210 
00211 //-----------------------------------------------------------------------------
00222 template< typename TypeOut, typename TypeIn >
00223 class IConvertorCreator
00224 {
00225 public:
00226   virtual ~IConvertorCreator() {}
00227   virtual IConvertorT< TypeOut, TypeIn >* operator()( const ConfigurationParameterDescriptor* node ) const
00228   {
00229     OMERROR( "Creator is not registered" << std::endl << *node ) ;
00230     throw Exception( "Creator is not registered" ) ;
00231     return 0 ;
00232   }
00233 } ;
00234 
00235 //-----------------------------------------------------------------------------
00251 template < typename TypeOut, typename TypeIn, class ConvertorType >
00252 class ConvertorCreatorT : public IConvertorCreator< TypeOut, TypeIn >
00253 {
00254 public:
00255   virtual ~ConvertorCreatorT() {}
00256   virtual IConvertorT< TypeOut, TypeIn >* operator()( const ConfigurationParameterDescriptor* node ) const
00257         {
00258                 return new ConvertorType( node ) ;
00259         }
00260 } ;
00261 
00262 //-----------------------------------------------------------------------------
00281 template< typename TypeIn, typename TypeOut >
00282 class ConvertorFactoryT
00283 {
00284   friend class OBT::Singleton< ConvertorFactoryT< TypeIn, TypeOut > > ;
00285   ConvertorFactoryT() {}
00286 public :
00291   const IConvertorCreator< TypeIn, TypeOut >& create( const Name& classId ) const 
00292   {
00293     return OBT::Singleton< OBT::PrototypeFactory< OMK::Name, IConvertorCreator< TypeIn, TypeOut > > >::getInstance().create( classId ) ;
00294   }
00296   template < class TDerivedCreator > bool registerCreator( const Name& classId ) 
00297   {
00298     return OBT::Singleton< OBT::PrototypeFactory< OMK::Name, IConvertorCreator< TypeIn, TypeOut > > >::getInstance().registerCreator<TDerivedCreator>( classId ) ;
00299   }
00300 } ;
00301 
00302 }// namespace Iii
00303 }// namespace OMK
00304 
00305 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< OMK::Type::Transform , std::vector< OMK::Type::Transform  > > > ;
00306 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< float , std::vector< float  > > > ;
00307 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< double , std::vector< double  > > > ;
00308 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< int , int > > ;
00309 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< float , float > > ;
00310 template class OMKIII_API OBT::Singleton< OMK::Iii::ConvertorFactoryT< double , double > > ;
00311 
00312 #include "OMKIConvertor.inl"
00313 
00314 #endif // defined OMK_III_ICONVERTOR_H

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007