fw4spl
GetObject.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 __FWDATACAMP_VISITOR_GETOBJECT_HPP__
8 #define __FWDATACAMP_VISITOR_GETOBJECT_HPP__
9 
10 #include <boost/algorithm/string/split.hpp>
11 #include <boost/algorithm/string/classification.hpp>
12 
13 #include <fwCamp/camp/ExtendedClassVisitor.hpp>
14 
15 #include "fwDataCamp/config.hpp"
16 
17 namespace fwDataCamp
18 {
19 
20 namespace visitor
21 {
22 
27 {
31  typedef std::shared_ptr<PathVisitor> sptr;
32  typedef std::vector<std::string> ObjectsNamesType;
40  PathVisitor(const std::string& path)
41  {
42  ::boost::split( m_vectObj, path, ::boost::is_any_of("."));
43  }
44 
48  void merge(PathVisitor::sptr pathVisitor)
49  {
50  const ObjectsNamesType& vectObjFound = pathVisitor->m_vectObjFound;
51  m_vectObjFound.reserve(m_vectObjFound.size() + vectObjFound.size());
52  m_vectObjFound.insert(m_vectObjFound.end(), vectObjFound.begin(), vectObjFound.end());
53  }
54 
56  void addObject(const std::string& objPath)
57  {
58  m_vectObjFound.push_back(objPath);
59  }
60 
62  bool allObjectsFound() const
63  {
64  return m_vectObj == m_vectObjFound;
65  }
66 
67  private:
68 
70  ObjectsNamesType m_vectObj;
71 
73  ObjectsNamesType m_vectObjFound;
74 
75 };
76 
80 class FWDATACAMP_CLASS_API GetObject : public ::camp::ExtendedClassVisitor
81 {
82 
83 public:
84 
91  FWDATACAMP_API GetObject( ::fwData::Object::csptr object, const std::string& subObjPath );
92 
93  FWDATACAMP_API virtual ~GetObject();
94 
98  FWDATACAMP_API void visit(const camp::SimpleProperty& property);
99  FWDATACAMP_API void visit(const camp::EnumProperty& property);
100  FWDATACAMP_API void visit(const camp::UserProperty& property);
101  FWDATACAMP_API void visit(const camp::ArrayProperty& property);
102  FWDATACAMP_API void visit(const camp::Function& function);
103  FWDATACAMP_API virtual void visit(const camp::MapProperty& property);
106  FWDATACAMP_API ::fwData::Object::sptr get();
108 
112  FWDATACAMP_API bool objectsFound() const;
113 
117  PathVisitor::sptr getPathVisitor() const
118  {
119  return m_pathVisitor;
120  }
121 
122 private:
123 
124  /*
125  * @brief Parses m_newSubObjPath, returns the substring until the first dot ( property name, key map or
126  * index array ) and updates m_newSubObjPath.
127  */
128  std::string getNextPropertyName();
129 
131  ::fwData::Object::csptr m_object;
132 
134  const std::string m_subObjPath;
135 
137  std::string m_newSubObjPath;
138 
140  std::string m_propertyName;
141 
143  ::camp::UserObject m_campObj;
144 
146  ::fwData::Object::sptr m_subObject;
147 
148 protected:
149 
151  PathVisitor::sptr m_pathVisitor;
152 
153 };
154 
155 } // namespace visitor
156 
157 } // namespace fwDataCamp
158 
159 #endif // __FWDATACAMP_VISITOR_GETOBJECT_HPP__
160 
void merge(PathVisitor::sptr pathVisitor)
Appends the path elements of the given path visitor.
Definition: GetObject.hpp:48
PathVisitor::sptr getPathVisitor() const
Returns pointer to associated path visitor.
Definition: GetObject.hpp:117
bool allObjectsFound() const
Returns true if all path elements were found during an introspection process.
Definition: GetObject.hpp:62
PathVisitor(const std::string &path)
Constructor.
Definition: GetObject.hpp:40
void addObject(const std::string &objPath)
Appends a path element.
Definition: GetObject.hpp:56
Check if object introspection process mathes a given path.
Definition: GetObject.hpp:26
This namespace contains data object descriptions used for introspection.
PathVisitor::sptr m_pathVisitor
Path visitor.
Definition: GetObject.hpp:151
This class is an helper to introspect a data and find an object (contained into this data) from a nor...
Definition: GetObject.hpp:80