fw4spl
ISemanticPatch.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <fwAtoms/Object.hpp>
8 
9 #include "fwAtomsPatch/helper/functions.hpp"
10 #include "fwAtomsPatch/ISemanticPatch.hpp"
11 #include "fwAtomsPatch/types.hpp"
12 
13 namespace fwAtomsPatch
14 {
15 
17 {
18 }
19 
20 // ----------------------------------------------------------------------------
21 
23 {
24 }
25 
26 // ----------------------------------------------------------------------------
27 
29 {
32 }
33 
34 // ----------------------------------------------------------------------------
35 
36 void ISemanticPatch::addContext(const std::string& context,
37  const std::string& originVersion,
38  const std::string& targetVersion)
39 {
41  m_contexts.push_back(Context(context, originVersion, targetVersion));
42 }
43 
44 // ----------------------------------------------------------------------------
45 
46 bool ISemanticPatch::isApplicable(const std::string& context,
47  const std::string& originVersion,
48  const std::string& targetVersion) const
49 {
50  Context c(context, originVersion, targetVersion);
52  ContextVectorType::const_iterator it = std::find(m_contexts.begin(), m_contexts.end(), c);
53  return it != m_contexts.end();
54 }
55 
56 // ----------------------------------------------------------------------------
57 
58 void ISemanticPatch::apply(const ::fwAtoms::Object::sptr& previous,
59  const ::fwAtoms::Object::sptr& current,
60  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions)
61 {
62  OSLM_ASSERT("The type of the previous object ("
63  << ::fwAtomsPatch::helper::getClassname(previous) << "does not match"
64  "the required type (" << m_originClassname << ").",
66 
67  OSLM_ASSERT("The version of the previous object (" << ::fwAtomsPatch::helper::getVersion(previous) <<
68  "does not match the required version (" << m_originVersion << ").",
70 }
71 
72 } //fwAtomsPatch
virtual FWATOMSPATCH_API const std::string & getOriginClassname() const
Returns the origin classname of the object.
Definition: IPatch.cpp:32
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
FWATOMSPATCH_API std::string getClassname(const ::fwAtoms::Object::sptr &obj)
Get classname of an object.
virtual FWATOMSPATCH_API ~ISemanticPatch()
Destructor.
mutable::fwCore::mt::ReadWriteMutex m_mutex
Mutex to protect concurrent access for m_contexts.
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
::boost::unique_lock< ReadWriteMutex > WriteLock
Defines a lock of write type for read/write mutex.
std::string m_originClassname
Origin classname of the object.
Definition: IPatch.hpp:64
virtual FWATOMSPATCH_API void addContext(const std::string &context, const std::string &originVersion, const std::string &targetVersion)
Add a context where the patch can be applied.
virtual FWATOMSPATCH_API bool isApplicable(const std::string &context, const std::string &originVersion, const std::string &targetVersion) const
Returns true if patch is applicable into the context from origin to target versions.
std::string m_originVersion
Origin version of the object.
Definition: IPatch.hpp:67
FWATOMSPATCH_API ISemanticPatch()
Constructor.
::boost::shared_lock< ReadWriteMutex > ReadLock
Defines a lock of read type for read/write mutex.
virtual FWATOMSPATCH_API void apply(const std::shared_ptr< ::fwAtoms::Object > &previous, const std::shared_ptr< ::fwAtoms::Object > &current,::fwAtomsPatch::IPatch::NewVersionsType &newVersions) override
Applies modifications between given objects.
Base class of contextual patches.
FWATOMSPATCH_API std::string getVersion(const ::fwAtoms::Object::sptr &obj)
Get version of an object.
Struct used to store a context and the versions where the patch can be applied.
virtual FWATOMSPATCH_API const std::string & getOriginVersion() const
Returns the origin version of the object.
Definition: IPatch.cpp:39
Base class of all patches.
Definition: IPatch.hpp:27
ContextVectorType m_contexts
Vector used to store the contexts where the patch can be applied.