Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsGenericControlParameter.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 PsGenericControlParameterHEADER
00019 #define PsGenericControlParameterHEADER
00020 
00021 #include "PsAttribute.h"
00022 
00023 template <typename Type> class PsChangedControlParameterEventListener ;
00024 
00035 template <typename Type, class AncestorClass>
00036 class PsGenericControlParameter : virtual public PsAttribute, 
00037                                   public AncestorClass, 
00038                                   public PsControlParameter<Type>
00039 {
00040 public:
00041 
00048    PsGenericControlParameter (const PsName & attributeName, 
00049                               PsSimulatedObject & owner,
00050                               const int historyLength,
00051                               PsPolatorNT * polator) ;
00052    
00054    virtual ~PsGenericControlParameter (void) ;
00055    
00057    virtual const Type & get (int & distanceToExactValue,
00058                              const int precisionLevel,
00059                              const PsDate & deltaT,
00060                              Type & calculatedResult ) const ;
00061 
00062 
00064    virtual const Type & get (void) const;
00065    
00067    virtual const Type & getLastExactValue (void) const;
00068 
00069 
00071    virtual const PsDate & getDateOfLastExactValue (void) const;
00072 
00073 
00075    virtual void set (const Type & val) ; 
00076 
00078    virtual void extract (istream & = cin);
00079    
00081    virtual void unpack (PsIncomingSynchronisationMessage &) ;
00082    
00084    virtual void pack (PsOutgoingSynchronisationMessage &) const ;
00085 
00087    virtual void insertInStream (ostream & = cout) const;
00088 
00090   virtual void printDebuggingInformation(ostream & err) const ;
00091 
00092 
00098    virtual bool connect (const PsName & objectName, const PsName & inputName ) ;
00099 
00100 
00106    virtual bool connect (PsSimulatedObject & object, const PsName & inputName ) ;
00107 
00108 
00114    virtual bool connect (PsSimulatedObject * pointerToObject, const PsName & inputName ) ;
00115 
00116 protected:
00118    virtual void realSet ( const Type & val ) ;
00119    
00121    PsChangedControlParameterEventListener<Type> * _associatedEventListener ;
00122  } ; // PsControlParameter
00123 
00124 
00125 
00126 #include "PsChangedControlParameterEventListener.h"
00127 #include "PsnCurrentActiveObject.h"
00128 template <typename Type, class AncestorClass>
00129 inline PsGenericControlParameter<Type,AncestorClass>::PsGenericControlParameter(const PsName & controlParameterName,
00130                                                                   PsSimulatedObject & owner,
00131                                                                   const int historyLength,
00132                                                                   PsPolatorNT * polator) : 
00133    PsAttribute (owner, controlParameterName),  
00134    AncestorClass (controlParameterName,
00135                   owner,
00136                   historyLength,
00137                   polator),
00138    PsControlParameter<Type> (owner, 
00139                              controlParameterName,
00140                              PsString("ChangedControlParameter::")+controlParameterName.getCString() )
00141 {
00142    _associatedEventListener = new PsChangedControlParameterEventListener<Type>(owner, *this ) ;
00143    owner.addEventListener( *_associatedEventListener ) ;
00144 }
00145 
00146 //-----------------------------------------------------------------
00147 
00148 template <typename Type, class AncestorClass>
00149 inline PsGenericControlParameter<Type,AncestorClass>::~PsGenericControlParameter (void)
00150 {
00151    delete _associatedEventListener ;
00152 }
00153 
00154 
00155 
00156 template <typename Type, class AncestorClass>
00157 inline void PsGenericControlParameter<Type,AncestorClass>::set (const Type & val)
00158 {
00159    PsSimulatedObject * caller = PsnCurrentActiveObject::getCurrentActiveObject() ;
00160    if ( (caller != NULL) &&
00161         (caller != &_owner) )
00162       {
00163          caller->sendValuedEvent(_owner,getAssociatedEventId(),val) ;
00164       } 
00165    else //probably in initialisation phase : suppose the owner is calling set with the initial value
00166       // warning: this is a security hole, because the currentActiveObject can easily be changed
00167       {
00168          realSet (val) ;
00169       }
00170 }
00171 
00172 
00173 
00174 template <typename Type, class AncestorClass>
00175 inline void PsGenericControlParameter<Type,AncestorClass>::realSet (const Type & val)
00176 {
00177    if ( _owner.getObjectHandle() != NULL )
00178       {//during initialisation phase, objectHandle of the owner can be null
00179          _owner.getObjectHandle()->notifyChangeInControlParameter (this) ;
00180       }
00181    AncestorClass::set(val) ;
00182 } 
00183 
00184 
00185 
00186 template <typename Type, class AncestorClass>
00187 inline void PsGenericControlParameter<Type,AncestorClass>::insertInStream (ostream & out) const
00188 {
00189    /*thread safety assessement :
00190      As thread safe as localInsert 
00191    */
00192    AncestorClass::insertInStream ( out ) ; 
00193 }
00194 
00195 template <typename Type, class AncestorClass>
00196 inline void PsGenericControlParameter<Type,AncestorClass>::extract (istream & in) 
00197 {
00198    /*thread safety assessement :
00199      As thread safe as localInsert 
00200    */
00201    AncestorClass::extract ( in ) ; 
00202 }
00203 
00204 
00205 template <typename Type, class AncestorClass>
00206 inline void PsGenericControlParameter<Type,AncestorClass>::pack (PsOutgoingSynchronisationMessage & out) const
00207 {
00208    /*thread safety assessement :
00209      As thread safe as localInsert 
00210    */
00211    AncestorClass::pack ( out ) ; 
00212 }
00213 
00214 template <typename Type, class AncestorClass>
00215 inline void PsGenericControlParameter<Type,AncestorClass>::unpack (PsIncomingSynchronisationMessage & in) 
00216 {
00217    /*thread safety assessement :
00218      As thread safe as localInsert 
00219    */
00220    AncestorClass::unpack ( in ) ; 
00221 }
00222 
00223 
00224 template <typename Type, class AncestorClass>
00225 inline void PsGenericControlParameter<Type,AncestorClass>::printDebuggingInformation(ostream & err) const
00226 {
00227   AncestorClass::printDebuggingInformation( err ) ;
00228   err <<" Output is a control parameter "<<endl;
00229 }
00230 
00231 template <typename Type, class AncestorClass>
00232 const Type & PsGenericControlParameter<Type,AncestorClass>::get (int & distanceToExactValue,
00233                                                                  const int precisionLevel,
00234                                                                  const PsDate & deltaT,
00235                                                                  Type & calculatedResult ) const 
00236 {
00237    return AncestorClass::get(distanceToExactValue,precisionLevel,deltaT,calculatedResult );
00238 }
00239 
00240 template <typename Type, class AncestorClass>
00241 inline const Type & PsGenericControlParameter<Type,AncestorClass>::get (void) const 
00242 {
00243   return AncestorClass::getLastExactValue ( ) ;
00244 }
00245 
00246 
00247 template <typename Type, class AncestorClass>
00248 inline const PsDate & PsGenericControlParameter<Type,AncestorClass>::getDateOfLastExactValue (void) const 
00249 {
00250   return AncestorClass::getDateOfLastExactValue ( ) ;
00251 }
00252 
00253 template <typename Type, class AncestorClass>
00254 inline const Type & PsGenericControlParameter<Type,AncestorClass>::getLastExactValue (void) const 
00255 {
00256   return AncestorClass::getLastExactValue ( ) ;
00257 }
00258 
00259 template <typename Type, class AncestorClass>
00260 bool PsGenericControlParameter<Type,AncestorClass>::connect (const PsName & objectName, const PsName & inputName ) 
00261 {
00262    return AncestorClass::connect (objectName, inputName) ;
00263 }
00264 
00265 
00266 template <typename Type, class AncestorClass>
00267 bool PsGenericControlParameter<Type,AncestorClass>::connect (PsSimulatedObject & object, const PsName & inputName ) 
00268 {
00269    return AncestorClass::connect (object, inputName) ;
00270 }
00271 
00272 
00273 template <typename Type, class AncestorClass>
00274 bool PsGenericControlParameter<Type,AncestorClass>::connect (PsSimulatedObject * pointerToObject, const PsName & inputName )
00275 {
00276    return AncestorClass::connect (pointerToObject, inputName) ;
00277 }
00278 
00279 #endif

logo OpenMask

Documentation generated on Mon Nov 25 15:24:59 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001