OMK::ExtensibleSimulatedObject Class Reference
[Extension featureAttribute feature]

Ancestor of every extensible objects. More...

#include <OMKExtensibleSimulatedObject.h>

Inheritance diagram for OMK::ExtensibleSimulatedObject:

Inheritance graph
[legend]
Collaboration diagram for OMK::ExtensibleSimulatedObject:

Collaboration graph
[legend]
List of all members.

Extensions

See Extension feature and ExtensionManager for details

class ExtensionOfExtensionCreatorEvent
typedef ValuedEventListenerCallBack<
ExtensibleSimulatedObject,
CreateAndAddExtensionType > 
CreateAndAddExtensionEventListener
EventListener_eventCreateAndAddExtensionListener
 The event listener which receives the event to create and add extension.
void activateCreateExtensionByEvent (bool activate=true)
 Activates the event processing for dynamic creation of extension.
bool processCreateAndAddExtension (CreateAndAddExtensionEvent *event)
 Called as a event processing call back to create and add an extension to the object.

Attributes

See Extension feature for details

typedef std::map< Name, IAttribute * > AttributeStore
 The storage type for attributes.
AttributeStore _attributes
 List of attributes.
IAttributegetAttribute (const Name &id)
 Get an attribute.
template<typename Type>
IAttributeBaseT< Type > * getBaseAttribute (const Name &id)
 Get an attribute.
void addAttribute (IAttribute &attribute, bool createOutput=false)
 Called to add an attribute to the object.
void removeAttribute (const Name &id)
 Called to remove an attribute of the object.

Constructors and destructor.

 ExtensibleSimulatedObject (Controller &ctrl, const ObjectDescriptor &objectDescriptor)
 Protected constructor of ExtensibleSimulatedObject call by derivate classes.
virtual ~ExtensibleSimulatedObject ()
 Destructor of ExtensibleSimulatedObject.
virtual void postConstruction ()
 The post construction.
virtual void finish ()
 The pre destruction.

Protected Member Functions

Reset and configuration loaders
virtual void init ()
 Init method inherited from SimulatedObject.
virtual bool loadParameters (const ConfigurationParameterDescriptor *node)
 Configuration parameters loader of ExtensibleSimulatedObject.
Computation
virtual void compute ()
 Compute method inherited from SimulatedObject.
virtual void computeInputs ()
 This part of the compute methods reads the inputs.
virtual void computeParameters ()
 This part of the compute methods computes the associated data.
virtual void computeOutputs ()
 This part of the compute methods copies the data in their associated output.

Protected Attributes

bool _exitOnInitError
 Flag to know how to handle error during init.

Detailed Description

Ancestor of every extensible objects.

Date:
2007-02-28
Author:
Benoît Chanclou
Module description :
This class defines all the items to create an extensible object.
Use it by derivation to add or overwrite the necessary methods. This base class is never implemented, only the derivate classes are. All the members of this class are protected except the destructor according to the OpenMASK precepts of simulated objects.

Some of the new features of the simulated objects of this OpenMASK version are their attributes and their extensibility.

Using attributes is a simple way to define parameters that can be seen by other objects. Using attributes gives automatically many features to manage the initialisation, connection, and event processing.

Using extensions is a simple way to modify the object features without modifying it. An extension can independently modify the attributes, the loading of the configuration, the computation or the event handling of its associated object.

For more details see the Attribute feature and Extension feature explanations.

Definition at line 71 of file OMKExtensibleSimulatedObject.h.


Member Typedef Documentation

typedef ValuedEventListenerCallBack< ExtensibleSimulatedObject, CreateAndAddExtensionType > OMK::ExtensibleSimulatedObject::CreateAndAddExtensionEventListener [protected]

Definition at line 167 of file OMKExtensibleSimulatedObject.h.

typedef std::map< Name, IAttribute* > OMK::ExtensibleSimulatedObject::AttributeStore [protected]

The storage type for attributes.

Definition at line 212 of file OMKExtensibleSimulatedObject.h.


Constructor & Destructor Documentation

