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 PsValuedEventHEADER 00019 #define PsValuedEventHEADER 00020 00021 #include "PsEvent.h" 00022 #include "PsnEventAssociationList.h" 00023 #include "PsEventCreator.h" 00024 00027 template <typename UserType > 00028 class PsValuedEvent : public PsEvent { 00029 public: 00030 00033 UserType value ; 00034 00037 PsValuedEvent(const PsValuedEvent & originalEvent); 00038 00041 PsValuedEvent & operator = (const PsValuedEvent & originalEvent); 00042 00043 00045 virtual PsValuedEvent * clone () const ; 00046 00047 00051 virtual void insertInStream (ostream & = cout) const; 00052 00053 00057 virtual void extract (istream & = cin); 00058 00059 00060 00064 virtual void unpack (PsIncomingSynchronisationMessage &) ; 00065 00066 00067 00069 virtual void pack (PsOutgoingSynchronisationMessage &) const ; 00070 00071 00072 00073 00081 PsValuedEvent(const PsEventIdentifier & event, const PsDate & date, const PsName & sender, const PsName & receiver, const UserType & userValue ); 00082 00089 PsValuedEvent(const PsEventIdentifier & event, const PsDate & date, const PsName & sender, const PsName & receiver) ; 00090 00091 00094 virtual ~PsValuedEvent(); 00095 00096 protected: 00097 class ValuedEventCreator : public PsEventCreator 00098 { 00099 public: 00100 virtual ~ValuedEventCreator() 00101 { 00102 } 00103 00104 00105 ValuedEventCreator () : PsEventCreator ( typeid( PsValuedEvent<UserType> ).name() ) 00106 { 00107 } 00108 protected: 00109 virtual PsEvent * createRealEvent (const PsEventIdentifier & event, const PsDate & date, const PsName & sender, const PsName & receiver ) 00110 { 00111 return new PsValuedEvent<UserType> (event, date, sender, receiver) ; 00112 } 00113 }; 00114 public: 00116 static ValuedEventCreator myEventCreator ; 00117 00118 }; 00119 00120 00121 00122 //------------------------ implementation ------------------------- 00123 template <typename UserType> 00124 typename PsValuedEvent<UserType>::ValuedEventCreator PsValuedEvent<UserType>::myEventCreator ; 00125 00126 00127 00128 template <typename UserType> 00129 PsValuedEvent<UserType>::PsValuedEvent(const PsValuedEvent<UserType> & originalEvent) : 00130 PsEvent ( originalEvent ), 00131 value ( originalEvent.value ) 00132 { 00133 // this static ensures that the static members are present in the genretaed code 00134 // enabling correct linking. In this case, it enbles valued event registration with the PsEventCreator 00135 static bool instanciated = myEventCreator.touch() ; 00136 } 00137 00138 00139 00140 template <typename UserType> 00141 PsValuedEvent<UserType> & PsValuedEvent<UserType>::operator = (const PsValuedEvent<UserType> & originalEvent) 00142 { 00143 PsEvent::operator = ( originalEvent ) ; 00144 value = originalEvent.value ; 00145 } 00146 00147 00148 00149 template <typename UserType> 00150 PsValuedEvent<UserType> * PsValuedEvent<UserType>::clone () const { 00151 return new PsValuedEvent<UserType>( *this ) ; 00152 } 00153 00154 00155 00156 template <typename UserType> 00157 void PsValuedEvent<UserType>::insertInStream(ostream & out) const { 00158 PsEvent::insertInStream ( out ) ; 00159 out<<value<<" "; 00160 } 00161 00162 template <typename UserType> 00163 void PsValuedEvent<UserType>::extract ( istream & in ) { 00164 PsEvent::extract ( in ) ; 00165 in >> value ; 00166 } 00167 00168 template <typename UserType> 00169 PsValuedEvent<UserType>::PsValuedEvent(const PsEventIdentifier & event, 00170 const PsDate & date, 00171 const PsName & sender, 00172 const PsName & receiver, 00173 const UserType & userValue ) : 00174 PsEvent(event, date, sender, receiver) , 00175 value (userValue ) 00176 { 00177 // this static ensures that the static members are present in the generated code 00178 // enabling correct linking. In this case, it enbles valued event registration with the PsEventCreator 00179 // as from g++3, it is no longer necessary in constructors 00180 static bool instanciated = myEventCreator.touch() ; 00181 } 00182 00183 00184 00185 template <typename UserType> 00186 PsValuedEvent<UserType>::PsValuedEvent(const PsEventIdentifier & event, 00187 const PsDate & date, 00188 const PsName & sender, 00189 const PsName & receiver ) : 00190 PsEvent(event, date, sender, receiver) 00191 { 00192 // this static ensures that the static members are present in the generated code 00193 // enabling correct linking. In this case, it enbles valued event registration with the PsEventCreator 00194 // as from g++3, it is no longer necessary in constructors 00195 static bool instanciated = myEventCreator.touch() ; 00196 } 00197 00198 00199 template <typename UserType> 00200 PsValuedEvent<UserType>::~PsValuedEvent() 00201 { 00202 // this static ensures that the static members are present in the generated code 00203 // enabling correct linking. In this case, it enbles valued event registration with the PsEventCreator 00204 static bool instanciated = myEventCreator.touch() ; 00205 } 00206 00207 00208 00209 template <typename UserType> 00210 void PsValuedEvent<UserType>::unpack (PsIncomingSynchronisationMessage & in) 00211 { 00212 00213 //un pack base information 00214 PsEvent::unpack ( in ) ; 00215 in >> value ; 00216 } 00217 00218 template <typename UserType> 00219 void PsValuedEvent<UserType>::pack(PsOutgoingSynchronisationMessage & out) const 00220 { 00221 static PsName valueType ( typeid (PsValuedEvent<UserType>) .name() ) ; 00222 out << valueType 00223 << eventId 00224 << date 00225 << sender 00226 << receiver 00227 << value ; 00228 } 00229 00230 00231 #endif
| Documentation generated on Mon Nov 25 15:25:02 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |