7 #include "fwAtomConversion/AtomToDataMappingVisitor.hpp" 9 #include "fwAtomConversion/camp_ext/ValueMapper.hpp" 10 #include "fwAtomConversion/convert.hpp" 11 #include "fwAtomConversion/DataVisitor.hpp" 12 #include "fwAtomConversion/exception/ConversionNotManaged.hpp" 13 #include "fwAtomConversion/mapper/Base.hpp" 15 #include <fwAtoms/Blob.hpp> 16 #include <fwAtoms/Boolean.hpp> 17 #include <fwAtoms/Map.hpp> 18 #include <fwAtoms/Numeric.hpp> 19 #include <fwAtoms/Numeric.hxx> 20 #include <fwAtoms/Sequence.hpp> 22 #include <fwCamp/factory/new.hpp> 24 #include <fwData/Object.hpp> 26 #include <fwMemory/BufferObject.hpp> 37 ::fwAtoms::Numeric::sptr m_typedAtom;
38 ::camp::UserObject& m_campDataObj;
39 const camp::SimpleProperty& m_property;
42 ::camp::UserObject& campDataObj,
43 const camp::SimpleProperty& property ) :
44 m_typedAtom(typedAtom),
45 m_campDataObj(campDataObj),
52 void operator()( ::boost::blank& )
const 54 m_property.set( m_campDataObj, m_typedAtom->getString() );
59 void operator()( const ::boost::blank& )
const 61 m_property.set( m_campDataObj, m_typedAtom->getString() );
67 void operator()( U& value )
const 69 m_property.set( m_campDataObj, value );
79 ::fwAtoms::Numeric::sptr m_typedAtom;
80 ::camp::UserObject& m_campDataObj;
81 const camp::ArrayProperty& m_property;
85 ::camp::UserObject& campDataObj,
86 const camp::ArrayProperty& property,
87 unsigned int index ) :
88 m_typedAtom(typedAtom),
89 m_campDataObj(campDataObj),
97 void operator()( ::boost::blank& )
const 99 if( m_property.dynamic() )
101 m_property.insert( m_campDataObj, m_index, m_typedAtom->getString() );
105 m_property.set( m_campDataObj, m_index, m_typedAtom->getString() );
111 void operator()( const ::boost::blank& )
const 113 if( m_property.dynamic() )
115 m_property.insert( m_campDataObj, m_index, m_typedAtom->getString() );
119 m_property.set( m_campDataObj, m_index, m_typedAtom->getString() );
125 template <
typename U>
126 void operator()( U& value )
const 128 if( m_property.dynamic() )
130 m_property.insert( m_campDataObj, m_index, value );
134 m_property.set( m_campDataObj, m_index, value );
144 ::fwAtoms::Numeric::sptr m_typedAtom;
145 ::camp::UserObject& m_campDataObj;
150 ::camp::UserObject& campDataObj,
152 const std::string& key ) :
153 m_typedAtom(typedAtom),
154 m_campDataObj(campDataObj),
155 m_property(property),
162 void operator()( ::boost::blank& )
const 164 m_property.set( m_campDataObj, m_key, m_typedAtom->getString() );
169 void operator()( const ::boost::blank& )
const 171 m_property.set( m_campDataObj, m_key, m_typedAtom->getString() );
176 template <
typename U>
177 void operator()( U& value )
const 179 m_property.set( m_campDataObj, m_key, value );
186 ::fwData::Object::sptr dataObj,
187 ::fwAtoms::Object::sptr atomObj,
188 AtomVisitor::DataCacheType& cache,
191 m_campDataObj( m_dataObj.get() ),
194 m_uuidPolicy(uuidPolicy)
206 const std::string& name( property.name() );
207 ::fwAtoms::Base::sptr atom = m_atomObj->getAttribute( name );
209 std::stringstream msg;
210 msg <<
"Atom attribute is not well formed. Attribute '" << name <<
"' missing for data conversion";
213 switch( atom->type() )
215 case ::fwAtoms::Base::NUMERIC:
217 ::fwAtoms::Numeric::sptr typedAtom = ::fwAtoms::Numeric::dynamicCast( atom );
219 typedAtom->getVariant() );
224 property.set( m_campDataObj, atom->getString() );
235 const std::string& name( property.name() );
236 ::fwAtoms::Base::sptr atom = m_atomObj->getAttribute( name );
238 std::stringstream msg;
239 msg <<
"Atom attribute is not well formed. Attribute '" << name <<
"' missing for data conversion";
242 property.set( m_campDataObj, atom->getString() );
249 const std::string& name( property.name() );
250 ::fwAtoms::Base::sptr atom = m_atomObj->getAttribute( name );
253 switch( atom->type() )
255 case ::fwAtoms::Base::BLOB:
257 ::fwAtoms::Blob::sptr blobAtom = ::fwAtoms::Blob::dynamicCast(atom);
258 ::fwMemory::BufferObject::sptr buffer;
259 buffer = ::camp_ext::ValueMapper< ::fwAtoms::Blob::sptr >::to(blobAtom);
261 "A blob cannot contain a null buffer pointer"),
263 property.set( m_campDataObj, ::camp::UserObject(buffer) );
266 case ::fwAtoms::Base::OBJECT:
268 ::fwAtoms::Object::sptr objectAtom = ::fwAtoms::Object::dynamicCast(atom);
269 ::fwData::Object::sptr objectData = ::fwAtomConversion::convert( objectAtom, m_cache, m_uuidPolicy );
270 property.set( m_campDataObj, objectData );
275 std::stringstream msg;
276 msg <<
"Attribute of type '";
277 switch( atom->type() )
279 case ::fwAtoms::Base::BOOLEAN:
282 case ::fwAtoms::Base::STRING:
285 case ::fwAtoms::Base::NUMERIC:
288 case ::fwAtoms::Base::MAP:
291 case ::fwAtoms::Base::SEQUENCE:
297 msg <<
"', are not supported in the data conversion process.";
309 const std::string& name( property.name() );
310 ::fwAtoms::Base::sptr atom = m_atomObj->getAttribute( name );
312 std::stringstream msg;
313 msg <<
"Atom attribute is not well formed. Attribute '" << name <<
"' missing for data conversion";
316 ::fwAtoms::Sequence::sptr seqAtom = ::fwAtoms::Sequence::dynamicCast(atom);
317 unsigned int index = 0;
318 for( ::fwAtoms::Base::sptr elemAtom : seqAtom->getValue() )
323 property.elementType() != ::camp::userType );
325 ::fwData::Object::sptr objectData;
326 if( property.dynamic() )
328 property.insert( m_campDataObj, index, objectData );
332 property.set( m_campDataObj, index, objectData );
337 switch( elemAtom->type() )
339 case ::fwAtoms::Base::BOOLEAN:
340 case ::fwAtoms::Base::STRING:
342 std::string value = elemAtom->getString();
344 if( property.dynamic() )
346 property.insert( m_campDataObj, index, value );
350 property.set( m_campDataObj, index, value );
354 case ::fwAtoms::Base::NUMERIC:
356 ::fwAtoms::Numeric::sptr typedAtom = ::fwAtoms::Numeric::dynamicCast( elemAtom );
358 typedAtom->getVariant() );
362 case ::fwAtoms::Base::OBJECT:
364 ::fwAtoms::Object::sptr objectAtom = ::fwAtoms::Object::dynamicCast(elemAtom);
365 ::fwData::Object::sptr objectData =
366 ::fwAtomConversion::convert( objectAtom, m_cache, m_uuidPolicy);
368 if( property.dynamic() )
370 property.insert( m_campDataObj, index, objectData );
374 property.set( m_campDataObj, index, objectData );
380 std::stringstream msg;
381 msg <<
"fwAtoms::Sequence elements of type '";
382 switch( elemAtom->type() )
384 case ::fwAtoms::Base::BLOB:
387 case ::fwAtoms::Base::MAP:
390 case ::fwAtoms::Base::SEQUENCE:
396 msg <<
"', are not supported in the data conversion process.";
410 const std::string& name( property.name() );
411 ::fwAtoms::Base::sptr atom = m_atomObj->getAttribute( name );
413 std::stringstream msg;
414 msg <<
"Atom attribute is not well formed. Attribute '" << name <<
"' missing for data conversion";
417 ::fwAtoms::Map::sptr mapAtom = ::fwAtoms::Map::dynamicCast(atom);
419 for( ::fwAtoms::Map::ValueType elemAtom : mapAtom->getValue() )
421 if (!elemAtom.second)
426 ::fwData::Object::sptr objectData;
427 property.set( m_campDataObj, elemAtom.first, objectData );
431 switch( elemAtom.second->type() )
433 case ::fwAtoms::Base::BOOLEAN:
434 case ::fwAtoms::Base::STRING:
436 std::string value = elemAtom.second->getString();
437 property.set( m_campDataObj, elemAtom.first, value );
440 case ::fwAtoms::Base::NUMERIC:
442 ::fwAtoms::Numeric::sptr typedAtom = ::fwAtoms::Numeric::dynamicCast( elemAtom.second );
445 typedAtom->getVariant() );
448 case ::fwAtoms::Base::OBJECT:
450 ::fwAtoms::Object::sptr objectAtom = ::fwAtoms::Object::dynamicCast(elemAtom.second);
451 ::fwData::Object::sptr objectData =
452 ::fwAtomConversion::convert( objectAtom, m_cache, m_uuidPolicy);
453 property.set( m_campDataObj, elemAtom.first, objectData );
456 case ::fwAtoms::Base::BLOB:
458 ::fwAtoms::Blob::sptr blobAtom = ::fwAtoms::Blob::dynamicCast(elemAtom.second);
459 ::fwMemory::BufferObject::sptr buffer;
460 buffer = ::camp_ext::ValueMapper< ::fwAtoms::Blob::sptr >::to(blobAtom);
462 "A blob cannot contain a null buffer pointer"),
464 property.set( m_campDataObj, elemAtom.first, ::camp::UserObject(buffer) );
469 std::stringstream msg;
470 msg <<
"fwAtoms::Map value elements of type '";
471 switch( elemAtom.second->type() )
473 case ::fwAtoms::Base::MAP:
476 case ::fwAtoms::Base::SEQUENCE:
482 msg <<
"', are not supported in the data conversion process.";
FWATOMCONVERSION_API void visit(const camp::SimpleProperty &property)
Visits data object simple property and fill it with associated atom attribute.
virtual FWATOMCONVERSION_API ~AtomToDataMappingVisitor()
Destructor. Does nothing.
This namespace contains the necessary class for fwData <-> fwAtoms conversion.
Throw this exception when a conversion between data and atom is not managed (error message explains t...
Visitor UUID Management policies.
FWATOMCONVERSION_API AtomToDataMappingVisitor(std::shared_ptr< ::fwData::Object >dataObj, std::shared_ptr< ::fwAtoms::Object >atomObj, AtomVisitor::DataCacheType &cache, const AtomVisitor::IReadPolicy &uuidPolicy)
Constructor. Initializes visitor.
FWCAMP_API Type elementType() const
Get the type of the map elements.