OMKValuedEvent.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask � INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Universit� de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #ifndef OMKValuedEventHEADER
00019 #define OMKValuedEventHEADER
00020 
00021 #include "OMKEvent.h"
00022 #include "OMKEventCreator.h"
00023 #include "OMKBaseType.h" 
00024 
00025 namespace OMK
00026 {
00031 template <typename UserType >
00032 class ValuedEvent : public Event 
00033 {
00034 public:
00035 
00037   UserType value ; 
00038   
00040   ValuedEvent( const ValuedEvent & originalEvent );
00041   
00043   ValuedEvent & operator = ( const ValuedEvent & originalEvent );
00044   
00045 
00047   virtual ValuedEvent * clone() const ;
00048 
00049   
00052   virtual void insertInStream (std::ostream & = std::cout) const;
00053 
00054   
00057   virtual void extract (std::istream & = std::cin);
00058 
00059 
00060 
00065   virtual void unpack (IncomingSynchronisationMessage &) ;
00066 
00067 
00068 
00070   virtual void pack (OutgoingSynchronisationMessage &) const ;
00071 
00072 
00073 
00074 
00081   ValuedEvent(const EventIdentifier & event, const Date & date, const Name & sender, const Name & receiver, const UserType & userValue );
00082   
00088   ValuedEvent(const EventIdentifier & event, const Date & date, const Name & sender, const Name & receiver) ;
00089 
00090   
00092   virtual ~ValuedEvent();
00093   
00094 protected:
00095   class ValuedEventCreator : public EventCreator
00096   {
00097   public:
00098     ValuedEventCreator () : EventCreator ( typeid( ValuedEvent<UserType> ).name() ) {}
00099     virtual ~ValuedEventCreator() {} 
00100   protected:
00101     virtual Event * createRealEvent (const EventIdentifier & event, const Date & date, const Name & sender, const Name & receiver )
00102     {
00103       return new ValuedEvent<UserType> (event, date, sender, receiver) ;
00104     }      
00105   } ;
00106 public:
00108   static ValuedEventCreator myEventCreator ;
00109 };
00110 
00111 
00112 
00113 //------------------------ implementation -------------------------
00114 template <typename UserType>
00115 typename ValuedEvent<UserType>::ValuedEventCreator ValuedEvent<UserType>::myEventCreator ;
00116 
00117 
00118 template <typename UserType>
00119 ValuedEvent<UserType>::ValuedEvent( const ValuedEvent<UserType> & originalEvent) :
00120                                           Event ( originalEvent ),
00121                                           value ( originalEvent.value )
00122 {
00123    // this static ensures that the static members are present in the genretaed code
00124    // enabling correct linking. In this case, it enbles valued event registration with the OMKEventCreator
00125   static bool instanciated = myEventCreator.touch() ;
00126   myEventCreator.touch(instanciated) ;
00127 }
00128 
00129 
00130 
00131 template <typename UserType>
00132 ValuedEvent<UserType> & ValuedEvent<UserType>::operator = (const ValuedEvent<UserType> & originalEvent) 
00133 {
00134   Event::operator = ( originalEvent ) ;
00135   value = originalEvent.value ;
00136   return *this ;
00137 }
00138 
00139 
00140 
00141 template <typename UserType>
00142 ValuedEvent<UserType> * ValuedEvent<UserType>::clone () const 
00143 {
00144    return new ValuedEvent<UserType>( *this ) ;
00145 }
00146 
00147 
00148 
00149 template <typename UserType>
00150 void ValuedEvent<UserType>::insertInStream(std::ostream & out) const 
00151 {
00152   Event::insertInStream ( out ) ;
00153    out<<value<<" ";
00154 }
00155 
00156 template <typename UserType>
00157 void ValuedEvent<UserType>::extract ( std::istream & in ) 
00158 {
00159   Event::extract ( in ) ;
00160    in >> value ;
00161 }
00162 
00163 template <typename UserType>
00164 ValuedEvent<UserType>::ValuedEvent( const EventIdentifier & event, 
00165                                           const Date & date, 
00166                                           const Name & sender, 
00167                                           const Name & receiver, 
00168                                           const UserType & userValue ) :
00169    Event(event, date, sender, receiver) ,
00170    value (userValue )
00171 {
00172    // this static ensures that the static members are present in the generated code
00173    // enabling correct linking. In this case, it enbles valued event registration with the OMKEventCreator
00174    // as from g++3, it is no longer necessary in constructors
00175   static bool instanciated = myEventCreator.touch() ;
00176   myEventCreator.touch(instanciated) ;
00177 }
00178 
00179 
00180 
00181 template <typename UserType>
00182 ValuedEvent<UserType>::ValuedEvent( const EventIdentifier & event, 
00183                                           const Date & date, 
00184                                           const Name & sender, 
00185                                           const Name & receiver ) :
00186 Event(event, date, sender, receiver) 
00187 {
00188    // this static ensures that the static members are present in the generated code
00189    // enabling correct linking. In this case, it enbles valued event registration with the OMKEventCreator
00190    // as from g++3, it is no longer necessary in constructors
00191   static bool instanciated = myEventCreator.touch() ;
00192   myEventCreator.touch(instanciated) ;
00193 }
00194 
00195 
00196 template <typename UserType>
00197 ValuedEvent<UserType>::~ValuedEvent() 
00198 {
00199    // this static ensures that the static members are present in the generated code
00200    // enabling correct linking. In this case, it enbles valued event registration with the OMKEventCreator
00201    static bool instanciated = myEventCreator.touch() ;  
00202   myEventCreator.touch(instanciated) ;
00203 }
00204 
00205 template <typename UserType>
00206 void ValuedEvent<UserType>::unpack (IncomingSynchronisationMessage & in)
00207 {
00208    //un pack base information
00209   Event::unpack ( in ) ;
00210    in >> value ;
00211 }
00212 
00213 template< typename UserType >
00214 void ValuedEvent< UserType >::pack( OutgoingSynchronisationMessage & out ) const
00215 {
00216    static Name valueType( typeid( ValuedEvent< UserType > ).name() ) ;
00217    out << valueType
00218        << eventId 
00219        << date 
00220        << sender 
00221        << receiver
00222        << value ;
00223 }
00224 
00225 } // namespace OMK
00226 
00227 #endif

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007