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 
27 /** @class NavGraphNode <navgraph/navgraph_node.h>
28  * Topological graph node.
29  * @author Tim Niemueller
30  */
31 
32 /** Constructor for invalid node. */
33 NavGraphNode::NavGraphNode() : unconnected_(false)
34 {
35 }
36 
37 /** Constructor.
38  * @param name name of the node
39  * @param x x coordinate in global frame of node
40  * @param y y coordinate in global frame of node
41  * @param properties properties for the new node
42  */
43 NavGraphNode::NavGraphNode(const std::string & name,
44  float x,
45  float y,
46  std::map<std::string, std::string> properties)
47 : unconnected_(false)
48 {
49  name_ = name;
50  x_ = x;
51  y_ = y;
52  properties_ = properties;
53 }
54 
55 /** Constructor.
56  * @param name name of the node
57  * @param x x coordinate in global frame of node
58  * @param y y coordinate in global frame of node
59  */
60 NavGraphNode::NavGraphNode(const std::string &name, float x, float y) : unconnected_(false)
61 {
62  name_ = name;
63  x_ = x;
64  y_ = y;
65 }
66 
67 /** Set X position.
68  * @param x X coordinate in global frame for node.
69  */
70 void
71 NavGraphNode::set_x(float x)
72 {
73  x_ = x;
74 }
75 
76 /** Set Y position.
77  * @param y Y coordinate in global frame for node.
78  */
79 void
80 NavGraphNode::set_y(float y)
81 {
82  y_ = y;
83 }
84 
85 /** Set name of node.
86  * @param name new name for node
87  */
88 void
89 NavGraphNode::set_name(const std::string &name)
90 {
91  name_ = name;
92 }
93 
94 /** Set unconnected state of the node.
95  * A node must be marked as unconnected explicitly or otherwise it is an
96  * error that the graph will report as an error. On other hand, unconnected
97  * nodes may not have any connection. By default nodes are expected to
98  * have at least one connection (behaving as though this function had been
99  * called with "false").
100  * @param unconnected true to make this node a unconnected node,
101  * false otherwise
102  */
103 void
104 NavGraphNode::set_unconnected(bool unconnected)
105 {
106  unconnected_ = unconnected;
107 }
108 
109 /** Get specified property as string.
110  * @param prop property key
111  * @return property value as string
112  */
113 std::string
114 NavGraphNode::property(const std::string &prop) const
115 {
116  std::map<std::string, std::string>::const_iterator p;
117  if ((p = properties_.find(prop)) != properties_.end()) {
118  return p->second;
119  } else {
120  return "";
121  }
122 }
123 
124 /** Overwrite properties with given ones.
125  * @param properties map of properties to set
126  */
127 void
128 NavGraphNode::set_properties(const std::map<std::string, std::string> &properties)
129 {
130  properties_ = properties;
131 }
132 
133 /** Set property.
134  * @param property property key
135  * @param value property value
136  */
137 void
138 NavGraphNode::set_property(const std::string &property, const std::string &value)
139 {
140  properties_[property] = value;
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, float value)
149 {
150  properties_[property] = StringConversions::to_string(value);
151 }
152 
153 /** Set property.
154  * @param property property key
155  * @param value property value
156  */
157 void
158 NavGraphNode::set_property(const std::string &property, int value)
159 {
160  properties_[property] = StringConversions::to_string(value);
161 }
162 
163 /** Set property.
164  * @param property property key
165  * @param value property value
166  */
167 void
168 NavGraphNode::set_property(const std::string &property, bool value)
169 {
170  properties_[property] = value ? "true" : "false";
171 }
172 
173 /** Set directly reachable nodes of node.
174  * @param reachable_nodes vector of directly reachable nodes
175  */
176 void
177 NavGraphNode::set_reachable_nodes(std::vector<std::string> reachable_nodes)
178 {
179  reachable_nodes_ = reachable_nodes;
180 }
181 
182 } // end of namespace fawkes
fawkes::NavGraphNode::set_properties
void set_properties(const std::map< std::string, std::string > &properties)
Overwrite properties with given ones.
Definition: navgraph_node.cpp:133
fawkes::NavGraphNode::set_unconnected
void set_unconnected(bool unconnected)
Set unconnected state of the node.
Definition: navgraph_node.cpp:109
fawkes::NavGraphNode::set_property
void set_property(const std::string &property, const std::string &value)
Set property.
Definition: navgraph_node.cpp:143
fawkes::NavGraphNode::set_y
void set_y(float y)
Set Y position.
Definition: navgraph_node.cpp:85
fawkes::NavGraphNode::name
const std::string & name() const
Get name of node.
Definition: navgraph_node.h:60
fawkes::NavGraphNode::properties
const std::map< std::string, std::string > & properties() const
Get all properties.
Definition: navgraph_node.h:117
fawkes::NavGraphNode::property
std::string property(const std::string &prop) const
Get specified property as string.
Definition: navgraph_node.cpp:119
fawkes::StringConversions::to_string
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
Definition: string_conversions.cpp:73
fawkes::NavGraphNode::unconnected
bool unconnected() const
Check if this node shall be unconnected.
Definition: navgraph_node.h:84
fawkes::NavGraphNode::set_name
void set_name(const std::string &name)
Set name of node.
Definition: navgraph_node.cpp:94
fawkes
fawkes::NavGraphNode::reachable_nodes
const std::vector< std::string > & reachable_nodes() const
Get reachable nodes.
Definition: navgraph_node.h:216
fawkes::NavGraphNode::x
float x() const
Get X coordinate in global frame.
Definition: navgraph_node.h:68
fawkes::NavGraphNode::NavGraphNode
NavGraphNode()
Constructor for invalid node.
Definition: navgraph_node.cpp:38
fawkes::NavGraphNode::y
float y() const
Get Y coordinate in global frame.
Definition: navgraph_node.h:76
fawkes::NavGraphNode::set_x
void set_x(float x)
Set X position.
Definition: navgraph_node.cpp:76
fawkes::NavGraphNode::set_reachable_nodes
void set_reachable_nodes(std::vector< std::string > reachable_nodes)
Set directly reachable nodes of node.
Definition: navgraph_node.cpp:182