OMKAnimator.h

Go to the documentation of this file.
00001 /************************************************************************/
00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00003 /* 1993-2002, thereinafter the Software                                 */
00004 /*                                                                      */
00005 /* The Software has been developped within the Siames Project.          */
00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00007 /* property rights                                                      */
00008 /*                                                                      */
00009 /* The Software has been registered with the Agence pour la Protection  */
00010 /* des Programmes (APP) under registration number                       */
00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00012 /*                                                                      */
00013 /* This file may be distributed under the terms of the Q Public License */
00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00015 /* the file LICENSE.QPL included in the packaging of this file.         */
00016 /*                                                                      */
00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00018 /* Universite Rennes 1 for the software may use this file in            */
00019 /* acordance with that specific license                                 */
00020 /************************************************************************/
00021 #ifndef OMK_VIS_ANIMATOR_H
00022 #define OMK_VIS_ANIMATOR_H
00023 
00024 #include "OBTPrototypeFactory.h"
00025 #include "OMKVis.h"
00026 
00027 namespace OMK  
00028 {
00029 class ConfigurationParameterDescriptor ;
00030 namespace Vis 
00031 {
00032 class VisBase ;
00033 class AnimatorPlug ;
00048 class OMKVIS_API Animator
00049 {
00050 public:
00051 
00053 
00054 
00055   virtual ~Animator() ;
00057 
00061   virtual void processVis() ;
00062   
00064   const Name& getId() const ;
00065 
00067   const VisualObject& getVisualObject() const ;
00069   VisualObject& getVisualObject() ;
00070   
00072   template < typename T > T* getTemplateNode (  );
00073 protected:
00074 
00076 
00077 
00078   Animator( VisualObject& visualObject, const Name& id, const ConfigurationParameterDescriptor& node ) ;
00080   Animator( VisualObject& visualObject, const Name& id );
00081 
00083 
00085 
00086 
00087 
00088 
00089 
00090   virtual void selfProcessVis() = 0 ;
00092 
00094   AnimatorPlug* _plugUpdate ;
00095   
00096  
00097 private:
00098 
00100   Name _id ;
00101 
00104   VisualObject& _visualObject ;
00105   
00106 protected: 
00108   void * _tNode;
00109  
00110 } ;
00120 #define DECLARE_ANIMATOR_FACTORY( AnimatorClass ) \
00121 public: \
00122  \
00123   friend class OMK::Vis::AnimatorCreatorT< AnimatorClass > ; \
00124  \
00125   static OMK::Name OMK_CLASS_ID ; \
00126  \
00127   static const bool REGISTERED_IN_ANIMATOR_FACTORY ; \
00128 protected: \
00129  \
00131   AnimatorClass( OMK::Vis::VisualObject& visualObject, const OMK::Name& id, const OMK::ConfigurationParameterDescriptor& node ) ; \
00132 public: \
00133   virtual ~AnimatorClass() 
00134 
00141 #define DECLARE_TEMPLATE_ANIMATOR_FACTORY( AnimatorClass, Type ) \
00142 public: \
00143  \
00144   friend class OMK::Vis::AnimatorCreatorT< AnimatorClass< Type > > ; \
00145  \
00146   static OMK::Name OMK_CLASS_ID ; \
00147  \
00148   static const bool REGISTERED_IN_ANIMATOR_FACTORY ; \
00149 protected: \
00150  \
00152   AnimatorClass( OMK::Vis::VisualObject& visualObject, const OMK::Name& id, const OMK::ConfigurationParameterDescriptor& node ) ; \
00153 public: \
00154   virtual ~AnimatorClass() 
00155 
00163 #define REGISTER_ANIMATOR_FACTORY( AnimatorClass, Id )\
00164   /* Factory */ \
00165   OMK::Name AnimatorClass::OMK_CLASS_ID( Id ) ; \
00166   const bool AnimatorClass::REGISTERED_IN_ANIMATOR_FACTORY( OMK::Vis::AnimatorFactory::getInstance().registerCreator< OMK::Vis::AnimatorCreatorT< AnimatorClass > >( Id ) )
00167 
00174 #define REGISTER_TEMPLATE_ANIMATOR_FACTORY( AnimatorClass, Id )\
00175   /* Factory */ \
00176   template <> OMK::Name AnimatorClass::OMK_CLASS_ID( Id ) ; \
00177   template <> const bool AnimatorClass::REGISTERED_IN_ANIMATOR_FACTORY( OMK::Vis::AnimatorFactory::getInstance().registerCreator< OMK::Vis::AnimatorCreatorT< AnimatorClass > >( Id ) )
00178 
00179 
00180 //-----------------------------------------------------------------------------
00184 class AnimatorCreator
00185 {
00186 public:
00187   virtual ~AnimatorCreator() {}
00188   virtual Animator* operator()( VisualObject& visualObject,
00189                   const Name& instanceId, 
00190                   const ConfigurationParameterDescriptor& node  ) const
00191   {
00192     OMERROR( "Creator is not registered for \"" << instanceId << "\"" << std::endl << node ) ;
00193     throw Exception( "Creator is not registered" ) ;
00194     return 0 ;
00195   }
00196 } ;
00197 
00198 
00199 //-----------------------------------------------------------------------------
00203 template <class T>
00204 class AnimatorCreatorT : public AnimatorCreator
00205 {
00206 public:
00207   virtual ~AnimatorCreatorT() {}
00208 
00209   typedef T object_to_create ;
00210 
00211   Animator* operator()( VisualObject& visualObject,
00212               const Name& instanceId, 
00213               const ConfigurationParameterDescriptor& node ) const
00214   {
00215     return new T( visualObject, instanceId, node ) ;
00216   }
00217 } ;
00218 
00219 //-------------------------------------------------------------------------
00220 // getId
00221 //-------------------------------------------------------------------------
00222 inline const Name& 
00223 Animator::getId() const 
00224 {
00225   return _id ;
00226 }
00227 //-------------------------------------------------------------------------
00228 //const  getVisualObject
00229 //-------------------------------------------------------------------------
00230 inline const VisualObject& Animator::getVisualObject() const 
00231 {
00232   return _visualObject ;
00233 }
00234 //-------------------------------------------------------------------------
00235 // getVisualObject
00236 //-------------------------------------------------------------------------
00237 inline  VisualObject& Animator::getVisualObject()
00238 {
00239   return _visualObject ;
00240 }
00241 //-------------------------------------------------------------------------
00242 // getTemplateNode
00243 //-------------------------------------------------------------------------
00244 template < typename T > inline T* Animator::getTemplateNode( )
00245 {
00246   return (T *) _tNode ;
00247 }
00248 
00249 typedef OBT::Singleton< OBT::PrototypeFactory< OMK::Name, Vis::AnimatorCreator > > AnimatorFactory ;
00250 
00254 std::string OMKVIS_API debugMsg( const Vis::Animator* anim ) ;
00255 }// namespace Vis
00256 }// namespace OMK
00257 
00258 template class OMKVIS_API OBT::PrototypeFactory< OMK::Name, OMK::Vis::AnimatorCreator > ;
00259 template class OMKVIS_API OBT::Singleton< OBT::PrototypeFactory< OMK::Name, OMK::Vis::AnimatorCreator > > ;
00260 
00261 #endif // OMK_VIS_ANIMATOR_H

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007