ExtensibleSimulatedObject::ExtensibleSimulatedObject ( Controller ctrl,
const ObjectDescriptor objectDescriptor 
) [protected]

Protected constructor of ExtensibleSimulatedObject call by derivate classes.

Definition at line 43 of file OMKExtensibleSimulatedObject.cpp.

00044 : SimulatedObject( ctrl, objectDescriptor ),
00045   ExtensionManager(),
00046   _exitOnInitError( true )
00047 {
00048 }

ExtensibleSimulatedObject::~ExtensibleSimulatedObject (  )  [virtual]

Destructor of ExtensibleSimulatedObject.

The destructor delete all the extensions.

Definition at line 53 of file OMKExtensibleSimulatedObject.cpp.

00054 {
00055 }


Member Function Documentation

void ExtensibleSimulatedObject::postConstruction (  )  [virtual]

The post construction.

Parses the object descriptor to dynamically creates the extensions.
Retrieves the Extensions field in the object descriptor, extracts the extensions with a Class field, creates and adds them to the object.

Reimplemented from OMK::SimulatedObject.

Definition at line 57 of file OMKExtensibleSimulatedObject.cpp.

References OMK::ExtensionManager::createExtensionsFromParameters(), and OMK::SimulatedObject::getObjectDescriptor().

00058 {
00059   // Retrieve the extension fields to create the extensions which defined a "Class"
00060   createExtensionsFromParameters( this, getObjectDescriptor().getExtensionsParameters() ) ;
00061 }

void ExtensibleSimulatedObject::finish (  )  [virtual]

The pre destruction.

Delete all the extensions of the object.

Reimplemented from OMK::SimulatedObject.

Reimplemented in OMK::Vis::VisBase, and OMK::MKMHumano.

Definition at line 65 of file OMKExtensibleSimulatedObject.cpp.

References OMK::ExtensionManager::deleteExtensions(), and OMK::SimulatedObject::finish().

Referenced by OMK::Vis::VisBase::finish().

00066 {
00067   // Destroy every extensions
00068   deleteExtensions() ;
00069   // Calls the ancestor
00070   SimulatedObject::finish() ;
00071 }

void ExtensibleSimulatedObject::init (  )  [protected, virtual]

Init method inherited from SimulatedObject.

Calls the loaders.
Most of the time it is not necessary to redefine this method in the children class. If you have to add some initialisations, redefine and call the inherited method to load parameters or call directly the loaders.

Reimplemented from OMK::SimulatedObject.

Reimplemented in OMK::Clock, and OMK::Vis::VisBase.

Definition at line 74 of file OMKExtensibleSimulatedObject.cpp.

References _attributes, OMK::ExtensionManager::_orderedExtensionsForLoadParameters, OMK::ExtensionManager::_orderedExtensionsForPostCompute, OMK::ExtensionManager::_orderedExtensionsForPreCompute, OMK::debugMsg(), OMK::SimulatedObject::getConfigurationParameters(), OMK::ObjectDescriptor::getExtensionsParameters(), OMK::SimulatedObject::getObjectDescriptor(), OMK::ExtensionManager::loadFromExtensionsParameters(), OMK::ExtensionManager::loadFromObjectParameters(), OMK::ExtensionManager::loadOrder(), loadParameters(), OMFATALERROR, OMK_DEBUG_OMK_ATTR, and OMTRACEID.

Referenced by OMK::Vis::VisBase::init(), and OMK::Clock::init().

