Fawkes API  Fawkes Development Version
navgraph_node.cpp
1 
2 /***************************************************************************
3  * navgraph_node.cpp - Topological graph node
4  *
5  * Created: Fri Sep 21 16:11:20 2012
6  * Copyright 2012 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21  */
22 
23 #include <navgraph/navgraph_node.h>
24 
25 namespace fawkes {
26 #if 0 /* just to make Emacs auto-indent happy */
27 }
28 #endif
29 
30 /** @class NavGraphNode <navgraph/navgraph_node.h>
31  * Topological graph node.
32  * @author Tim Niemueller
33  */
34 
35 /** Constructor for invalid node. */
37  : unconnected_(false)
38 {
39 }
40 
41 
42 /** Constructor.
43  * @param name name of the node
44  * @param x x coordinate in global frame of node
45  * @param y y coordinate in global frame of node
46  * @param properties properties for the new node
47  */
48 NavGraphNode::NavGraphNode(const std::string &name, float x, float y,
49  std::map<std::string, std::string> properties)
50  : unconnected_(false)
51 {
52  name_ = name;
53  x_ = x;
54  y_ = y;
55  properties_ = properties;
56 }
57 
58 
59 /** Constructor.
60  * @param name name of the node
61  * @param x x coordinate in global frame of node
62  * @param y y coordinate in global frame of node
63  */
64 NavGraphNode::NavGraphNode(const std::string &name, float x, float y)
65  : unconnected_(false)
66 {
67  name_ = name;
68  x_ = x;
69  y_ = y;
70 }
71 
72 
73 /** Set X position.
74  * @param x X coordinate in global frame for node.
75  */
76 void
78 {
79  x_ = x;
80 }
81 
82 /** Set Y position.
83  * @param y Y coordinate in global frame for node.
84  */
85 void
87 {
88  y_ = y;
89 }
90 
91 
92 /** Set name of node.
93  * @param name new name for node
94  */
95 void
96 NavGraphNode::set_name(const std::string &name)
97 {
98  name_ = name;
99 }
100 
101 /** Set unconnected state of the node.
102  * A node must be marked as unconnected explicitly or otherwise it is an
103  * error that the graph will report as an error. On other hand, unconnected
104  * nodes may not have any connection. By default nodes are expected to
105  * have at least one connection (behaving as though this function had been
106  * called with "false").
107  * @param unconnected true to make this node a unconnected node,
108  * false otherwise
109  */
110 void
112 {
113  unconnected_ = unconnected;
114 }
115 
116 
117 /** Get specified property as string.
118  * @param prop property key
119  * @return property value as string
120  */
121 std::string
122 NavGraphNode::property(const std::string &prop) const
123 {
124  std::map<std::string, std::string>::const_iterator p;
125  if ((p = properties_.find(prop)) != properties_.end()) {
126  return p->second;
127  } else {
128  return "";
129  }
130 }
131 
132 
133 /** Overwrite properties with given ones.
134  * @param properties map of properties to set
135  */
136 void
137 NavGraphNode::set_properties(const std::map<std::string, std::string> &properties)
138 {
139  properties_ = properties;
140 }
141 
142 
143 /** Set property.
144  * @param property property key
145  * @param value property value
146  */
147 void
148 NavGraphNode::set_property(const std::string &property, const std::string &value)
149 {
150  properties_[property] = value;
151 }
152 
153 
154 /** Set property.
155  * @param property property key
156  * @param value property value
157  */
158 void
159 NavGraphNode::set_property(const std::string &property, float value)
160 {
161  properties_[property] = StringConversions::to_string(value);
162 }
163 
164 /** Set property.
165  * @param property property key
166  * @param value property value
167  */
168 void
169 NavGraphNode::set_property(const std::string &property, int value)
170 {
171  properties_[property] = StringConversions::to_string(value);
172 }
173 
174 /** Set property.
175  * @param property property key
176  * @param value property value
177  */
178 void
179 NavGraphNode::set_property(const std::string &property, bool value)
180 {
181  properties_[property] = value ? "true" : "false";
182 }
183 
184 
185 /** Set directly reachable nodes of node.
186  * @param reachable_nodes vector of directly reachable nodes
187  */
188 void
190 {
191  reachable_nodes_ = reachable_nodes;
192 }
193 
194 } // end of namespace fawkes
void set_properties(const std::map< std::string, std::string > &properties)
Overwrite properties with given ones.
Fawkes library namespace.
void set_unconnected(bool unconnected)
Set unconnected state of the node.
void set_y(float y)
Set Y position.
std::string property(const std::string &prop) const
Get specified property as string.
const std::map< std::string, std::string > & properties() const
Get all properties.
Definition: navgraph_node.h:88
void set_property(const std::string &property, const std::string &value)
Set property.
const std::string & name() const
Get name of node.
Definition: navgraph_node.h:49
float y() const
Get Y coordinate in global frame.
Definition: navgraph_node.h:59
NavGraphNode()
Constructor for invalid node.
void set_x(float x)
Set X position.
void set_name(const std::string &name)
Set name of node.
bool unconnected() const
Check if this node shall be unconnected.
Definition: navgraph_node.h:64
void set_reachable_nodes(std::vector< std::string > reachable_nodes)
Set directly reachable nodes of node.
float x() const
Get X coordinate in global frame.
Definition: navgraph_node.h:54
const std::vector< std::string > & reachable_nodes() const
Get reachable nodes.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.