MIRA
Node.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2013,
3  Neuroinformatics and Cognitive Robotics Labs at TU Ilmenau, Germany
4 
5 All rights reserved.
6 
7 Copying, resale, or redistribution, with or without modification, is strictly
8 prohibited.
9 
10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
11 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
12 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
13 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
14 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES,
15 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 */
17 
26 #pragma once
27 
28 
29 #include <serialization/adapters/std/set>
30 #include <serialization/adapters/boost/shared_ptr.hpp>
31 
32 #include <topomap/TopoMapFwd.h>
33 #include <topomap/GraphElement.h>
34 
35 namespace viros { namespace topomap {
36 
38 
39 class Node : public AttributedGraphElement, public boost::enable_shared_from_this<Node>
40 {
41 
42 public:
43  friend class TopoMap;
44 
45  Node();
46  ~Node();
47 
48  static NodePtr create() {
49  return boost::make_shared<Node>();
50  }
51 
53  return shared_from_this();
54  }
55 
56 public:
57 
58  template<typename Reflector>
59  void reflect(Reflector& r)
60  {
62  r.member("Children", mChildren, "");
63  r.member("Parent", mParent, "");
64  r.member("GatewayNodes", mGatewayNodes, "");
65  }
66 
67 public:
68 
69  NodePtr getParent() { return mParent; }
70  const NodePtr getParent() const { return mParent; }
71 
72  bool isLeaf() const { return mChildren.empty(); }
73 
74  const std::string getFullName() const;
75 
76 
77 public:
78 
79  virtual GraphElementPtr findElement(const std::string& predicate);
80 
81 
82 public:
83 
84  virtual AttributePtr getAttributeUntyped(const std::string& name, const mira::Class& clazz, bool inherited=true);
85  virtual void getAllAttributesUntyped(std::map<std::string, AttributePtr>& oAttributes, const mira::Class& clazz, bool inherited=true);
86 
87 
88 public:
89 
90  const NodeSet& getChildNodes() { return mChildren; }
91  const GatewayNodeSet& getGatewayNodes() { return mGatewayNodes; }
92 
93 public:
94 
99  template <typename Visitor>
100  void visitChildNodes(Visitor&& visitor, bool recursively=true)
101  {
102  foreach(auto n, mChildren)
103  {
104  visitor(n);
105  if(recursively)
106  n->visitChildNodes(visitor,recursively);
107  }
108  }
109 
110 protected:
111 
112  void addChildNode(NodePtr node);
113  void addGatewayNode(GatewayNodePtr gatewayNode);
114 
115 private:
116 
118  NodeSet mChildren;
119  NodePtr mParent;
120 
121  GatewayNodeSet mGatewayNodes;
122 };
123 
124 std::ostream& operator<<(std::ostream& os, const Node& node);
125 
127 
128 }} // namespace
void visitChildNodes(Visitor &&visitor, bool recursively=true)
Calls the operator()(NodePtr node) of the given visitor for each child node (by default recursively i...
Definition: Node.h:100
virtual AttributePtr getAttributeUntyped(const std::string &name, const mira::Class &clazz, bool inherited=true)
Returns NULL, if no such attribute exsits.
bool isLeaf() const
Definition: Node.h:72
void addChildNode(NodePtr node)
boost::shared_ptr< GatewayNode > GatewayNodePtr
Definition: TopoMapFwd.h:87
const std::string getFullName() const
const GatewayNodeSet & getGatewayNodes()
Definition: Node.h:91
NodePtr getParent()
Definition: Node.h:69
boost::shared_ptr< Attribute > AttributePtr
Definition: TopoMapFwd.h:73
virtual GraphElementPtr findElement(const std::string &predicate)
std::set< NodePtr, shared_ptr_sort< Node > > NodeSet
Definition: TopoMapFwd.h:101
const NodePtr getParent() const
Definition: Node.h:70
Definition: TopoMap.h:36
static NodePtr create()
Definition: Node.h:48
void addGatewayNode(GatewayNodePtr gatewayNode)
void reflect(Reflector &r)
Definition: Node.h:59
NodePtr thisP()
Definition: Node.h:52
virtual void getAllAttributesUntyped(std::map< std::string, AttributePtr > &oAttributes, const mira::Class &clazz, bool inherited=true)
boost::shared_ptr< GraphElement > GraphElementPtr
Definition: TopoMapFwd.h:80
std::ostream & operator<<(std::ostream &os, const GatewayNode &gatewayNode)
Definition: Node.h:39
boost::shared_ptr< Node > NodePtr
Definition: TopoMapFwd.h:84
Definition: MetricCostmapTopoMapPlanner.h:45
Forward decls.
void reflect(Reflector &r)
Definition: GraphElement.h:101
const NodeSet & getChildNodes()
Definition: Node.h:90
std::set< GatewayNodePtr, shared_ptr_sort< GatewayNode > > GatewayNodeSet
Definition: TopoMapFwd.h:102
Definition: GraphElement.h:91