00075 {
00076   bool ok = true ;
00077 
00078   // The configuration parameter node
00079   const ConfigurationParameterDescriptor* node = getConfigurationParameters() ;
00080   const ConfigurationParameterDescriptor* extensionsNode = getObjectDescriptor().getExtensionsParameters() ;
00081   //---Load Extension order if there is one
00082   loadOrder( extensionsNode, "LoadParametersOrder", _orderedExtensionsForLoadParameters ) ;
00083  
00084   //---Load the user parameters
00085   // Load object parameters for the attributes 
00086   for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ )
00087   {
00088     OMTRACEID( OMK_DEBUG_OMK_ATTR, "Load configuration for " << OMK::debugMsg( i->second ) ) ;
00089     ok = i->second->loadParameters( node ) && ok ;
00090   }
00091 
00092   //--- Load parameters for extensions
00093   ok = loadFromObjectParameters( node ) && ok ;
00094 
00095   // Load object parameters for the object
00096   ok = loadParameters( node ) && ok ;
00097 
00098   //--- Load parameters for extensions
00099   // In case Extension parameter create extensionNode
00100   extensionsNode = getObjectDescriptor().getExtensionsParameters() ;
00101   ok = loadFromExtensionsParameters( extensionsNode ) && ok ;
00102 
00103   loadOrder( extensionsNode, "PreComputeOrder"    , _orderedExtensionsForPreCompute     ) ;
00104   loadOrder( extensionsNode, "PostComputeOrder"   , _orderedExtensionsForPostCompute    ) ;
00105 
00106   if( !ok )
00107   { // Not ok, display the following message and exit
00108     OMFATALERROR( "Error in ExtensibleSimulatedObject::init for " << debugMsg( this ) << std::endl
00109       << ">>> :-( Unable to initialize the object" ) ; 
00110   }
00111 }

bool ExtensibleSimulatedObject::loadParameters ( const ConfigurationParameterDescriptor node  )  [protected, virtual]

Configuration parameters loader of ExtensibleSimulatedObject.

Parameters:
[in] node the root node of the configuration parameter.
Returns:
true if all needed parameters can be read.
Reads in the configuration node the values to set the attributs. No data or output have been declared, this method does nothing.

Reimplemented in OMK::Vis::OgreVis, OMK::BasicHumano, OMK::FixedPoint, OMK::HumanoPlayer, OMK::HumanoRecorder, OMK::Orbit, OMK::Tracker, and OMK::Trajectory.

Definition at line 160 of file OMKExtensibleSimulatedObject.cpp.

Referenced by init(), OMK::Trajectory::loadParameters(), OMK::Tracker::loadParameters(), OMK::Orbit::loadParameters(), OMK::Vis::OgreVis::loadParameters(), OMK::FixedPoint::loadParameters(), and OMK::BasicHumano::loadParameters().

00161 { 
00162   return true ;
00163 }

void ExtensibleSimulatedObject::compute (  )  [protected, virtual]

Compute method inherited from SimulatedObject.

The compute method is splitted in three main parts:

The second method computeParameters is a pure virtual method and must be defined in the child classes.
The inputs and outputs should work with associated data, you should use these associated data.

The extensions take place between each step :

So the extensions could modify the associated data, after they have been retrieved in the inputs, and before they have been copied in the outputs.

See Computing of simulated object for more details.

Reimplemented from OMK::SimulatedObject.

Reimplemented in OMK::Clock.

Definition at line 114 of file OMKExtensibleSimulatedObject.cpp.

References computeInputs(), computeOutputs(), computeParameters(), OMK::ExtensionManager::postComputeExtension(), and OMK::ExtensionManager::preComputeExtension().

Referenced by OMK::Clock::compute().

00115 {
00116   // to retrieve the inputs value
00117   computeInputs();
00118 
00119   // Call the extensions which work on inputs parameters
00120   preComputeExtension() ;
00121 
00122   // To compute the behavior
00123   computeParameters();
00124 
00125   // Call the extensions which work on outputs parameters
00126   postComputeExtension() ;
00127 
00128   // To set the outputs
00129   computeOutputs();
00130 }

void ExtensibleSimulatedObject::computeInputs (  )  [protected, virtual]

This part of the compute methods reads the inputs.

The inputs should work with associated data. The inputs are read and put in the associated data.

Definition at line 134 of file OMKExtensibleSimulatedObject.cpp.

References _attributes.

Referenced by compute().

00135 {
00136   // Call the attribute which work with inputs 
00137   for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ )
00138   {
00139     i->second->getValueFromInput() ;
00140   }
00141 }

void ExtensibleSimulatedObject::computeParameters (  )  [protected, virtual]

This part of the compute methods computes the associated data.

The inputs and outputs should work with associated data, you should use these associated data.

