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 
29 /** @class NavGraphStaticListNodeConstraint <navgraph/constraints/static_list_node_constraint.h>
30  * Constraint that holds a list of nodes to block.
31  * @author Sebastian Reuter
32  */
33 
34 /** Constructor.
35  * @param name name of node constraint
36  */
39 {
40  modified_ = false;
41 }
42 
43 /** Constructor.
44  * @param name name of node constraint
45  * @param node_list list of nodes to block
46  */
48  std::string name,
49  std::vector<fawkes::NavGraphNode> &node_list)
51 {
53  modified_ = false;
54 }
55 
56 /** Virtual empty destructor. */
58 {
59 }
60 
61 bool
63 {
64  if (modified_) {
65  modified_ = false;
66  return true;
67  } else {
68  return false;
69  }
70 }
71 
72 /** Add a single node to constraint list.
73  * @param node node to add to constraint list
74  */
75 void
77 {
78  if (!has_node(node)) {
79  modified_ = true;
80  node_list_.push_back(node);
81  }
82 }
83 
84 /** Add multiple nodes to constraint list.
85  * @param nodes nodes to add to constraint list
86  */
87 void
88 NavGraphStaticListNodeConstraint::add_nodes(const std::vector<fawkes::NavGraphNode> &nodes)
89 {
90  for (const NavGraphNode &n : nodes) {
91  add_node(n);
92  }
93 }
94 
95 /** Remove a single node from the constraint list.
96  * @param node node to remote
97  */
98 void
100 {
101  std::vector<NavGraphNode>::iterator n = std::find(node_list_.begin(), node_list_.end(), node);
102  if (n != node_list_.end()) {
103  modified_ = true;
104  node_list_.erase(n);
105  }
106 }
107 
108 /** Check if constraint has a specific node.
109  * @param node node to check
110  * @return true if node is in list, false otherwise
111  */
112 bool
114 {
115  return (std::find(node_list_.begin(), node_list_.end(), node) != node_list_.end());
116 }
117 
118 /** Get list of blocked nodes.
119  * @return list of blocked nodes
120  */
121 const std::vector<fawkes::NavGraphNode> &
123 {
124  return node_list_;
125 }
126 
127 /** Remove all nodes. */
128 void
130 {
131  if (!node_list_.empty()) {
132  modified_ = true;
133  node_list_.clear();
134  }
135 }
136 
137 } // end of namespace fawkes
Fawkes library namespace.
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:35
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.