Fawkes API  Fawkes Development Version
static_list_node_constraint.cpp
1 /***************************************************************************
2  * static_list_node_constraint.cpp - node constraint that holds a static
3  * of nodes to block
4  *
5  * Created: Sun Mar 02 10:47:35 2014
6  * Copyright 2014 Sebastian Reuter
7  * 2014 Tim Niemueller
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
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 file in the doc directory.
21  */
22 
23 #include <navgraph/constraints/static_list_node_constraint.h>
24 
25 #include <algorithm>
26 
27 namespace fawkes{
28 #if 0 /* just to make Emacs auto-indent happy */
29 }
30 #endif
31 
32 /** @class NavGraphStaticListNodeConstraint <navgraph/constraints/static_list_node_constraint.h>
33  * Constraint that holds a list of nodes to block.
34  * @author Sebastian Reuter
35  */
36 
37 
38 /** Constructor.
39  * @param name name of node constraint
40  */
43 {
44  modified_ = false;
45 }
46 
47 
48 
49 /** Constructor.
50  * @param name name of node constraint
51  * @param node_list list of nodes to block
52  */
54  std::string name,
55  std::vector<fawkes::NavGraphNode> &node_list)
57 {
59  modified_ = false;
60 }
61 
62 /** Virtual empty destructor. */
64 {
65 }
66 
67 
68 bool
70 {
71  if (modified_) {
72  modified_ = false;
73  return true;
74  } else {
75  return false;
76  }
77 }
78 
79 
80 /** Add a single node to constraint list.
81  * @param node node to add to constraint list
82  */
83 void
85 {
86  if (! has_node(node)) {
87  modified_ = true;
88  node_list_.push_back(node);
89  }
90 }
91 
92 /** Add multiple nodes to constraint list.
93  * @param nodes nodes to add to constraint list
94  */
95 void
97  const std::vector<fawkes::NavGraphNode> &nodes)
98 {
99  for (const NavGraphNode &n : nodes) {
100  add_node(n);
101  }
102 }
103 
104 /** Remove a single node from the constraint list.
105  * @param node node to remote
106  */
107 void
109 {
110  std::vector<NavGraphNode>::iterator n =
111  std::find(node_list_.begin(), node_list_.end(), node);
112  if (n != node_list_.end()) {
113  modified_ = true;
114  node_list_.erase(n);
115  }
116 }
117 
118 /** Check if constraint has a specific node.
119  * @param node node to check
120  * @return true if node is in list, false otherwise
121  */
122 bool
124 {
125  return (std::find(node_list_.begin(), node_list_.end(), node) != node_list_.end());
126 }
127 
128 
129 /** Get list of blocked nodes.
130  * @return list of blocked nodes
131  */
132 const std::vector<fawkes::NavGraphNode> &
134 {
135  return node_list_;
136 }
137 
138 
139 /** Remove all nodes. */
140 void
142 {
143  if (! node_list_.empty()) {
144  modified_ = true;
145  node_list_.clear();
146  }
147 }
148 
149 
150 } // end of namespace fawkes
Fawkes library namespace.
std::string name()
Get name of constraint.
void add_node(const fawkes::NavGraphNode &node)
Add a single node to constraint list.
std::vector< fawkes::NavGraphNode > node_list_
Node list.
void remove_node(const fawkes::NavGraphNode &node)
Remove a single node from the constraint list.
const std::vector< fawkes::NavGraphNode > & node_list() const
Get list of blocked nodes.
bool has_node(const fawkes::NavGraphNode &node)
Check if constraint has a specific node.
void add_nodes(const std::vector< fawkes::NavGraphNode > &nodes)
Add multiple nodes to constraint list.
Topological graph node.
Definition: navgraph_node.h:38
NavGraphStaticListNodeConstraint(std::string name)
Constructor.
bool modified_
Set to true if changes are made to the constraint.
Constraint that can be queried to check if a node is blocked.
virtual ~NavGraphStaticListNodeConstraint()
Virtual empty destructor.
virtual bool compute(void)
Perform compuations before graph search and to indicate re-planning.