8 #include "fwAtomsPatch/helper/functions.hpp" 9 #include "fwAtomsPatch/infos/log.hpp" 10 #include "fwAtomsPatch/IPatch.hpp" 11 #include "fwAtomsPatch/ISemanticPatch.hpp" 12 #include "fwAtomsPatch/IStructuralPatch.hpp" 13 #include "fwAtomsPatch/patcher/DefaultPatcher.hpp" 14 #include "fwAtomsPatch/patcher/registry/macros.hpp" 15 #include "fwAtomsPatch/SemanticPatchDB.hpp" 16 #include "fwAtomsPatch/StructuralPatchDB.hpp" 17 #include "fwAtomsPatch/types.hpp" 18 #include "fwAtomsPatch/VersionDescriptor.hpp" 19 #include "fwAtomsPatch/VersionsManager.hpp" 21 #include <fwAtoms/Numeric.hpp> 22 #include <fwAtoms/Numeric.hxx> 46 const std::string &context,
47 const std::string ¤tVersion,
48 const std::string &targetVersion)
56 fwAtomsPatchInfoLogMacro(
"Transform from version '" 60 fwAtomsPatchInfoLogMacro(
"Begin structural pass");
67 fwAtomsPatchInfoLogMacro(
"End structural pass");
70 fwAtomsPatchInfoLogMacro(
"Begin contextual pass");
74 fwAtomsPatchInfoLogMacro(
"End contextual pass");
84 CacheType::const_iterator cIt =
m_cache.find(current->getMetaInfo( ::fwAtomsPatch::s_OBJ_ID ));
89 ::fwAtoms::Object::sptr newAtomObject = ::fwAtoms::Object::New();
92 m_cache[current->getMetaInfo( ::fwAtomsPatch::s_OBJ_ID )] = newAtomObject;
96 newAtomObject->setMetaInfo( ::fwAtomsPatch::s_OBJ_ID,
97 current->getMetaInfo( ::fwAtomsPatch::s_OBJ_ID ));
100 newAtomObject->setMetaInfos(current->getMetaInfos());
103 for( ::fwAtoms::Object::AttributesType::value_type elem : current->getAttributes() )
105 ::fwAtoms::Base::sptr obj = this->
processBase(elem.second);
108 newAtomObject->setAttribute(elem.first, obj);
125 CacheType::const_iterator cIt =
m_cache.find(current->getMetaInfo( ::fwAtomsPatch::s_OBJ_ID ));
134 for( ::fwAtoms::Object::AttributesType::value_type elem : current->getAttributes() )
138 if(elem.second->isObject())
140 ::fwAtoms::Object::sptr obj = ::fwAtoms::Object::dynamicCast(elem.second);
155 return m_cache[current->getMetaInfo( ::fwAtomsPatch::s_OBJ_ID )];
163 ::fwAtoms::Base::sptr newBase;
172 ::fwAtoms::Object::sptr obj = ::fwAtoms::Object::dynamicCast(base);
182 else if(base->isSequence())
184 ::fwAtoms::Sequence::sptr seq = ::fwAtoms::Sequence::dynamicCast(base);
187 else if(base->isMapping())
189 ::fwAtoms::Map::sptr map = ::fwAtoms::Map::dynamicCast(base);
192 else if(base->isString())
196 else if(base->isNumeric())
200 else if(base->isBoolean())
204 else if(base->isBlob())
206 ::fwAtoms::Blob::sptr blob = ::fwAtoms::Blob::dynamicCast(base);
218 ::fwAtoms::Map::sptr newMap = ::fwAtoms::Map::New();
222 ::fwAtoms::Base::sptr value;
224 for( ::fwAtoms::Map::MapType::value_type elem : map->getValue() )
229 ::fwAtoms::Base::sptr obj = this->
processBase(value);
232 newMap->insert( key, obj);
243 ::fwAtoms::Sequence::sptr newSeq = ::fwAtoms::Sequence::New();
246 for( ::fwAtoms::Base::sptr elem : seq->getValue() )
248 ::fwAtoms::Base::sptr obj = this->
processBase(elem);
251 newSeq->push_back(obj);
261 ::fwAtoms::Object::sptr previous, ::fwAtoms::Object::sptr current)
268 const std::string&
classname = ::fwAtomsPatch::helper::getClassname(current);
269 const std::string& version = ::fwAtomsPatch::helper::getVersion(current);
271 ::boost::tie(currentInfos,success) =
m_versionsGraph->getLinkedVersion(
273 std::make_pair(classname, version) );
279 classname, version, currentInfos.first, currentInfos.second);
284 fwAtomsPatchInfoLogMacro(
"Apply structural patch to transform '" + classname
285 +
"|" + version +
"' to '" 286 + currentInfos.first +
"|" + currentInfos.second +
"'");
289 fwAtomsPatchInfoLogMacro(
"End structural patch");
293 fwAtomsPatchInfoLogMacro(
"Move object '" + classname +
"|" + version +
"' to '" 294 + currentInfos.first +
"|" + currentInfos.second +
"'");
295 ::fwAtomsPatch::helper::setClassname(current, currentInfos.first);
296 ::fwAtomsPatch::helper::setVersion(current, currentInfos.second);
301 fwAtomsPatchErrorLogMacro(
"No linked version found for object '" + classname
302 +
"' with version '" + version +
"'");
312 ::fwAtoms::Object::sptr previous, ::fwAtoms::Object::sptr current)
321 ::fwAtomsPatch::ISemanticPatch::sptr patch =
322 contextDB->getPatch(
m_context, currentName, targetName,
329 fwAtomsPatchInfoLogMacro(
"Apply contextual patch to transform '" 337 fwAtomsPatchInfoLogMacro(
"End contextual patch");
351 ::fwAtoms::Object::sptr obj = ::fwAtoms::Object::dynamicCast(base);
359 std::string
classname = obj->getMetaInfo(::fwAtomsPatch::s_OBJ_CLASSNAME);
361 if (classname.empty() || versions.find(classname) != versions.end())
FWATOMSPATCH_API DefaultPatcher(::fwAtomsPatch::patcher::IPatcher::Key key)
Constructor.
virtual FWATOMSPATCH_API::fwAtoms::Base::sptr processBase(::fwAtoms::Base::sptr base)
Process atom base.
::fwAtomsPatch::VersionsGraph::sptr m_versionsGraph
Versions graph.
FWATOMSPATCH_API std::string getClassname(const ::fwAtoms::Object::sptr &obj)
Get classname of an object.
virtual FWATOMSPATCH_API::fwAtoms::Object::sptr applyContextualPatch(::fwAtoms::Object::sptr previous,::fwAtoms::Object::sptr current)
Apply contextual patch.
virtual FWATOMSPATCH_API::fwAtoms::Object::sptr processContextualObject(::fwAtoms::Object::sptr current)
Process contextual atom object.
const VersionsType & getVersions() const
Returns versions.
static FWATOMS_API String::sptr New(std::string value)
Construct a new Object represented a string.
NewVersionsType m_newVersions
Map used to store the correspondence between an old object and a new one.
Version descriptor used to identify a version.
#define OSLM_TRACE(message)
Contains base functionalities used to transform objects from a version to another.
::fwAtomsPatch::VersionsGraph::NodeIDType m_currentVersion
Current object version.
virtual FWATOMSPATCH_API::fwAtoms::Map::sptr processMapping(::fwAtoms::Map::sptr map)
Process atom mapping.
std::string m_context
Context where the object is patched.
::fwAtomsPatch::VersionsGraph::NodeIDType m_targetVersion
Target version for current object.
FWATOMSPATCH_API bool isKnown(const ::fwAtoms::Base::sptr &base)
Return true if the object is known in the target version.
::fwAtomsPatch::StructuralPatchDB::sptr getDefault()
Returns default instance.
PassType m_pass
Current type of pass during patching.
virtual FWATOMSPATCH_API ~DefaultPatcher()
Destructor.
std::map< std::string, std::string > VersionsType
VersionIDs used to link type and version.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
static Numeric::sptr New(T value)
Build a new numeric type.
virtual FWATOMSPATCH_API::fwAtoms::Object::sptr processStructuralObject(::fwAtoms::Object::sptr current)
Process structural atom object.
static const std::string & classname()
return object's classname without its namespace, i.e. BaseObject
static std::shared_ptr< VersionsManager > getDefault()
Returns the default instance of VersionsManager.
virtual FWATOMSPATCH_API::fwAtoms::Object::sptr applyStructuralPatch(::fwAtoms::Object::sptr previous,::fwAtoms::Object::sptr current)
Apply structural patch.
virtual FWATOMSPATCH_API::fwAtoms::Object::sptr transformObject(::fwAtoms::Object::sptr object, const std::string &context, const std::string ¤tVersion, const std::string &targetVersion) override
Apply the patch to the specified object.
std::pair< std::string, std::string > VersionIDType
VersionID used to link type and version.
CacheType m_cache
Cache used to store objects which have already been patched (in order to avoid patching the same obje...
virtual FWATOMSPATCH_API::fwAtoms::Sequence::sptr processSequence(::fwAtoms::Sequence::sptr seq)
Process atom sequence.
FWATOMSPATCH_API std::string getVersion(const ::fwAtoms::Object::sptr &obj)
Get version of an object.
::fwAtoms::Object::sptr m_object
Current object being patched.
static FWATOMS_API Boolean::sptr New(std::string value)
Construct an object storing a bool value.
static FWATOMSPATCH_API SemanticPatchDB::sptr getDefault()
Return default instance of SemanticPatchDB.
static FWATOMS_API Blob::sptr New(::fwMemory::BufferObject::sptr buffer)
create a new Blob shared ptr.