OMKGenericControlParameter.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 GenericControlParameterHEADER
00019 #define GenericControlParameterHEADER
00020 
00021 #include "OMKKernelAttribute.h"
00022 
00023 namespace OMK
00024 {
00025   template< typename T > class ChangedControlParameterEventListener ;
00026 
00037 template< typename T, class AncestorClass >
00038 class GenericControlParameter : virtual public KernelAttribute, 
00039                                 public AncestorClass, 
00040                                 public ControlParameter< T >
00041 {
00042  public:
00043   using ControlParameter< T >::getAssociatedEventId ;
00044   
00045 
00046 public:
00047 
00054    GenericControlParameter( const Name & attributeName, 
00055                             SimulatedObject & owner,
00056                             const int historyLength,
00057                             OMK::Type::PolatorNT * polator ) ;
00058    
00060    virtual ~GenericControlParameter() ;
00061    
00063    virtual const T & get( int & distanceToExactValue,
00064                           const int precisionLevel,
00065                           const Date & deltaT,
00066                           T & calculatedResult ) const ;
00067 
00068 
00070    virtual const T & get() const;
00071    
00073    virtual const T & getLastExactValue() const;
00074 
00075 
00077    virtual const Date & getDateOfLastExactValue() const;
00078 
00079 
00081    virtual void set( const T & val ) ;
00082 
00084    virtual void extract( std::istream & = std::cin ) ;
00085    
00087    virtual void unpack( IncomingSynchronisationMessage & ) ;
00088    
00090    virtual void pack( OutgoingSynchronisationMessage & ) const ;
00091 
00093    virtual void insertInStream( std::ostream & = std::cout ) const;
00094 
00096   virtual void printDebuggingInformation( std::ostream & err ) const ;
00097 
00098 
00104    virtual bool connect( const Name & objectName, const Name & inputName ) ;
00105 
00106 
00112    virtual bool connect( SimulatedObject & object, const Name & inputName ) ;
00113 
00114 
00120    virtual bool connect( SimulatedObject * pointerToObject, const Name & inputName ) ;
00121 
00122 protected:
00124    virtual void realSet(  const T & val ) ;
00125    
00127    ChangedControlParameterEventListener<T> * _associatedEventListener ;
00128  } ; // ControlParameter
00129 
00130 } // namespace OMK
00131 
00132 
00133 //-----------------------------------------------------------------------------
00134 //-----------------------------------------------------------------------------
00135 
00136 
00137 #include "OMKChangedControlParameterEventListener.h"
00138 #include "OMKCurrentActiveObject.h"
00139 
00140 namespace OMK
00141 {
00142 
00143 //-----------------------------------------------------------------------------
00144 
00145 template< typename T, class AncestorClass >
00146 inline GenericControlParameter< T, AncestorClass >::GenericControlParameter(
00147   const Name & controlParameterName,
00148   SimulatedObject & owner,
00149   const int historyLength,
00150   OMK::Type::PolatorNT * polator )
00151   :  KernelAttribute( owner, controlParameterName ),
00152      AncestorClass( controlParameterName,
00153                     owner,
00154                     historyLength,
00155                     polator ),
00156      ControlParameter< T >( owner, 
00157                             controlParameterName,
00158                             ( "ChangedControlParameter::" +
00159                               controlParameterName.getString() ) )
00160 {
00161   _associatedEventListener =
00162     new ChangedControlParameterEventListener< T >( owner, *this ) ;
00163 }
00164 
00165 //-----------------------------------------------------------------------------
00166 
00167 template< typename T, class AncestorClass >
00168 inline GenericControlParameter< T, AncestorClass >::~GenericControlParameter()
00169 {
00170   delete _associatedEventListener ;
00171 }
00172 
00173 //-----------------------------------------------------------------------------
00174 
00175 template< typename T, class AncestorClass >
00176 inline void GenericControlParameter< T, AncestorClass >::set( const T & val )
00177 {
00178    SimulatedObject * caller = CurrentActiveObject::getCurrentActiveObject() ;
00179    if( caller != 0 && caller != &_owner )
00180    {
00181      caller->sendValuedEvent( _owner, getAssociatedEventId(), val ) ;
00182    }
00183    else
00184    {
00185      /* Probably in initialisation phase : suppose the owner is calling set
00186       * with the initial value.
00187       * WARNING: this is a security hole because the currentActiveObject can
00188       * easily be changed.
00189       */
00190      realSet( val ) ;
00191    }
00192 }
00193 
00194 //-----------------------------------------------------------------------------
00195 
00196 template< typename T, class AncestorClass >
00197 inline void GenericControlParameter< T, AncestorClass >::realSet(
00198   const T & val )
00199 {
00200   if( _owner.getObjectHandle() != 0 )
00201   {//during initialisation phase, objectHandle of the owner can be null
00202     _owner.getObjectHandle()->notifyChangeInControlParameter( this ) ;
00203   }
00204   AncestorClass::set( val ) ;
00205 }
00206 
00207 //-----------------------------------------------------------------------------
00208 
00209 template< typename T, class AncestorClass >
00210 inline void GenericControlParameter< T, AncestorClass >::insertInStream(
00211   std::ostream & out ) const
00212 {
00213   /* Thread safety assessement : as thread safe as localInsert
00214    */
00215   AncestorClass::insertInStream( out ) ; 
00216 }
00217 
00218 //-----------------------------------------------------------------------------
00219 
00220 template< typename T, class AncestorClass >
00221 inline void GenericControlParameter< T, AncestorClass >::extract(
00222   std::istream & in )
00223 {
00224   /* Thread safety assessement : as thread safe as localInsert
00225    */
00226   AncestorClass::extract( in ) ;
00227 }
00228 
00229 //-----------------------------------------------------------------------------
00230 
00231 template< typename T, class AncestorClass >
00232 inline void GenericControlParameter< T, AncestorClass >::pack(
00233   OutgoingSynchronisationMessage & out ) const
00234 {
00235   /* Thread safety assessement : as thread safe as localInsert
00236    */
00237   AncestorClass::pack( out ) ;
00238 }
00239 
00240 //-----------------------------------------------------------------------------
00241 
00242 template< typename T, class AncestorClass >
00243 inline void GenericControlParameter< T, AncestorClass >::unpack(
00244   IncomingSynchronisationMessage & in )
00245 {
00246   /* Thread safety assessement : as thread safe as localInsert
00247    */
00248   AncestorClass::unpack( in ) ;
00249 }
00250 
00251 //-----------------------------------------------------------------------------
00252 
00253 template< typename T, class AncestorClass >
00254 inline void GenericControlParameter< T, AncestorClass >::printDebuggingInformation(
00255   std::ostream & err ) const
00256 {
00257   AncestorClass::printDebuggingInformation( err ) ;
00258   err << " Output is a control parameter " << std::endl ;
00259 }
00260 
00261 //-----------------------------------------------------------------------------
00262 
00263 template< typename T, class AncestorClass >
00264 const T & GenericControlParameter< T, AncestorClass >::get(
00265   int & distanceToExactValue,
00266   const int precisionLevel,
00267   const Date & deltaT,
00268   T & calculatedResult ) const
00269 {
00270   return AncestorClass::get( distanceToExactValue, precisionLevel, deltaT,
00271                              calculatedResult ) ;
00272 }
00273 
00274 //-----------------------------------------------------------------------------
00275 
00276 template< typename T, class AncestorClass >
00277 inline const T & GenericControlParameter< T, AncestorClass >::get() const
00278 {
00279   return AncestorClass::getLastExactValue() ;
00280 }
00281 
00282 //-----------------------------------------------------------------------------
00283 
00284 template< typename T, class AncestorClass >
00285 inline const Date & GenericControlParameter< T, AncestorClass >::getDateOfLastExactValue() const
00286 {
00287   return AncestorClass::getDateOfLastExactValue() ;
00288 }
00289 
00290 //-----------------------------------------------------------------------------
00291 
00292 template< typename T, class AncestorClass >
00293 inline const T & GenericControlParameter< T, AncestorClass >::getLastExactValue() const 
00294 {
00295   return AncestorClass::getLastExactValue() ;
00296 }
00297 
00298 //-----------------------------------------------------------------------------
00299 
00300 template< typename T, class AncestorClass >
00301 bool GenericControlParameter< T, AncestorClass >::connect(
00302   const Name & objectName, const Name & inputName )
00303 {
00304   return AncestorClass::connect( objectName, inputName ) ;
00305 }
00306 
00307 //-----------------------------------------------------------------------------
00308 
00309 template< typename T, class AncestorClass >
00310 bool GenericControlParameter< T, AncestorClass >::connect(
00311   SimulatedObject & object, const Name & inputName )
00312 {
00313   return AncestorClass::connect( object, inputName ) ;
00314 }
00315 
00316 //-----------------------------------------------------------------------------
00317 
00318 template< typename T, class AncestorClass >
00319 bool GenericControlParameter< T, AncestorClass >::connect(
00320   SimulatedObject * pointerToObject, const Name & inputName )
00321 {
00322   return AncestorClass::connect( pointerToObject, inputName ) ;
00323 }
00324 
00325 //-----------------------------------------------------------------------------
00326 
00327 } // namespace OMK
00328 
00329 #endif

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007