Reimplemented in OMK::Vis::OgreVis, OMK::Vis::VisBase, OMK::BasicHumano, OMK::FixedPoint, OMK::HumanoPlayer, OMK::HumanoRecorder, OMK::Orbit, OMK::Tracker, OMK::Trajectory, and OMK::MKMHumano.

Definition at line 145 of file OMKExtensibleSimulatedObject.cpp.

Referenced by compute().

00146 {
00147 }

void ExtensibleSimulatedObject::computeOutputs (  )  [protected, virtual]

This part of the compute methods copies the data in their associated output.

The outputs should work with associated data. The outputs are set with the value of their associated data.

Definition at line 150 of file OMKExtensibleSimulatedObject.cpp.

References _attributes.

Referenced by compute().

00151 {
00152   // Call the attribute which work with outputs
00153   for( AttributeStore::iterator i = _attributes.begin() ; i != _attributes.end(); i++ )
00154   {
00155     i->second->setValueToOutput() ;
00156     i->second->resetUpdated() ;
00157   }
00158 }

void ExtensibleSimulatedObject::activateCreateExtensionByEvent ( bool  activate = true  )  [protected]

Activates the event processing for dynamic creation of extension.

Definition at line 165 of file OMKExtensibleSimulatedObject.cpp.

References _eventCreateAndAddExtensionListener, OMK::EventId::CREATE_AND_ADD_EXTENSION, and processCreateAndAddExtension().

00166 {
00167   if( activate ) 
00168   {
00169     if( !_eventCreateAndAddExtensionListener )
00170     {
00171       _eventCreateAndAddExtensionListener = new CreateAndAddExtensionEventListener
00172                          ( *this, 
00173                            &ExtensibleSimulatedObject::processCreateAndAddExtension, 
00174                            EventId::CREATE_AND_ADD_EXTENSION ) ; 
00175     }
00176   }
00177   else
00178   {
00179     delete _eventCreateAndAddExtensionListener ;
00180     _eventCreateAndAddExtensionListener = 0 ;
00181   }
00182 }

bool ExtensibleSimulatedObject::processCreateAndAddExtension ( CreateAndAddExtensionEvent *  event  )  [protected]

Called as a event processing call back to create and add an extension to the object.

Parameters:
[in] event see CreateAndAddExtensionEvent
see createAndAddExtension.

Definition at line 184 of file OMKExtensibleSimulatedObject.cpp.

References OMK::ExtensionManager::createAndAddExtension().

Referenced by activateCreateExtensionByEvent().

00185 {
00186   const CreateAndAddExtensionPrm& value = event->value.getValue() ;
00187   createAndAddExtension( this, value.first, value.second ) ;
00188   return true ;
00189 }

IAttribute * ExtensibleSimulatedObject::getAttribute ( const Name id  ) 

Get an attribute.

Parameters:
[in] id The id of the attribute to find.
Returns:
The attribute named id, or null if doesn't exist.

Definition at line 191 of file OMKExtensibleSimulatedObject.cpp.

References _attributes.

Referenced by OMK::Iii::InteractorOutput::create(), getBaseAttribute(), OMK::Iii::IConnector::IConnector(), OMK::MultiValuedEventSignalEmitterUtilT< T, ModelType >::loadParametersUtil(), and OMK::ValuedEventSignalEmitterUtilT< T, ModelType >::loadParametersUtil().

00192 {
00193   AttributeStore::iterator i = _attributes.find( id );
00194   return ( i == _attributes.end() ) ? 0 : i->second ;
00195 }

template<typename Type>
IAttributeBaseT< Type > * OMK::ExtensibleSimulatedObject::getBaseAttribute ( const Name id  )  [inline]

Get an attribute.

Parameters:
[in] id The id of the attribute to find.
Returns:
The attribute named id, or null if doesn't exist.
You must include "OMKExtensibleSimulatedObject.inl" to use this method.

Definition at line 34 of file OMKExtensibleSimulatedObject.inl.

References getAttribute().

