fw4spl
ISemanticPatch.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #ifndef __FWATOMSPATCH_ISEMANTICPATCH_HPP__
8 #define __FWATOMSPATCH_ISEMANTICPATCH_HPP__
9 
10 #include "fwAtomsPatch/config.hpp"
11 #include "fwAtomsPatch/helper/Object.hpp"
12 #include "fwAtomsPatch/IPatch.hpp"
13 
14 #include <fwCore/base.hpp>
15 #include <fwCore/mt/types.hpp>
16 
17 #include <string>
18 
19 namespace fwAtoms
20 {
21 class Object;
22 }
23 
24 namespace fwAtomsPatch
25 {
26 
30 class FWATOMSPATCH_CLASS_API ISemanticPatch : public IPatch
31 {
32 
33 public:
36 
38  FWATOMSPATCH_API ISemanticPatch();
39 
41  FWATOMSPATCH_API ISemanticPatch( const ISemanticPatch& cpy );
42 
44  FWATOMSPATCH_API virtual ~ISemanticPatch();
45 
55  FWATOMSPATCH_API virtual void apply(const SPTR(::fwAtoms::Object)& previous,
56  const SPTR(::fwAtoms::Object)& current,
57  ::fwAtomsPatch::IPatch::NewVersionsType& newVersions) override;
58 
63  FWATOMSPATCH_API virtual bool isApplicable(
64  const std::string& context,
65  const std::string& originVersion,
66  const std::string& targetVersion) const;
67 
68 protected:
69 
71  struct Context
72  {
73  std::string m_context;
74  std::string m_originVersion;
75  std::string m_targetVersion;
76 
77  Context(const std::string& context, const std::string& originVersion, const std::string& targetVersion) :
78  m_context(context),
79  m_originVersion(originVersion),
80  m_targetVersion(targetVersion)
81  {
82  }
83 
84  //------------------------------------------------------------------------------
85 
86  bool operator==(const Context& b) const
87  {
88  return m_context == b.m_context
89  && m_originVersion == b.m_originVersion
90  && m_targetVersion == b.m_targetVersion;
91  }
92  };
93 
98  FWATOMSPATCH_API virtual void addContext(const std::string& context,
99  const std::string& originVersion,
100  const std::string& targetVersion);
101 
105  typedef std::vector< Context > ContextVectorType;
108  mutable ::fwCore::mt::ReadWriteMutex m_mutex;
110 
112  ContextVectorType m_contexts;
113 
114 };
115 
116 } //fwAtomsPatch
117 #endif /* __FWATOMSPATCH_ISEMANTICPATCH_HPP__ */
#define SPTR(_cls_)
#define fwCoreNonInstanciableClassDefinitionsMacro(_classinfo_)
Generate common code for Non Instanciable classes (Interfaces, Abstract classes, ...)
fwAtoms contains basic objects to represent any other kind of object
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
Class represented a fwData::Object.
Base class of contextual patches.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
Struct used to store a context and the versions where the patch can be applied.
Base class of all patches.
Definition: IPatch.hpp:27
ContextVectorType m_contexts
Vector used to store the contexts where the patch can be applied.