hpp-manipulation  6.0.0
Classes for manipulation planning.
validation.hh
Go to the documentation of this file.
1 // Copyright (c) 2019, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 
29 #ifndef HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH
30 #define HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH
31 
32 #include <hpp/core/validation-report.hh>
34 #include <hpp/manipulation/fwd.hh>
37 #include <string>
38 #include <vector>
39 
40 namespace hpp {
41 namespace manipulation {
42 namespace graph {
45 
51  public:
52  typedef std::vector<std::string> Collision;
53  typedef std::vector<Collision> CollisionList;
54  typedef std::map<std::string, CollisionList> CollisionMap;
55  Validation(const core::ProblemPtr_t& problem) : problem_(problem) {}
56 
57  void clear() {
58  warnings_.clear();
59  errors_.clear();
60  }
61 
62  bool hasWarnings() const { return !warnings_.empty(); }
63 
64  bool hasErrors() const { return !errors_.empty(); }
65 
66  virtual std::ostream& print(std::ostream& os) const;
67 
74  bool validate(const GraphComponentPtr_t& comp);
75 
79  bool validateState(const StatePtr_t& state);
80 
84  bool validateEdge(const EdgePtr_t& edge);
85 
89  bool validateGraph(const GraphPtr_t& graph);
90 
91  CollisionList getCollisionsForNode(const std::string& nodeName) {
92  return collisions_[nodeName];
93  }
94 
95  private:
96  void addWarning(const GraphComponentPtr_t& c, const std::string& w) {
97  warnings_.push_back(Message(c, w));
98  }
99 
100  void addError(const GraphComponentPtr_t& c, const std::string& w) {
101  errors_.push_back(Message(c, w));
102  }
103 
104  void addCollision(const GraphComponentPtr_t& c, const std::string& obj1,
105  const std::string& obj2) {
106  Collision coll = Collision{obj1, obj2};
107  collisions_[c->name()].push_back(coll);
108  }
109 
110  typedef std::pair<GraphComponentPtr_t, std::string> Message;
111  std::vector<Message> warnings_, errors_;
112  CollisionMap collisions_;
113 
114  core::ProblemPtr_t problem_;
115 };
116 
117 inline std::ostream& operator<<(std::ostream& os, const Validation& v) {
118  return v.print(os);
119 }
120 
122 } // namespace graph
123 } // namespace manipulation
124 
125 } // namespace hpp
126 
127 #endif // HPP_MANIPULATION_GRAPH_VALIDATION_REPORT_HH
Definition: validation.hh:50
std::vector< Collision > CollisionList
Definition: validation.hh:53
bool validateGraph(const GraphPtr_t &graph)
bool validateState(const StatePtr_t &state)
CollisionList getCollisionsForNode(const std::string &nodeName)
Definition: validation.hh:91
Validation(const core::ProblemPtr_t &problem)
Definition: validation.hh:55
bool validateEdge(const EdgePtr_t &edge)
void clear()
Definition: validation.hh:57
bool validate(const GraphComponentPtr_t &comp)
std::map< std::string, CollisionList > CollisionMap
Definition: validation.hh:54
std::vector< std::string > Collision
Definition: validation.hh:52
virtual std::ostream & print(std::ostream &os) const
bool hasErrors() const
Definition: validation.hh:64
bool hasWarnings() const
Definition: validation.hh:62
#define HPP_MANIPULATION_DLLAPI
Definition: config.hh:88
std::ostream & operator<<(std::ostream &os, const GraphComponent &graphComp)
shared_ptr< Edge > EdgePtr_t
Definition: fwd.hh:49
shared_ptr< State > StatePtr_t
Definition: fwd.hh:48
shared_ptr< GraphComponent > GraphComponentPtr_t
Definition: fwd.hh:54
shared_ptr< Graph > GraphPtr_t
Definition: fwd.hh:47
shared_ptr< Problem > ProblemPtr_t
Definition: fwd.hh:65
Definition: main.hh:1