MIRA
PropertyTree.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
48 #include <serialization/adapters/std/vector>
49 
50 #ifndef _MIRA_PROPERTYTREE_H_
51 #define _MIRA_PROPERTYTREE_H_
52 
53 namespace mira {
54 
56 
87 {
88 private:
89 
95  struct Node : public PropertyNodeInfo
96  {
97  Node() {}
98  Node(const PropertyNodeInfo& info) : PropertyNodeInfo(info) {}
99 
100  template<typename Reflector>
101  void reflect(Reflector& r)
102  {
104  r.member("Children", children, "");
105  }
106 
107  std::list<Node> children;
108  };
109 
111  void createChildren(Node& node, PropertyNode* pnode)
112  {
113  node.children.clear();
114  foreach(PropertyNode* p, pnode->children())
115  {
116  node.children.push_back(*p);
117  createChildren(node.children.back(),p);
118  }
119  }
120 
122  template <typename PropertyNodeType>
123  void generateChildren(PropertyNodeType* pnode, const Node& node) const
124  {
125  assert(pnode!=NULL);
126  foreach(const Node& c, node.children)
127  {
128  PropertyNodeType* cn = new PropertyNodeType(c);
129  pnode->addChild(cn);
130  generateChildren<PropertyNodeType>(cn, c);
131  }
132  }
133 
134 public:
135 
138 
146  {
147  assert(root!=NULL);
148  mRoot = *root;
149  createChildren(mRoot,root);
150  }
151 
152  template<typename Reflector>
153  void reflect(Reflector& r)
154  {
155  r.member("Root", mRoot, "");
156  }
157 
158 public:
159 
165  return mRoot;
166  }
167 
168 public:
169 
175  template <typename PropertyNodeType>
176  PropertyNodeType* generatePropertyNodes(PropertyNodeType* root = NULL) const
177  {
178  // create property node, if no one was specified to be used
179  if(root==NULL)
180  root = new PropertyNodeType(mRoot);
181 
182  generateChildren<PropertyNodeType>(root, mRoot);
183  return root;
184  }
185 
186 private:
187  Node mRoot;
188 };
189 
191 
192 } // namespace
193 
194 #endif
Abstract base class for all derived property node classes.
Definition: PropertyNode.h:202
Definition: PropertyNode.h:72
Declaration and implementation of the property node hierarchy.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:956
virtual NodeList & children()
Returns a vector with all child property nodes.
Definition: PropertyNode.h:230
void reflect(Reflector &r)
Definition: PropertyTree.h:153
const PropertyNodeInfo & getRootNodeInfo() const
Returns the info for the root node, and therefore allows the user to create a root property node from...
Definition: PropertyTree.h:164
PropertyNodeType * generatePropertyNodes(PropertyNodeType *root=NULL) const
Reconstructs the property nodes from the given tree structure.
Definition: PropertyTree.h:176
PropertyTree(PropertyNode *root)
Constructs a property tree representation from a given property node and all of its child nodes...
Definition: PropertyTree.h:145
PropertyTree()
Creates an empty tree.
Definition: PropertyTree.h:137
Helper class that is able to hold a complete property tree structure.
Definition: PropertyTree.h:86