fw4spl
CompareObjects.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 #pragma once
8 
9 #include "fwDataCamp/config.hpp"
10 
11 #include <fwCamp/camp/ExtendedClassVisitor.hpp>
12 
13 #include <fwCore/Exception.hpp>
14 #include <fwCore/macros.hpp>
15 
16 namespace fwData
17 {
18 class Object;
19 }
20 
21 namespace fwDataCamp
22 {
23 
24 namespace visitor
25 {
26 
30 class FWDATACAMP_CLASS_API CompareObjects : public ::camp::ExtendedClassVisitor
31 {
32 
33 public:
34 
36  typedef std::map< std::string, std::string > PropsMapType;
37 
41  FWDATACAMP_API CompareObjects();
42 
43  FWDATACAMP_API virtual ~CompareObjects();
44 
48  FWDATACAMP_API void visit(const camp::SimpleProperty& property);
49  FWDATACAMP_API void visit(const camp::EnumProperty& property);
50  FWDATACAMP_API void visit(const camp::UserProperty& property);
51  FWDATACAMP_API void visit(const camp::ArrayProperty& property);
52  FWDATACAMP_API void visit(const camp::Function& function);
53  FWDATACAMP_API virtual void visit(const camp::MapProperty& property);
56  SPTR(::fwData::Object) getReferenceObject() const
58  {
59  return m_objRef;
60  }
61 
63  SPTR(::fwData::Object) getComparedObject() const
64  {
65  return m_objComp;
66  }
67 
69  const PropsMapType& getReferenceProps() const
70  {
71  return m_propsRef;
72  }
73 
75  const PropsMapType& getComparedProps() const
76  {
77  return m_propsComp;
78  }
79 
86  SPTR(PropsMapType) getDifferences() const
87  {
88  return m_props;
89  }
90 
103  FWDATACAMP_API void compare(SPTR(::fwData::Object) objRef,
104  SPTR(::fwData::Object) objComp);
105 
107  FWDATACAMP_API static const std::string s_MISSING_PROPERTY;
108 
109 private:
110 
111  friend struct PropertyVisitor;
112 
121  const ::camp::UserObject& obj,
122  const std::string& prefix,
123  SPTR(PropsMapType)props = SPTR(PropsMapType)(new PropsMapType));
124 
126  std::string getPath(const std::string& property) const;
127 
129  PropsMapType m_propsRef;
130 
132  PropsMapType m_propsComp;
133 
135  ::camp::UserObject m_campObj;
136 
138  std::string m_prefix;
139 
141  SPTR(PropsMapType) m_props;
142 
144  SPTR(::fwData::Object) m_objRef;
145 
147  SPTR(::fwData::Object) m_objComp;
148 
149 };
150 
151 } // namespace visitor
152 
153 } // namespace fwDataCamp
#define SPTR(_cls_)
const PropsMapType & getComparedProps() const
Returns compared object properties.
static FWDATACAMP_API const std::string s_MISSING_PROPERTY
Property value for differences map meaning a missing property.
This file defines fwCore base macros.
Visitor used to compare two objects.
const PropsMapType & getReferenceProps() const
Returns reference object properties.
This namespace contains data object descriptions used for introspection.
Base class for each data object.
Contains the representation of the data objects used in the framework.
std::map< std::string, std::string > PropsMapType
Associates property path (within its parent object) to its value.