7 #include <fwAtoms/Object.hpp> 9 #include "fwAtomsPatch/exceptions/ImpossibleConversion.hpp" 10 #include "fwAtomsPatch/exceptions/MissingInformation.hpp" 11 #include "fwAtomsPatch/infos/log.hpp" 12 #include "fwAtomsPatch/patcher/IPatcher.hpp" 13 #include "fwAtomsPatch/PatchingManager.hpp" 14 #include "fwAtomsPatch/VersionsGraph.hpp" 15 #include "fwAtomsPatch/VersionsManager.hpp" 35 const std::string& context =
m_object->getMetaInfo(
"context");
36 const std::string& currentVersion =
m_object->getMetaInfo(
"version_name");
38 if(currentVersion == newVersion)
40 OSLM_WARN(
"Trying to patch an object with the same version (" << currentVersion <<
").");
44 FW_RAISE_EXCEPTION_IF(
48 FW_RAISE_EXCEPTION_IF(
50 currentVersion.empty());
53 ::fwAtomsPatch::VersionsGraph::sptr versionsGraph;
57 "There is no way to go from version '" + currentVersion +
"' to version '" +
58 newVersion +
"' for context '" + context +
"'."), !versionsGraph);
61 ::fwAtomsPatch::VersionsGraph::VersionSeriesType series
62 = versionsGraph->shortestPath(currentVersion, newVersion);
65 "There is no way to go from version '" + currentVersion +
"' to version '" +
66 newVersion +
"' for context '" + context +
"'."),
69 ::fwAtomsPatch::VersionsGraph::NodeIDType currentVersionNode = versionsGraph->getNode(currentVersion);
71 ::fwAtomsPatch::patcher::IPatcher::sptr patcher;
72 std::string currentName, targetName;
76 for(::fwAtomsPatch::VersionsGraph::VersionSeriesType::value_type elt : series)
78 ::fwAtomsPatch::VersionsGraph::NodeIDType targetVersionNode = elt;
81 currentName = versionsGraph->getNode(currentVersionNode).getVersionName();
82 targetName = versionsGraph->getNode(targetVersionNode).getVersionName();
85 const ::fwAtomsPatch::LinkDescriptor& link
86 = versionsGraph->getEdge(currentVersionNode, targetVersionNode);
89 patcher = ::fwAtomsPatch::patcher::factory::New(link.getPatcher());
90 OSLM_ASSERT(
"There is no patcher called \"" << link.getPatcher() <<
"\".", patcher);
92 OSLM_TRACE(
"[PATCHING] '" << currentName <<
"' -> '" << targetName <<
"'.");
93 fwAtomsPatchInfoLogMacro(
"Begin patcher '" + link.getPatcher() +
"'");
96 m_object = patcher->transformObject(m_object, context, currentName, targetName);
97 fwAtomsPatchInfoLogMacro(
"End patcher '" + link.getPatcher() +
"'");
99 currentVersionNode = targetVersionNode;
102 m_object->setMetaInfo(
"version_name", newVersion);
std::shared_ptr< ::fwAtoms::Object > m_object
Object that we want to patch.
FWATOMSPATCH_API::fwAtoms::Object::sptr transformTo(const std::string &newVersion)
Transforms the object to the given version.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define OSLM_TRACE(message)
Contains base functionalities used to transform objects from a version to another.
#define OSLM_WARN(message)
FWATOMSPATCH_API ~PatchingManager()
Default destructor.
static std::shared_ptr< VersionsManager > getDefault()
Returns the default instance of VersionsManager.
#define SLM_TRACE(message)
FWATOMSPATCH_API PatchingManager(std::shared_ptr< ::fwAtoms::Object >object)
Default constructor.
Reports an impossible conversion between data objects.