7 #include <fwData/Object.hpp> 9 #include "fwAtomConversion/AtomVisitor.hpp" 10 #include "fwAtomConversion/DataVisitor.hpp" 11 #include "fwAtomConversion/AtomToDataMappingVisitor.hpp" 12 #include "fwAtomConversion/exception/DataFactoryNotFound.hpp" 13 #include "fwAtomConversion/exception/DuplicatedDataUUID.hpp" 14 #include "fwAtomConversion/exception/ClassnameMismatch.hpp" 19 ::fwData::Object::sptr AtomVisitor::ReusePolicy::operator()(
const std::string &uuid,
const std::string &classname)
const 21 ::fwData::Object::sptr obj = ::fwData::Object::dynamicCast(::
fwTools::UUID::get(uuid));
23 FW_RAISE_EXCEPTION_IF(
24 exception::ClassnameMismatch(
"Loaded object classname (" + classname
25 +
") for UUID '" + uuid
26 +
"' does not match existing classname (" + obj->classname() +
")" ),
27 classname != obj->getClassname());
31 ::fwData::Object::sptr obj = ::fwData::factory::New(classname);
34 FW_RAISE_EXCEPTION_IF(
35 exception::DataFactoryNotFound(
36 std::string(
"Unable to build '") + classname +
"': the data factory may be missing.")
41 OSLM_ASSERT(
"UUID '" << uuid <<
"' should not exist", uuidIsSet );
47 ::fwData::Object::sptr AtomVisitor::ChangePolicy::operator()(
const std::string &uuid,
48 const std::string &classname)
const 50 ::fwData::Object::sptr obj = ::fwData::factory::New(classname);
53 FW_RAISE_EXCEPTION_IF(
54 exception::DataFactoryNotFound(
55 std::string(
"Unable to build '") + classname +
"': the data factory may be missing.")
63 ::fwData::Object::sptr AtomVisitor::StrictPolicy::operator()(
const std::string &uuid,
64 const std::string &classname)
const 67 ::fwData::Object::sptr obj = ::fwData::factory::New(classname);
69 FW_RAISE_EXCEPTION_IF(
70 exception::DataFactoryNotFound(
71 std::string(
"Unable to build '") + classname +
"': the data factory may be missing.")
77 FW_RAISE_EXCEPTION_IF(
78 exception::DuplicatedDataUUID(
79 std::string(
"Try to create new data object '") + classname +
"' with uuid '" 80 + uuid +
"' but this uuid is already used." 90 : m_atomObj ( atomObj ),
92 m_uuidPolicy(uuidPolicy)
102 this->processMetaInfos( m_atomObj->getMetaInfos() );
103 this->processAttributes( m_atomObj->getAttributes() );
106 void AtomVisitor::processMetaInfos( const ::fwAtoms::Object::MetaInfosType & metaInfos )
111 m_dataObj = m_uuidPolicy(uuid, classname);
112 m_cache[uuid] = m_dataObj;
115 void AtomVisitor::processAttributes( const ::fwAtoms::Object::AttributesType & attributes )
117 const camp::Class& metaclass = ::camp::classByName( m_dataObj->getClassname() );
119 metaclass.visit(visitor);
FWATOMCONVERSION_API void visit()
Visits the atom information to create the data object and store it in the cache.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
This namespace contains the necessary class for fwData <-> fwAtoms conversion.
Visitor UUID Management policies.
This visitor visits data object to fill it with associated atom object attributes. This class is used by AtomVisitor to convert an fwData::Object.
FWATOMCONVERSION_API std::shared_ptr< ::fwData::Object > getDataObject() const
Returns the data object. Calls this method after 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.
FWATOMCONVERSION_API AtomVisitor(const ::fwAtoms::Object::sptr &atomObj, DataCacheType &cache, const IReadPolicy &uuidPolicy)
Constructors. Initializes parameters.
virtual FWATOMCONVERSION_API ~AtomVisitor()
Destructor. Does nothing.