#include <OMKExtensionManager.h>
Inheritance diagram for OMK::ExtensionManager:
Extensions | |
See Extension feature for details | |
typedef std::pair< Name, Name > | CreateAndAddExtensionPrm |
Type of create and add parameters. | |
typedef std::map< Name, Extension * > | ExtensionStore |
The storage type for extensions. | |
typedef std::list< Extension * > | ExtensionList |
The ordered storage type for extensions. | |
DECLARE_TYPE_EVENT (CreateAndAddExtensionPrm, CreateAndAddExtension) | |
Defines CreateAndAddExtensionType and CreateAndAddExtensionEvent. | |
Extension * | createAndAddExtension (ExtensibleSimulatedObject *owner, const Name &classId, const Name &id) |
Called to create and add an extension to the object. | |
void | createExtensionsFromParameters (ExtensibleSimulatedObject *owner, const ConfigurationParameterDescriptor *node) |
Creates and adds extensions according to the configuration node. | |
void | deleteExtensions () |
Delete all the extensions. | |
void | preComputeExtension () |
Calls the preComputeParameters of each extension. | |
void | postComputeExtension () |
Calls the postComputeParameters of each extension. | |
bool | loadFromExtensionsParameters (const ConfigurationParameterDescriptor *extensionNode) |
Configuration parameters loader of ExtensibleSimulatedObject. | |
bool | loadFromObjectParameters (const ConfigurationParameterDescriptor *node) |
void | loadOrder (const ConfigurationParameterDescriptor *node, const std::string &name, ExtensionList &extensionsList) |
To load the order. | |
void | addExtension (Extension *extension) |
Called to add an extension to the object. | |
Extension * | removeExtension (const Name &id) |
Called to remove an extension of the object. | |
void | removeAndDeleteExtension (const Name &id) |
Called to remove an extension of the object. | |
Extension * | getExtension (const Name &id) |
Called to retrieve an extension of the object. | |
template<typename Type> | |
Type * | getExtensionT (const Name &id) |
Called to retrieve an typed extension of the object. | |
Public Attributes | |
ExtensionStore | _extensions |
List of extensions. | |
ExtensionList | _orderedExtensionsForLoadParameters |
List of extensions. | |
ExtensionList | _orderedExtensionsForPreCompute |
Stores pointers on extensions to schedule them for pre-computing. | |
ExtensionList | _orderedExtensionsForPostCompute |
Stores pointers on extensions to schedule them for post-computing. |
Definition at line 43 of file OMKExtensionManager.h.
typedef std::pair< Name, Name > OMK::ExtensionManager::CreateAndAddExtensionPrm |
Type of create and add parameters.
classId | The first item is the class id of the extension to create | |
id | The second item is the id of the extension to create |
Definition at line 62 of file OMKExtensionManager.h.
typedef std::map< Name, Extension* > OMK::ExtensionManager::ExtensionStore |
typedef std::list< Extension* > OMK::ExtensionManager::ExtensionList |
OMK::ExtensionManager::ExtensionManager | ( | ) |
Constructor of ExtensionManager call by derivate classes.
Definition at line 37 of file OMKExtensionManager.cpp.
OMK::ExtensionManager::~ExtensionManager | ( | ) | [virtual] |
Destructor of ExtensionManager.
The destructor delete all the extensions.
Definition at line 44 of file OMKExtensionManager.cpp.
OMK::ExtensionManager::ExtensionManager | ( | ) |
Constructor of ExtensionManager call by derivate classes.
Definition at line 37 of file OMKExtensionManager.cpp.
OMK::ExtensionManager::~ExtensionManager | ( | ) | [virtual] |
Destructor of ExtensionManager.
The destructor delete all the extensions.
Definition at line 44 of file OMKExtensionManager.cpp.
OMK::ExtensionManager::DECLARE_TYPE_EVENT | ( | CreateAndAddExtensionPrm | , | |
CreateAndAddExtension | ||||
) |
Defines CreateAndAddExtensionType and CreateAndAddExtensionEvent.
Extension * OMK::ExtensionManager::createAndAddExtension | ( | ExtensibleSimulatedObject * | owner, | |
const Name & | classId, | |||
const Name & | id | |||
) |
Called to create and add an extension to the object.
[in] | owner | the owner of the extension to create |
[in] | classId | the class id of the extension to create |
[in] | id | the id of the extension to add |
Definition at line 249 of file OMKExtensionManager.cpp.
References addExtension(), OMK::debugMsg(), OMK_DEBUG_OMK_EXEC, OMK_DEBUG_OMK_EXT, and OMTRACEID.
Referenced by createExtensionsFromParameters(), and OMK::ExtensibleSimulatedObject::processCreateAndAddExtension().
00250 { 00251 Extension *extension = ExtensionFactory::getInstance().create( classId )( owner, id, false ) ; 00252 if( extension ) 00253 { 00254 addExtension( extension ) ; 00255 OMTRACEID( OMK_DEBUG_OMK_EXEC, "Information for " << debugMsg( extension ) << std::endl 00256 << ">>> :-) Created" ) ; 00257 } 00258 else 00259 { 00260 OMTRACEID( OMK_DEBUG_OMK_EXT, 00261 "Error to create extension" << std::endl 00262 << ">>> :-( Unable to create the extension \"" << id << "\" with the class id \"" << classId << "\"." << std::endl ) ; 00263 } 00264 return extension ; 00265 }
void OMK::ExtensionManager::createExtensionsFromParameters | ( | ExtensibleSimulatedObject * | owner, | |
const ConfigurationParameterDescriptor * | node | |||
) |
Creates and adds extensions according to the configuration node.
[in] | owner | the owner of the extensions to create |
[in] | node | the node where are the extension descriptions |
Definition at line 48 of file OMKExtensionManager.cpp.
References createAndAddExtension(), OMK::ParametersAccessor::get(), and OMK::ConfigurationParameterDescriptor::getNumberOfSubItems().
Referenced by OMK::ExtensibleSimulatedObject::postConstruction().
00049 { 00050 // Retrieve the extension fields to create the extensions which defined a "Class" 00051 if( node ) 00052 { 00053 int nbItems = node->getNumberOfSubItems() ; 00054 for( int i = 0 ; i < nbItems ; ++i ) 00055 { 00056 // Retrieves parameters sets for each extension 00057 Name id( static_cast<const MultipleConfigurationParameter *>( node )->getNameOfSubDescriptor( i ) ) ; 00058 const ConfigurationParameterDescriptor * extensionParam = node->getSubDescriptorByPosition( i ) ; 00059 // Try to retrieve the class id to create the extension 00060 std::string classId ; 00061 if( ParametersAccessor::get( extensionParam, "Class", classId ) ) 00062 { // ClassId is ok => Create the extension 00063 createAndAddExtension( owner, classId, id ) ; 00064 } 00065 } 00066 } 00067 }
void OMK::ExtensionManager::deleteExtensions | ( | ) |
Delete all the extensions.
This method is automatically called by the destructor, but it can be called before, example in the finish method of ExtensibleSimulatedObject.
Definition at line 71 of file OMKExtensionManager.cpp.
References _extensions, _orderedExtensionsForLoadParameters, _orderedExtensionsForPostCompute, and _orderedExtensionsForPreCompute.
Referenced by OMK::ExtensibleSimulatedObject::finish().
00072 { 00073 // Destroy every extensions 00074 for( ExtensionStore::iterator i = _extensions.begin() ; i != _extensions.end() ; i++ ) 00075 { 00076 delete i->second ; 00077 } 00078 _extensions.clear() ; 00079 _orderedExtensionsForLoadParameters.clear() ; 00080 _orderedExtensionsForPreCompute.clear() ; 00081 _orderedExtensionsForPostCompute.clear() ; 00082 }
void OMK::ExtensionManager::preComputeExtension | ( | ) |
Calls the preComputeParameters of each extension.
The order is the one defined in _orderedExtensionsForPreCompute.
Definition at line 106 of file OMKExtensionManager.cpp.
References _orderedExtensionsForPreCompute.
Referenced by OMK::ExtensibleSimulatedObject::compute().
00107 { 00108 // Call the extensions which work on inputs parameters 00109 for( ExtensionList::iterator i = _orderedExtensionsForPreCompute.begin() ; i != _orderedExtensionsForPreCompute.end(); ) 00110 { 00111 // should pass to the next extension because maybe the current extension will be self destruct ! 00112 ExtensionList::iterator current = i ; 00113 i++ ; 00114 (*current)->preComputeParameters() ; 00115 } 00116 }
void OMK::ExtensionManager::postComputeExtension | ( | ) |
Calls the postComputeParameters of each extension.
The order is the one defined in _orderedExtensionsForPostCompute.
Definition at line 119 of file OMKExtensionManager.cpp.
References _orderedExtensionsForPostCompute.
Referenced by OMK::ExtensibleSimulatedObject::compute().
00120 { 00121 // Call the extensions which work on outputs parameters 00122 for( ExtensionList::iterator i = _orderedExtensionsForPostCompute.begin() ; i != _orderedExtensionsForPostCompute.end(); ) 00123 { 00124 // should pass to the next extension because maybe the current extension will be self destruct ! 00125 ExtensionList::iterator current = i ; 00126 i++ ; 00127 (*current)->postComputeParameters() ; 00128 } 00129 }
bool OMK::ExtensionManager::loadFromExtensionsParameters | ( | const ConfigurationParameterDescriptor * | extensionNode | ) |
Configuration parameters loader of ExtensibleSimulatedObject.
[in] | node | the root node of the configuration parameter of the object. |
[in] | extensionNode | the root node of the configuration parameter of the extensions. |
The extensions are declared in the configuration file in the UserParameters field of the object and in the parameters of each extension like this :
myObject { Class MyObjectClassId Scheduling { ...scheduling parameters } UserParams { ...user parameters } Extensions { extensionNumber1 { Class MyExtensionClassId ...other parameters of the extension } extensionNumber2 { Class MyExtensionOtherClassId ...other parameters of the extension } ...other extensions } }
Definition at line 132 of file OMKExtensionManager.cpp.
References _orderedExtensionsForLoadParameters, and OMK::ParametersAccessor::get().
Referenced by OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadExtensionParameters(), and OMK::ContainerExtension::loadExtensionParameters().
00133 { 00134 bool ok = true ; 00135 if( extensionNode ) 00136 { 00137 // Retrieve the each extension fields to configure the extension 00138 for( ExtensionList::iterator i = _orderedExtensionsForLoadParameters.begin() ; i != _orderedExtensionsForLoadParameters.end(); i++ ) 00139 { 00140 const ConfigurationParameterDescriptor* subExtensionNode = 0 ; 00141 ParametersAccessor::get( extensionNode, (*i)->getId().getCString(), subExtensionNode ) ; 00142 // call the extension parameter loader 00143 ok = (*i)->loadExtensionParameters( subExtensionNode ) && ok ; 00144 } 00145 } 00146 00147 return ok ; 00148 }
bool OMK::ExtensionManager::loadFromObjectParameters | ( | const ConfigurationParameterDescriptor * | node | ) |
Definition at line 150 of file OMKExtensionManager.cpp.
References _orderedExtensionsForLoadParameters.
Referenced by OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadObjectParameters(), and OMK::ContainerExtension::loadObjectParameters().
00151 { 00152 bool ok = true ; 00153 // Load object parameters for the extensions 00154 for( ExtensionList::iterator i = _orderedExtensionsForLoadParameters.begin() ; i != _orderedExtensionsForLoadParameters.end() ; ) 00155 { 00156 // should pass to the next extension because maybe the current extension will be self destruct ! 00157 ExtensionList::iterator current = i ; 00158 i++ ; 00159 ok = (*current)->loadObjectParameters( node ) && ok ; 00160 } 00161 00162 return ok ; 00163 }
void OMK::ExtensionManager::loadOrder | ( | const ConfigurationParameterDescriptor * | node, | |
const std::string & | name, | |||
ExtensionList & | extensionsList | |||
) |
To load the order.
Calls for both LoadParametersOrder, PreComputeOrder and PostComputeOrder configuration parameters to initialise the three ordered lists : _orderedExtensionsForLoadParameters, _orderedExtensionsForPreCompute and _orderedExtensionsForPostCompute)
Definition at line 86 of file OMKExtensionManager.cpp.
References _extensions, OMK::ParametersAccessor::get(), and OMASSERTM.
Referenced by OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadExtensionParameters(), and OMK::ContainerExtension::loadExtensionParameters().
00089 { 00090 std::vector< Name > order ; 00091 if( ParametersAccessor::get( node, name, order ) ) 00092 { 00093 OMASSERTM( extensionsList.size() == order.size(), "The list \"" << name << "\" has not the good size" ) ; 00094 extensionsList.clear() ; 00095 for( size_t i = 0 ; i < order.size() ; i++ ) 00096 { 00097 ExtensionStore::const_iterator iterator = _extensions.find( order[ i ] ) ; 00098 OMASSERTM( iterator != _extensions.end(), "Cannot find the extension \"" << order[ i ] << "\"" ) ; 00099 extensionsList.push_back( iterator->second ) ; 00100 } 00101 } 00102 }
void OMK::ExtensionManager::addExtension | ( | Extension * | extension | ) |
Called to add an extension to the object.
[in] | extension | the extension to add |
This method is called by the extension constructor, no one else should call it.
Definition at line 165 of file OMKExtensionManager.cpp.
References _extensions, _orderedExtensionsForLoadParameters, _orderedExtensionsForPostCompute, _orderedExtensionsForPreCompute, OMK::Extension::getId(), OMK::Name::getString(), OMK_DEBUG_OMK_EXT, and OMTRACEID.
Referenced by createAndAddExtension(), and OMK::Extension::Extension().
00166 { 00167 // return value 00168 std::string errorMsg ; 00169 bool ok = false ; 00170 if( extension ) 00171 { 00172 // Check for duplicate extension 00173 ExtensionStore::iterator i = _extensions.find( extension->getId() ); 00174 if( i == _extensions.end() ) 00175 { 00176 // It is a really new item, adds it in the main list 00177 _extensions[ extension->getId() ] = extension ; 00178 _orderedExtensionsForLoadParameters.push_back( extension ) ; 00179 _orderedExtensionsForPreCompute .push_back( extension ) ; 00180 _orderedExtensionsForPostCompute .push_back( extension ) ; 00181 ok = true ; 00182 } 00183 else 00184 { 00185 // Duplicate Item 00186 errorMsg = "The extension \"" ; 00187 errorMsg += extension->getId().getString() ; 00188 errorMsg += "\" is a duplicate one" ; 00189 } 00190 } 00191 else 00192 { 00193 errorMsg = "No extension to add" ; 00194 } 00195 // Unable to add the extension => error message 00196 if( !ok ) 00197 { 00198 OMTRACEID( OMK_DEBUG_OMK_EXT, 00199 "Error to add extension" << std::endl 00200 << ">>> :-( " << errorMsg << "." << std::endl ) ; 00201 } 00202 }
Called to remove an extension of the object.
Definition at line 204 of file OMKExtensionManager.cpp.
References _extensions, _orderedExtensionsForLoadParameters, _orderedExtensionsForPostCompute, _orderedExtensionsForPreCompute, OMK::debugMsg(), OMK_DEBUG_OMK_EXEC, OMK_DEBUG_OMK_EXT, and OMTRACEID.
00205 { 00206 Extension* extension = 0 ; 00207 // look for the extension 00208 ExtensionStore::iterator i = _extensions.find( id ) ; 00209 if( i != _extensions.end() ) 00210 { 00211 extension = i->second ; 00212 // remove the extension 00213 _extensions.erase( i ) ; 00214 _orderedExtensionsForLoadParameters.remove( extension ) ; 00215 _orderedExtensionsForPreCompute.remove( extension ) ; 00216 _orderedExtensionsForPostCompute.remove( extension ) ; 00217 OMTRACEID( OMK_DEBUG_OMK_EXEC, "Information for " << debugMsg( extension, 0 ) << std::endl 00218 << ">>> :-) removed from object" ) ; 00219 } 00220 else 00221 { 00222 // unknow Item 00223 OMTRACEID( OMK_DEBUG_OMK_EXT, 00224 "Unable to remove the extension from" << std::endl 00225 << ">>> :-( The extension \"" << id << "\" is not an extension of this object." << std::endl ) ; 00226 } 00227 return extension ; 00228 }
void OMK::ExtensionManager::removeAndDeleteExtension | ( | const Name & | id | ) | [inline] |
Called to remove an extension of the object.
The extension is removed of the extension list, and then deleted.
Definition at line 156 of file OMKExtensionManager.h.
00156 { delete removeExtension( id ) ; }
Called to retrieve an extension of the object.
Definition at line 230 of file OMKExtensionManager.cpp.
References _extensions, OMK_DEBUG_OMK_EXT, and OMTRACEID.
Referenced by getExtensionT().
00231 { 00232 Extension* extension = 0 ; 00233 // look for the extension 00234 ExtensionStore::iterator i = _extensions.find( id ) ; 00235 if( i != _extensions.end() ) 00236 { 00237 extension = i->second ; 00238 } 00239 else 00240 { 00241 // unknow Item 00242 OMTRACEID( OMK_DEBUG_OMK_EXT, 00243 "Unable to find the extension" << std::endl 00244 << ">>> :-( The extension \"" << id << "\" is not an extension of this object." << std::endl ) ; 00245 } 00246 return extension ; 00247 }
Type * OMK::ExtensionManager::getExtensionT | ( | const Name & | id | ) |
Called to retrieve an typed extension of the object.
Type | the type of the extension. |
Definition at line 181 of file OMKExtensionManager.h.
References getExtension(), OMK_DEBUG_OMK_EXT, and OMTRACEID.
00182 { 00183 // look for the extension 00184 Extension* extension = getExtension( id ) ; 00185 // cast it 00186 Type* extensionT = dynamic_cast< Type* >( extension ) ; 00187 if( extension && !extensionT ) 00188 { 00189 // Unable to cast <=> wrong type 00190 OMTRACEID( OMK_DEBUG_OMK_EXT, 00191 "Unable to convert the extension" << std::endl 00192 << ">>> :-( The extension \"" << id.getString() << "\" is not of the type \"" << typeid( Type ).name() << "\"" << std::endl ) ; 00193 } 00194 // and return id 00195 return extensionT ; 00196 }
List of extensions.
Stores pointers on extensions to aggregate them to the object.
Definition at line 170 of file OMKExtensionManager.h.
Referenced by addExtension(), deleteExtensions(), getExtension(), loadOrder(), and removeExtension().
List of extensions.
Stores pointers on extensions to schedule them for parameters loading.
Definition at line 173 of file OMKExtensionManager.h.
Referenced by addExtension(), deleteExtensions(), OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadExtensionParameters(), OMK::ContainerExtension::loadExtensionParameters(), loadFromExtensionsParameters(), loadFromObjectParameters(), and removeExtension().
Stores pointers on extensions to schedule them for pre-computing.
Definition at line 175 of file OMKExtensionManager.h.
Referenced by addExtension(), deleteExtensions(), OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadExtensionParameters(), OMK::ContainerExtension::loadExtensionParameters(), preComputeExtension(), and removeExtension().
Stores pointers on extensions to schedule them for post-computing.
Definition at line 177 of file OMKExtensionManager.h.
Referenced by addExtension(), deleteExtensions(), OMK::ExtensibleSimulatedObject::init(), OMK::TriggerContainerExtension::loadExtensionParameters(), OMK::ContainerExtension::loadExtensionParameters(), postComputeExtension(), and removeExtension().
Documentation generated on Mon Jun 9 11:46:01 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |