7 #include "fwAtomConversion/DataVisitor.hpp" 9 #include "fwAtomConversion/convert.hpp" 10 #include "fwAtomConversion/exception/ConversionNotManaged.hpp" 11 #include "fwAtomConversion/mapper/factory/new.hpp" 13 #include <fwAtoms/Base.hpp> 14 #include <fwAtoms/Blob.hpp> 15 #include <fwAtoms/Boolean.hpp> 16 #include <fwAtoms/Map.hpp> 17 #include <fwAtoms/Numeric.hpp> 18 #include <fwAtoms/Numeric.hxx> 19 #include <fwAtoms/Sequence.hpp> 20 #include <fwAtoms/String.hpp> 22 #include <fwCamp/Mapper/ValueMapper.hpp> 23 #include <fwCamp/factory/new.hpp> 25 #include <fwData/Array.hpp> 26 #include <fwData/camp/mapper.hpp> 28 #include <fwDataCamp/Version.hpp> 30 #include <fwMedDataCamp/Version.hpp> 32 #include <fwMemory/BufferObject.hpp> 34 #include <fwTools/UUID.hpp> 36 #include <boost/utility/enable_if.hpp> 38 #include <camp/class.hpp> 46 static int dataCampVersion = ::fwDataCamp::Version::s_CURRENT_VERSION;
47 static int medDataCampVersion = ::fwMedDataCamp::Version::s_CURRENT_VERSION;
56 DataVisitor::AtomCacheType& m_cache;
62 ::fwAtoms::Base::sptr operator()(camp::NoType value)
65 "Enter in void GetCampValueVisitor()(camp::NoType value) : case not managed" ) );
66 ::fwAtoms::Base::sptr val;
70 ::fwAtoms::Base::sptr operator()(
bool value)
72 return ::fwAtoms::Boolean::New( value );
75 ::fwAtoms::Base::sptr operator()(
long value)
77 return ::fwAtoms::Numeric::New( value );
80 ::fwAtoms::Base::sptr operator()(
double value)
82 return ::fwAtoms::Numeric::New( value );
85 ::fwAtoms::Base::sptr operator()(std::string value)
87 return ::fwAtoms::String::New( value );
90 ::fwAtoms::Base::sptr operator()(
const camp::EnumObject& value)
92 return ::fwAtoms::String::New( value.name() );
95 ::fwAtoms::Base::sptr operator()(
const camp::UserObject& value)
97 ::fwAtoms::Base::sptr baseObj;
99 if ( value.pointer() )
101 DataVisitor::ClassnameType classname = value.call(
"classname").to<std::string>();
103 if( classname ==
"::fwMemory::BufferObject" )
112 ::fwData::Object::sptr dataObj = ptr->getSptr();
114 baseObj = ::fwAtomConversion::convert( dataObj, m_cache );
125 : m_campDataObj( dataObj.get() ), m_cache( cache )
129 m_atomObj = ::fwAtoms::Object::New();
130 ClassnameType classname = m_campDataObj.call(
"classname").to<std::string>();
131 m_atomObj->setMetaInfo( DataVisitor::CLASSNAME_METAINFO, classname );
133 m_atomObj->setMetaInfo( DataVisitor::ID_METAINFO, uuid );
134 m_cache[uuid] = m_atomObj;
137 const camp::Class& metaclass = ::camp::classByName(classname);
138 std::size_t tagCount = metaclass.tagCount();
139 for ( std::size_t i = 0; i < tagCount; ++i )
141 const ::camp::Value& tag = metaclass.tagId(i);
142 const ::camp::Value& val = metaclass.tag(tag);
143 m_atomObj->setMetaInfo( tag.to< std::string >(), val.to< std::string >() );
158 const std::string& name ( property.name() );
159 const ::camp::Value& val ( property.get( m_campDataObj ) );
162 if( val.type() != camp::intType )
165 ::fwAtoms::Base::sptr atom = val.visit( visitor );
166 m_atomObj->setAttribute( name, atom );
171 m_atomObj->setAttribute( name, atom );
179 const std::string& name ( property.name() );
180 const ::camp::Value& val ( property.get( m_campDataObj ) );
183 ::fwAtoms::Base::sptr atom = val.visit( visitor );
184 m_atomObj->setAttribute( name, atom );
191 const std::string name ( property.name() );
192 ::fwAtoms::Map::sptr atom = ::fwAtoms::Map::New();
194 std::pair< ::camp::Value, ::camp::Value > value;
195 ::fwAtoms::Base::sptr valAtom;
197 ::camp::Value second;
199 const size_t size =
property.getSize( m_campDataObj );
200 for (
size_t index = 0; index < size; ++index)
202 value =
property.getElement(m_campDataObj, index);
205 second = value.second;
208 valAtom = second.visit( valVisitor );
210 FW_RAISE_EXCEPTION_IF(
212 first.type() != ::camp::stringType &&
213 first.type() != ::camp::intType &&
214 first.type() != ::camp::realType );
215 atom->insert( first.to< std::string >(), valAtom );
218 m_atomObj->setAttribute( name, atom );
225 const std::string name ( property.name() );
226 ::fwAtoms::Sequence::sptr atom = ::fwAtoms::Sequence::New();
229 ::fwAtoms::Base::sptr valAtom;
230 const size_t size =
property.size( m_campDataObj );
231 for (
size_t index = 0; index < size; ++index)
233 val =
property.get( m_campDataObj, index );
236 valAtom = val.visit( visitor );
237 atom->push_back( valAtom );
240 m_atomObj->setAttribute( name, atom );
247 const std::string& name ( property.name() );
248 const ::camp::Value& val ( property.get( m_campDataObj ) );
251 ::fwAtoms::Base::sptr atom = val.visit( visitor );
252 m_atomObj->setAttribute( name, atom );
260 return this->m_atomObj;
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...
FWATOMCONVERSION_API std::shared_ptr< ::fwAtoms::Object > getAtomObject() const
Returns the atom object (representation of dataObj in fwAtoms) . Calls this methods after the visit...
static FWATOMCONVERSION_API const std::string CLASSNAME_METAINFO
Key of the meta info to store data object classname.
static FWATOMCONVERSION_API const std::string ID_METAINFO
Key of the meta info to store data object ID.
static Numeric::sptr New(T value)
Build a new numeric type.
Base class for each data object.
virtual FWATOMCONVERSION_API ~DataVisitor()
Destructor. Does nothing.
Define Base class for FW4SPL buffers.
FWATOMCONVERSION_API DataVisitor(std::shared_ptr< ::fwData::Object >dataObj, AtomCacheType &cache)
Constructor. Initializes atom object and store it in the cache.
FWATOMCONVERSION_API void visit(const camp::SimpleProperty &property)
Visit simple property.
static FWATOMS_API Blob::sptr New(::fwMemory::BufferObject::sptr buffer)
create a new Blob shared ptr.