7 #include "dataReg/parser/Composite.hpp" 9 #include <fwData/Composite.hpp> 11 #include <fwServices/macros.hpp> 13 #include <boost/foreach.hpp> 24 bool Composite::refObjectValidator( ::fwRuntime::ConfigurationElement::sptr _cfgElement )
29 configEltIter != _cfgElement->end();
32 std::string subElementName = (*configEltIter)->getName();
33 if( subElementName !=
"service" &&
34 subElementName !=
"serviceList" )
37 "xml subelement \""<< subElementName <<
38 "\" for element object is not supported for the moment when you use a reference on item composite.");
50 SLM_FATAL(
"This method is deprecated, and this, shouldn't be used.");
55 void Composite::createConfig( ::fwTools::Object::sptr _obj )
58 const std::string OBJECT_BUILD_MODE =
"src";
59 const std::string BUILD_OBJECT =
"new";
60 const std::string GET_OBJECT =
"ref";
62 ::fwData::Composite::sptr dataComposite = ::fwData::Composite::dynamicCast(_obj);
63 SLM_ASSERT(
"The passed object must be a fwData::Composite", dataComposite);
65 for( ::fwRuntime::ConfigurationElement::csptr elem : m_cfg->getElements() )
67 if( elem->getName() ==
"item" )
71 std::string buildMode = BUILD_OBJECT;
73 if ( elem->hasAttribute( OBJECT_BUILD_MODE ) )
75 buildMode = elem->getExistingAttributeValue( OBJECT_BUILD_MODE );
76 OSLM_ASSERT(
"The buildMode \""<< buildMode <<
"\" is not supported, it should be either BUILD_OBJECT" 78 buildMode == BUILD_OBJECT || buildMode == GET_OBJECT );
81 SLM_ASSERT(
"The xml element \"item\" must have an attribute named \"key\" .",
82 elem->hasAttribute(
"key") );
83 std::string key = elem->getExistingAttributeValue(
"key");
84 SLM_ASSERT(
"The xml element \"item\" must have an attribute named \"key\" which is not empty.",
86 SLM_ASSERT(
"The xml element \"item\" must have one (and only one) xml sub-element \"object\".",
87 elem->size() == 1 && (*elem->getElements().begin())->getName() ==
"object" );
89 if( buildMode == BUILD_OBJECT )
92 OSLM_ASSERT(
"The key "<< key <<
" already exists in the composite.", dataComposite->find(
93 key ) == dataComposite->end() );
97 ctm->::fwServices::IAppConfigManager::setConfig( elem );
99 m_ctmContainer.push_back( ctm );
101 ::fwData::Object::sptr localObj = ctm->getConfigRoot();
104 SLM_ASSERT(
"A ::fwData::Composite can contain only ::fwData::Object", localObj );
105 (*dataComposite)[ key ] = localObj;
118 void Composite::startConfig()
120 for( ::fwServices::IAppConfigManager::sptr ctm : m_ctmContainer )
128 void Composite::updateConfig()
130 for( ::fwServices::IAppConfigManager::sptr ctm : m_ctmContainer )
138 void Composite::stopConfig()
140 BOOST_REVERSE_FOREACH( ::fwServices::IAppConfigManager::sptr ctm, m_ctmContainer )
148 void Composite::destroyConfig()
150 BOOST_REVERSE_FOREACH( ::fwServices::IAppConfigManager::sptr ctm, m_ctmContainer )
154 m_ctmContainer.clear();
Specific service for the construction of a Composite and its associated services from an XML-based de...
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace dataReg (data registration) contains classes which allow to parse the xml configuration...
#define SLM_FATAL(message)
#define OSLM_ERROR(message)
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
This class defines a composite object.
virtual DATAREG_API void updating() override
Updating method : create composite object.
Service type for the construction of an object and associated services from an XML-based description...
Container::iterator Iterator
Defines the configuration element container type.