Referenced by OMK::TriggerAttributeExtension::loadExtensionParameters(), OMK::DistanceToExtension::loadExtensionParameters(), OMK::MultiTriggerEmitterExtensionT< T, ModelType >::loadExtensionParameters(), OMK::TriggerEmitterExtensionT< T, ModelType >::loadExtensionParameters(), and OMK::TriggerEmitterExtension::loadExtensionParameters().

00035 {
00036   return dynamic_cast< IAttributeBaseT< Type >* >( getAttribute( id ) ) ;
00037 }

void ExtensibleSimulatedObject::addAttribute ( IAttribute attribute,
bool  createOutput = false 
)

Called to add an attribute to the object.

Parameters:
[in] attribute the attribute to add.
The attribute is stored in the attributes list.

This method must called for each the attribute of the object.

Definition at line 197 of file OMKExtensibleSimulatedObject.cpp.

References _attributes, OMK::debugMsg(), OMK::IAttribute::getId(), OMK::Name::getString(), OMK_DEBUG_OMK_ATTR, OMTRACEID, and OMK::IAttribute::setOwner().

Referenced by OMK::BasicHumano::BasicHumano(), OMK::MovingHumano::MovingHumano(), and OMK::TriggerBaseExtension::TriggerBaseExtension().

00198 {
00199   // Check for duplicate attribute
00200   AttributeStore::iterator i = _attributes.find( attribute.getId() );
00201   if( i == _attributes.end() ) 
00202   { 
00203     // Initialise the owner of the attribute as itself
00204     attribute.setOwner( this, createOutput ) ;
00205     // It is a really new item, adds it in the main list
00206     _attributes[ attribute.getId() ] = &attribute ;
00207   }
00208   else 
00209   {
00210     OMTRACEID( OMK_DEBUG_OMK_ATTR, 
00211       "Error to add attribute to " << debugMsg( this ) << std::endl
00212       << ">>> :-( The attribute \"" << attribute.getId().getString() << "\" is a duplicate one" ) ;
00213   }
00214 }

void ExtensibleSimulatedObject::removeAttribute ( const Name id  ) 

Called to remove an attribute of the object.

Parameters:
[in] id The id of the attribute to remove.
The attribute is removed of the attributes list, but it is not deleted.

Be careful, if a output has been created, it is not removed. Its value will be no more updated.

Definition at line 216 of file OMKExtensibleSimulatedObject.cpp.

References _attributes, OMK::debugMsg(), OMK_DEBUG_OMK_ATTR, and OMTRACEID.

Referenced by OMK::IAttribute::~IAttribute().

00217 {
00218   // Look for the attribute
00219   AttributeStore::iterator i = _attributes.find( id );
00220   if( i != _attributes.end() ) 
00221   {
00222     _attributes.erase( i ) ;
00223   }
00224   else 
00225   {
00226     OMTRACEID( OMK_DEBUG_OMK_ATTR, 
00227       "Error to remove attribute to " << debugMsg( this ) << std::endl
00228       << ">>> :-( The attribute \"" << id.getString() << "\" cannot be find" ) ;
00229   }
00230 }


Friends And Related Function Documentation

friend class ExtensionOfExtensionCreatorEvent [friend]

Definition at line 166 of file OMKExtensibleSimulatedObject.h.


Member Data Documentation

EventListener* OMK::ExtensibleSimulatedObject::_eventCreateAndAddExtensionListener [protected]

The event listener which receives the event to create and add extension.

Definition at line 169 of file OMKExtensibleSimulatedObject.h.

Referenced by activateCreateExtensionByEvent().

AttributeStore OMK::ExtensibleSimulatedObject::_attributes [protected]

List of attributes.

Stores pointers on attributes to aggregate them to the object.

Definition at line 215 of file OMKExtensibleSimulatedObject.h.

Referenced by addAttribute(), computeInputs(), computeOutputs(), getAttribute(), init(), and removeAttribute().

bool OMK::ExtensibleSimulatedObject::_exitOnInitError [protected]

Flag to know how to handle error during init.

Can be set in the constructor of the sons.

Definition at line 220 of file OMKExtensibleSimulatedObject.h.


logo OpenMask

Documentation generated on Mon Jun 9 11:46:02 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007