7 #include "fwDataTools/helper/Field.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwData/Exception.hpp> 12 #include <fwData/Object.hpp> 41 void Field::setField(
const fwData::Object::FieldNameType& name, fwData::Object::sptr obj)
50 ::fwData::Object::sptr
object =
m_object.lock();
51 SLM_ASSERT(
"Field helper need a non-null object pointer",
object);
52 const ::fwData::Object::FieldMapType oldFields =
object->getFields();
53 this->buildMessage(oldFields, newFields);
54 object->setFields(newFields);
66 void Field::add(
const fwData::Object::FieldNameType& _name, fwData::Object::sptr _obj)
68 ::fwData::Object::sptr
object =
m_object.lock();
69 SLM_ASSERT(
"Field helper need a non-null object pointer",
object);
71 ::fwData::Object::sptr field =
object->getField(_name);
76 object->setField(_name, _obj);
81 void Field::swap(
const fwData::Object::FieldNameType& _name, fwData::Object::sptr _obj)
84 ::fwData::Object::sptr
object =
m_object.lock();
86 ::fwData::Object::sptr field =
object->getField(_name);
92 object->setField(_name, _obj);
97 void Field::addOrSwap(
const fwData::Object::FieldNameType& _name, fwData::Object::sptr _obj)
100 ::fwData::Object::sptr
object =
m_object.lock();
102 ::fwData::Object::sptr field =
object->getField(_name);
113 object->setField(_name, _obj);
121 ::fwData::Object::sptr
object =
m_object.lock();
122 ::fwData::Object::sptr field =
object->getField(_name);
127 object->removeField(_name);
135 ::fwData::Object::sptr
object =
m_object.lock();
137 auto fieldNames =
object->getFieldNames();
138 for(
const auto& name : fieldNames)
140 ::fwData::Object::sptr field =
object->getField(name);
142 object->removeField(name);
174 +
"', nothing to notify.",
185 void Field::buildMessage(const ::fwData::Object::FieldMapType& oldFields,
186 const ::fwData::Object::FieldMapType& newFields)
188 ::fwData::Object::FieldNameVectorType oldFieldNames;
189 ::fwData::Object::FieldNameVectorType newFieldNames;
192 oldFields.begin(), oldFields.end(),
193 std::back_inserter(oldFieldNames),
194 std::bind(&::fwData::Object::FieldMapType::value_type::first, std::placeholders::_1)
197 newFields.begin(), newFields.end(),
198 std::back_inserter(newFieldNames),
199 std::bind(&::fwData::Object::FieldMapType::value_type::first, std::placeholders::_1)
202 std::sort(oldFieldNames.begin(), oldFieldNames.end());
203 std::sort(newFieldNames.begin(), newFieldNames.end());
205 ::fwData::Object::FieldNameVectorType added;
206 ::fwData::Object::FieldNameVectorType changed;
207 ::fwData::Object::FieldNameVectorType removed;
210 newFieldNames.begin(), newFieldNames.end(),
211 oldFieldNames.begin(), oldFieldNames.end(),
212 std::back_inserter(added)
215 std::set_intersection(
216 newFieldNames.begin(), newFieldNames.end(),
217 oldFieldNames.begin(), oldFieldNames.end(),
218 std::back_inserter(changed)
222 oldFieldNames.begin(), oldFieldNames.end(),
223 newFieldNames.begin(), newFieldNames.end(),
224 std::back_inserter(removed)
227 for(const ::fwData::Object::FieldNameVectorType::value_type& fieldName : added)
229 m_addedFields[fieldName] = newFields.find(fieldName)->second;
232 for(const ::fwData::Object::FieldNameVectorType::value_type& fieldName : changed)
238 for(const ::fwData::Object::FieldNameVectorType::value_type& fieldName : removed)
Implements data exception class.
#define OSLM_INFO_IF(message, cond)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_FIELDS_SIG
Type of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_FIELDS_SIG
Type of signal m_sigModified.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_FIELDS_SIG
Type of signal m_sigModified.