OMKInputListener.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_IN_INPUTLISTENER_H
00022 #define OMK_IN_INPUTLISTENER_H
00023 
00024 #include "OBTPrototypeFactory.h"
00025 #include "OMKName.h"
00026 #include "OMKExtensibleSimulatedObject.h"
00027 #include "OISKeyboard.h"
00028 #include "OISMouse.h"
00029 #include "OISJoyStick.h"
00030 #include "OMKInputs.h"
00031 
00032 namespace OMK
00033 {
00034 class ConfigurationParameterDescriptor ;
00035 class EventIdentifier ;
00036 class ExtensibleSimulatedObject ;
00037 namespace Inp
00038 {
00039 class InputExtension ;
00040 
00053 class OMKINPUTS_API InputListener
00054 {
00055 protected:
00058   InputListener( ExtensibleSimulatedObject* sender, const Name& id, 
00059           const ConfigurationParameterDescriptor* node ) ;
00060 public:
00062   static OIS::KeyCode retrieveCode( const std::string& code ) ;
00075   static bool retrieveCodeFromConfig( const ConfigurationParameterDescriptor * node,
00076                                       const std::string &keyId,
00077                                       OIS::KeyCode &keyCode ) ;
00078 public:
00079   virtual ~InputListener() ;
00080   const Name& getId() const ;
00081 protected:
00082   void sendEvent( const Name& receiver, const EventIdentifier & eventId ) ; 
00083   template< typename UserType> 
00084   void sendValuedEvent( const Name& receiver, const EventIdentifier & eventId, const UserType & prm ) ;
00085 protected:
00086   Name _id ;
00087   ExtensibleSimulatedObject* _sender ;
00088 } ;
00089 inline const Name& InputListener::getId() const { return _id ; } 
00090 template< typename UserType> 
00091 inline void InputListener::sendValuedEvent( const Name& receiver, const EventIdentifier & eventId, const UserType & prm ) 
00092 {
00093   _sender->sendValuedEvent( receiver, eventId, prm ) ;
00094 }
00095   
00103 class InputListenerCreator
00104 {
00105 public:
00106   virtual ~InputListenerCreator(){}
00107   virtual InputListener* operator()
00108         ( ExtensibleSimulatedObject* sender, const Name& id, 
00109       const ConfigurationParameterDescriptor* node ) const
00110   {
00111     OMERROR( "Creator is not registered for" << std::endl << *node ) ;
00112     throw Exception( "Creator is not registered" ) ;
00113     return 0 ;
00114   }
00115 } ;
00116 
00117 typedef OBT::Singleton< OBT::PrototypeFactory< OMK::Name, InputListenerCreator > > InputListenerFactory ;
00118 
00124 template <class T>
00125 class InputListenerCreatorT : public InputListenerCreator
00126 {
00127 public:
00128 
00129   typedef T object_to_create ;
00130 
00131   virtual ~InputListenerCreatorT(){}
00132   InputListener* operator()
00133     ( ExtensibleSimulatedObject* sender, const Name& instanceId, 
00134       const ConfigurationParameterDescriptor* node ) const
00135   {
00136     return new T( sender, instanceId, node ) ;
00137   }
00138 } ;
00139   
00140   } // namespace Inp
00141 } // namespace OMK
00142 
00143 template class OMKINPUTS_API OBT::PrototypeFactory< OMK::Name, OMK::Inp::InputListenerCreator > ;
00144 template class OMKINPUTS_API OBT::Singleton< OBT::PrototypeFactory< OMK::Name, OMK::Inp::InputListenerCreator > > ;
00145 
00152 #define DECLARE_INPUT_LISTENER_FACTORY( InputListenerClass ) \
00153 public: \
00154  \
00155   friend class OMK::Inp::InputListenerCreatorT< InputListenerClass > ; \
00156  \
00157   static OMK::Name OMK_CLASS_ID ; \
00158  \
00159   static const bool REGISTERED_IN_INPUT_LISTENER_FACTORY ; \
00160 protected: \
00161  \
00163    InputListenerClass( OMK::ExtensibleSimulatedObject* sender, const OMK::Name& instanceId, \
00164                        const OMK::ConfigurationParameterDescriptor* node ) ; \
00165 public: \
00166         virtual ~InputListenerClass() 
00167   
00174 #define REGISTER_INPUT_LISTENER_FACTORY( InputListenerClass, Id )\
00175   /* Factory */ \
00176   Name InputListenerClass::OMK_CLASS_ID( Id ) ; \
00177   const bool InputListenerClass::REGISTERED_IN_INPUT_LISTENER_FACTORY( OMK::Inp::InputListenerFactory::getInstance().registerCreator< OMK::Inp::InputListenerCreatorT< InputListenerClass > >( Id ) )  
00178 
00179 #endif // OMK_IN_INPUTLISTENER_H

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007