MIRA
GatewayNode.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 #include <set>
29 
30 #include <topomap/TopoMapFwd.h>
31 #include <topomap/GraphElement.h>
32 
33 #include <geometry/Line.h>
34 
35 namespace viros { namespace topomap {
36 using namespace mira;
37 
39 
40 class Gateway
41 {
42 public:
43  Gateway();
44 
45  static GatewayPtr create() {
46  return boost::make_shared<Gateway>();
47  }
48 
49  template<typename Reflector>
50  void reflect(Reflector& r)
51  {
52  r.member("Line", line, "");
53  r.member("Interrupt", interrupt, "");
54  }
55 
56 public:
57 
59  bool interrupt;
60 };
61 
62 class GatewayNode : public AttributedGraphElement, public boost::enable_shared_from_this<GatewayNode>
63 {
64 public:
65  friend class TopoMap;
66 
67  // to be created and destroyed by TopoMap only
68  GatewayNode();
69  ~GatewayNode();
70 
72  return boost::make_shared<GatewayNode>();
73  }
74 
76  return shared_from_this();
77  }
78 
79 public:
80 
81  template<typename Reflector>
82  void reflect(Reflector& r)
83  {
84  r.member("Node", mNode, "");
85  //r.member("Links", mLinks, ""); //TODO: maybe use this?
86  r.member("Gateway", mGateway, "");
87  }
88 
89 public:
90 
91  const std::string getFullName() const;
92 
93  void addLink(LinkPtr link);
94  void removeLink(LinkPtr link);
95 
96  NodePtr getNode() { return mNode; }
97  const NodePtr getNode() const { return mNode; }
98 
99  void setGateway(GatewayPtr gw);
100  GatewayPtr getGateway() { return mGateway; }
101  const GatewayPtr getGateway() const { return mGateway; }
102 
104  GatewayNodePtr getParentGatewayNode();
106  GatewayNodePtr getChildGatewayNode();
107 
108  const LinkSet& links() const { return mLinks; }
109 
110 
111  class OutgoingLinkIterator : public std::iterator<std::forward_iterator_tag, LinkPtr>
112  {
113  public:
115  typedef const value_type& reference;
116  typedef const value_type* pointer;
117 
120  END_ITERATOR
121  };
122  OutgoingLinkIterator(GatewayNodePtr g, SpecialValue v = BEGIN_ITERATOR);
123 
124  public:
125 
126  bool operator==(const OutgoingLinkIterator& other) const;
127  bool operator!=(const OutgoingLinkIterator& other) const;
128 
129  pointer operator->() { return mCurrent.operator->(); }
130  reference operator*() { return mCurrent.operator*(); }
131 
132  // prefix ++operator
134  advance();
135  return *this;
136  }
137 
139  LinkPtr link() { return *mCurrent; }
140 
146  GatewayNodePtr endpoint();
147 
148  private:
149 
150  void advance();
151  void nextValid();
152 
153  private:
154  LinkSet::iterator mCurrent;
155  GatewayNodePtr mGatewayNode;
156  };
157 
160  {
161  public:
162  OutgoingLinks(GatewayNodePtr g) : mGatewayNode(g) {}
163 
166 
167  iterator begin() const { return iterator(mGatewayNode, iterator::BEGIN_ITERATOR); }
168  iterator end() const { return iterator(mGatewayNode, iterator::END_ITERATOR); }
169  private:
170  GatewayNodePtr mGatewayNode;
171  };
172 
174 
175 
176 public:
177 
178  virtual GraphElementPtr findElement(const std::string& predicate);
179 
180 private:
181  friend class Node;
182 
183  NodePtr mNode;
184  LinkSet mLinks;
185 
186  GatewayPtr mGateway;
187 };
188 
189 std::ostream& operator<<(std::ostream& os, const GatewayNode& gatewayNode);
190 
192 
193 } } // namespace
const value_type & reference
Definition: GatewayNode.h:115
static GatewayNodePtr create()
Definition: GatewayNode.h:71
bool interrupt
Definition: GatewayNode.h:59
Definition: GatewayNode.h:40
boost::shared_ptr< Link > LinkPtr
Definition: TopoMapFwd.h:89
LinkPtr value_type
Definition: GatewayNode.h:114
GatewayPtr getGateway()
Definition: GatewayNode.h:100
Line2i line
Definition: GatewayNode.h:58
pointer operator->()
Definition: GatewayNode.h:129
const value_type * pointer
Definition: GatewayNode.h:116
const GatewayPtr getGateway() const
Definition: GatewayNode.h:101
boost::shared_ptr< GatewayNode > GatewayNodePtr
Definition: TopoMapFwd.h:87
void reflect(Reflector &r)
Definition: GatewayNode.h:82
OutgoingLinkIterator & operator++()
Definition: GatewayNode.h:133
const LinkSet & links() const
Definition: GatewayNode.h:108
void reflect(Reflector &r)
Definition: GatewayNode.h:50
Definition: GatewayNode.h:62
Definition: TopoMap.h:36
const NodePtr getNode() const
Definition: GatewayNode.h:97
static GatewayPtr create()
Definition: GatewayNode.h:45
bool operator==(const ImgIteratorBase &a, const ImgIteratorBase &b)
boost::shared_ptr< Gateway > GatewayPtr
Definition: TopoMapFwd.h:86
boost::shared_ptr< GraphElement > GraphElementPtr
Definition: TopoMapFwd.h:80
GatewayNodePtr thisP()
Definition: GatewayNode.h:75
bool operator!=(const ImgIteratorBase &a, const ImgIteratorBase &b)
std::ostream & operator<<(std::ostream &os, const GatewayNode &gatewayNode)
Definition: Node.h:39
NodePtr getNode()
Definition: GatewayNode.h:96
std::set< LinkPtr, shared_ptr_sort< Link > > LinkSet
Definition: TopoMapFwd.h:103
boost::shared_ptr< Node > NodePtr
Definition: TopoMapFwd.h:84
Definition: MetricCostmapTopoMapPlanner.h:45
Forward decls.
reference operator*()
Definition: GatewayNode.h:130
LinkPtr link()
Returns a pointer to the currently iterated link.
Definition: GatewayNode.h:139
OutgoingLinks outgoingLinks()
Definition: GatewayNode.h:173
Definition: GraphElement.h:91