OMKAbstractInput.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 AbstractInputHEADER
00019 #define AbstractInputHEADER
00020 
00021 #include "OMKSimulatedObject.h"
00022 #include "OMKController.h"
00023 #include "OMKInputNT.h"
00024 
00025 namespace OMK
00026 {
00037 template < class Type >
00038 class AbstractInput : public InputNT
00039 {
00040 public:
00041    
00048   AbstractInput( const Name & inputName, SimulatedObject & owner, bool makeConnectable, const int precisionLevel = OMK::Type::PolatorNT::defaultPrecisionLevel ) ;
00049 
00050 
00053    virtual ~AbstractInput() ;
00054    
00055 
00061    virtual bool connect( const Name & objectName, const Name & outputName ) = 0 ;
00062 
00063 
00069    virtual bool connect( SimulatedObject & object, const Name & outputName ) = 0 ;
00070 
00071 
00077    virtual bool connect( SimulatedObject * pointerToObject, const Name & outputName ) = 0 ;
00078 
00079 
00086    virtual bool connect( const Name & objectName, const Name & outputName, const Type & initialValue ) = 0 ;
00087 
00088 
00095    virtual bool connect( SimulatedObject & object, const Name & outputName, const Type & initialValue ) = 0 ;
00096 
00097 
00104    virtual bool connect( SimulatedObject * pointerToObject, const Name & outputName, const Type & initialValue ) = 0 ;
00105 
00106 
00112    virtual bool connectToControlParameter( const Name & objectName, const Name & controlParameterName ) = 0 ;
00113 
00114 
00120    virtual bool connectToControlParameter( SimulatedObject & object, const Name & controlParameterName ) = 0 ;
00121 
00122 
00128    virtual bool connectToControlParameter( SimulatedObject * pointerToObject, const Name & controlParameterName ) = 0 ;
00129 
00130 
00137    virtual bool connectToControlParameter( const Name & objectName, const Name & controlParameterName, const Type & initialValue ) = 0 ;
00138 
00139 
00146    virtual bool connectToControlParameter( SimulatedObject & object, const Name & controlParameterName, const Type & initialValue ) = 0 ;
00147 
00148 
00155    virtual bool connectToControlParameter( SimulatedObject * pointerToObject, const Name & controlParameterName, const Type & initialValue ) = 0 ;
00156 
00157 
00161    virtual bool isConnectable() const ;
00162 
00165    bool isConnected() const { return getConnectedOutput() != 0 ; }
00166 
00167    
00170    virtual void setConnectable( bool nextConnectableState ) ;
00171 
00172 
00174    virtual const OutputNT * getConnectedOutput() const = 0 ;
00175 
00176 
00178    const EventIdentifier & getConnectionEventId() const ;
00179 
00180 
00182    const EventIdentifier & getConnectionToControlParameterEventId() const ;
00183 
00184 
00189   virtual const Type & get( int deltaT = 0 ) = 0 ; 
00190 
00191 
00195   virtual int getDistanceToExactValue() const = 0;
00196 
00197 
00201    virtual const Type & getLastExactValue() const = 0 ;
00202    
00203 
00207    virtual const Date & getDateOfLastExactValue() const = 0 ;
00208    
00209 
00212    virtual void printDebuggingInformation( std::ostream & err ) const = 0;
00213 
00214 
00217    virtual int getPrecisionLevel() const ;
00218 
00219 
00224    virtual int setPrecisionLevel( const int newValue ) ;
00225 
00226 
00230    virtual void notifyAliasing( InputAlias<Type> * aliasingInputAlias ) ;
00231 
00232 
00236    virtual void notifyUnaliasing( InputAlias<Type> *aliasingInputAlias ) ;
00237 
00238 
00239 protected:
00241    std::list<InputAlias<Type> *> _listOfAliases ;
00242 
00244    int _precisionLevel ;
00245 
00247    bool _connectable ;
00248 
00250    const EventIdentifier _connectionEventId ;
00251 
00253    const EventIdentifier _connectionToControlParameterEventId ;
00254 
00255 } ; // AbstractInput
00256 
00257 } // namespace OMK
00258 
00259 
00260 //-----------------------------------------------------------------------------
00261 //-----------------------------------------------------------------------------
00262 
00263 
00264 #include "OMKCurrentActiveObject.h"
00265 #include "OMKInputAlias.h"
00266 
00267 namespace OMK
00268 {
00269 
00270 //-----------------------------------------------------------------------------
00271 
00272 template < typename Type >
00273 inline AbstractInput< Type >::AbstractInput( const Name & inputName,
00274                                              SimulatedObject & owner,
00275                                              bool makeConnectable,
00276                                              const int precisionLevel )
00277   : InputNT( owner, inputName ),
00278     _precisionLevel( precisionLevel ),
00279     _connectable( makeConnectable ),
00280     _connectionEventId( ( "newConnection " + inputName.getString() ).c_str() ),
00281     _connectionToControlParameterEventId( ( "newConnectionToControlParameter "
00282                                             + inputName.getString() ).c_str() )
00283 {
00284 #ifdef _DEBUGTYPEUTIL
00285   std::cout << "AbstractInput<Type>::AbstractInput --> constructor " 
00286             << std::endl ;
00287 #endif
00288   registerMe() ;
00289 }
00290 
00291 //-----------------------------------------------------------------------------
00292 
00293 template< typename Type >
00294 inline AbstractInput< Type >::~AbstractInput()
00295 {
00296   typename std::list< InputAlias< Type > * >::iterator i ;
00297   for( i =_listOfAliases.begin() ; i != _listOfAliases.end() ; ++i )
00298   {
00299     (*i)->inputAliasedDeleted() ;
00300   }
00301 }
00302 
00303 //-----------------------------------------------------------------------------
00304 
00305 template< typename Type >
00306 inline int AbstractInput< Type >::getPrecisionLevel() const
00307 {
00308   return _precisionLevel ;
00309 }
00310 
00311 //-----------------------------------------------------------------------------
00312 
00313 template< typename Type >
00314 inline int AbstractInput< Type >::setPrecisionLevel( const int newValue )
00315 {
00316   int oldValue = _precisionLevel ;
00317   _precisionLevel = newValue ;
00318   return oldValue ;
00319 }
00320 
00321 //-----------------------------------------------------------------------------
00322 
00323 template< typename Type >
00324 inline void AbstractInput< Type >::notifyAliasing(
00325   InputAlias< Type > * aliasingInputAlias )
00326 {
00327   if( aliasingInputAlias != 0 )
00328   {
00329     _listOfAliases.push_back( aliasingInputAlias ) ;
00330   }
00331 }
00332 
00333 //-----------------------------------------------------------------------------
00334 
00335 template< typename Type >
00336 inline void AbstractInput< Type >::notifyUnaliasing(
00337   InputAlias< Type > * aliasingInputAlias )
00338 {
00339   if( aliasingInputAlias != 0 )
00340   {
00341     _listOfAliases.push_back( aliasingInputAlias ) ;
00342   }
00343 }
00344 
00345 //-----------------------------------------------------------------------------
00346 
00347 template< typename Type >
00348 inline bool AbstractInput< Type >::isConnectable() const
00349 {
00350   return _connectable ;
00351 }
00352 
00353 //-----------------------------------------------------------------------------
00354 
00355 template< typename Type >
00356 void AbstractInput< Type >::setConnectable( bool newConnectableState )
00357 {
00358   if( CurrentActiveObject::getCurrentActiveObject() == & _owner ||
00359       CurrentActiveObject::getCurrentActiveObject() == & _owner.getController() ||
00360       CurrentActiveObject::getCurrentActiveObject() == 0 )
00361   {
00362     _connectable = newConnectableState ;
00363   }
00364   else 
00365   {
00366     OMERROR( "Warning: " << _owner.getName() << "::" << getName()
00367              << "only the owner can change the connectable state of an input" ) ;
00368   }
00369 }
00370 
00371 //-----------------------------------------------------------------------------
00372 
00373 template< typename Type >
00374 inline const EventIdentifier & AbstractInput< Type >::getConnectionEventId() const
00375 {
00376   return _connectionEventId ;
00377 }
00378 
00379 //-----------------------------------------------------------------------------
00380 
00381 template< typename Type >
00382 inline const EventIdentifier & AbstractInput< Type >::getConnectionToControlParameterEventId() const
00383 {
00384   return _connectionToControlParameterEventId ;
00385 }
00386 
00387 //-----------------------------------------------------------------------------
00388 
00389 template< typename Type >
00390 inline bool AbstractInput< Type >::connect( SimulatedObject * pointerToObject,
00391                                             const Name & outputName )
00392 {
00393   if( pointerToObject != 0 )
00394   {
00395     return connect( *pointerToObject, outputName ) ;
00396   }
00397   else
00398   {
00399     OMERROR( "AbstractInput<Type>::connect : got null pointer" ) ;
00400     printDebuggingInformation( std::cerr ) ;
00401     return false ;
00402   }
00403 }
00404 
00405 //-----------------------------------------------------------------------------
00406 
00407 template< typename Type >
00408 inline bool AbstractInput< Type >::connect( SimulatedObject * pointerToObject,
00409                                             const Name & outputName,
00410                                             const Type & initialValue )
00411 {
00412   if( pointerToObject != 0 )
00413   {
00414     return connect( *pointerToObject, outputName, initialValue ) ;
00415   }
00416   else
00417   {
00418     OMERROR( "AbstractInput< Type >::connect : got null pointer" ) ;
00419     printDebuggingInformation( std::cerr ) ;
00420     return false ;
00421   }
00422 }
00423 
00424 //-----------------------------------------------------------------------------
00425 
00426 template< typename Type >
00427 inline bool AbstractInput< Type >::connectToControlParameter(
00428   SimulatedObject * pointerToObject,
00429   const Name & outputName )
00430 {
00431   if( pointerToObject != 0 )
00432   {
00433     return connectToControlParameter( *pointerToObject, outputName ) ;
00434   }
00435   else
00436   {
00437     OMERROR( "AbstractInput< Type >::connect : got null pointer" ) ;
00438     printDebuggingInformation( std::cerr ) ;
00439     return false ;
00440   }
00441 }
00442 
00443 //-----------------------------------------------------------------------------
00444 
00445 template< typename Type >
00446 inline bool AbstractInput< Type >::connectToControlParameter(
00447   SimulatedObject * pointerToObject,
00448   const Name & outputName,
00449   const Type & initialValue )
00450 {
00451   if( pointerToObject != 0 )
00452   {
00453     return connectToControlParameter( *pointerToObject,
00454                                       outputName,
00455                                       initialValue ) ;
00456   }
00457   else
00458   {
00459     OMERROR( "AbstractInput< Type >::connect : got null pointer" ) ;
00460     printDebuggingInformation( std::cerr ) ;
00461     return false ;
00462   }
00463 }
00464 
00465 //-----------------------------------------------------------------------------
00466 
00467 } // namespace OMK
00468 
00469 #endif

logo OpenMask

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

Generated with doxygen by Dimitri van Heesch ,   1997-2007