7 #include "fwDataTools/helper/Composite.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwData/Composite.hpp> 21 m_composite( _composite )
29 if(!m_addedObjects.empty() || !m_removedObjects.empty() || !m_newChangedObjects.empty() ||
30 !m_oldChangedObjects.empty())
38 void Composite::add( std::string _compositeKey, ::fwData::Object::sptr _newObject )
40 OSLM_FATAL_IF(
"The composite key " << _compositeKey <<
" does not exist in the composite, this is the key of the" 41 "object to be added.",
42 m_composite.lock()->find(_compositeKey) != m_composite.lock()->end() );
45 m_composite.lock()->getContainer()[ _compositeKey ] = _newObject;
47 m_addedObjects[_compositeKey] = _newObject;
55 OSLM_FATAL_IF(
"The composite key " << _compositeKey <<
" does not exist in the composite, this is the key of the" 56 "object to be removed.",
57 m_composite.lock()->find(_compositeKey) == m_composite.lock()->end() );
60 ::fwData::Object::sptr objBackup = m_composite.lock()->getContainer()[ _compositeKey ];
63 m_composite.lock()->getContainer().erase( _compositeKey );
65 m_removedObjects[_compositeKey] = objBackup;
73 ::fwData::Composite::sptr composite = m_composite.lock();
74 std::vector<std::string> vectKey;
75 std::transform( composite->begin(), composite->end(),
76 std::back_inserter(vectKey),
77 std::bind(&::fwData::Composite::value_type::first, std::placeholders::_1) );
79 for(std::string key : vectKey)
87 void Composite::swap( std::string _compositeKey, ::fwData::Object::sptr _newObject )
89 OSLM_FATAL_IF(
"The composite key " << _compositeKey <<
" does not exist in the composite, this is the key of the" 90 "object to be swapped.",
91 m_composite.lock()->find(_compositeKey) == m_composite.lock()->end() );
94 ::fwData::Object::sptr objBackup = m_composite.lock()->getContainer()[ _compositeKey ];
96 if( objBackup != _newObject )
99 m_composite.lock()->getContainer()[ _compositeKey ] = _newObject;
101 m_newChangedObjects[_compositeKey] = _newObject;
102 m_oldChangedObjects[_compositeKey] = objBackup;
107 "Cannot swap this object ( "<< _compositeKey <<
108 " ) in composite because it is the same object. Do nothing (not notification)");
116 if ( !m_removedObjects.empty() )
121 sig->asyncEmit(m_removedObjects);
123 if ( !m_newChangedObjects.empty() && !m_oldChangedObjects.empty() )
128 sig->asyncEmit(m_newChangedObjects, m_oldChangedObjects);
130 if ( !m_addedObjects.empty() )
135 sig->asyncEmit(m_addedObjects);
137 OSLM_INFO_IF(
"No changes were found on the composite '" + m_composite.lock()->getID() +
"', nothing to notify.",
138 m_addedObjects.empty() && m_newChangedObjects.empty() && m_removedObjects.empty());
140 m_removedObjects.clear();
141 m_newChangedObjects.clear();
142 m_oldChangedObjects.clear();
143 m_addedObjects.clear();
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_OBJECTS_SIG
Type of signal when objects are added.
#define OSLM_INFO_IF(message, cond)
#define OSLM_INFO(message)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
#define OSLM_FATAL_IF(message, cond)