hpp-constraints  4.12.0
Definition of basic geometric constraints for motion planning
comparison-types.hh
Go to the documentation of this file.
1 // Copyright (c) 2020 CNRS, Airbus SAS
2 // Author: Florent Lamiraux
3 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr), Florent Lamiraux
4 //
5 // This file is part of hpp-constraints.
6 // hpp-constraints is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-constraints is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-constraints. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HPP_CONSTRAINTS_COMOARISON_TYPES_HH
19 #define HPP_CONSTRAINTS_COMOARISON_TYPES_HH
20 
21 #include <iostream>
22 #include <vector>
23 #include <hpp/constraints/fwd.hh>
24 
25 namespace hpp {
26  namespace constraints {
27  namespace internal {
29  struct ReplicateCompType {
30  ComparisonType type;
31  std::size_t n;
32 
33  void push_to(ComparisonTypes_t& v) const
34  {
35  for (std::size_t i = 0; i < n; ++i) v.push_back(type);
36  }
37  // Cast to ComparisonTypes_t
38  operator ComparisonTypes_t() const
39  {
40  return ComparisonTypes_t(n, type);
41  }
42  }; // struct ReplicateCompType
44  }
45  inline internal::ReplicateCompType operator*(const int& n,
46  const ComparisonType& c)
47  {
48  internal::ReplicateCompType cts;
49  cts.type = c;
50  cts.n = (std::size_t)n;
51  return cts;
52  }
53 
55  const ComparisonType& b)
56  {
57  ComparisonTypes_t v(2);
58  v[0]=a;
59  v[1]=b;
60  return v;
61  }
62 
63  inline ComparisonTypes_t operator<<(const internal::ReplicateCompType& a,
64  const ComparisonType& b)
65  {
67  v.reserve(a.n+1);
68  a.push_to(v);
69  v.push_back(b);
70  return v;
71  }
72 
74  const internal::ReplicateCompType& b)
75  {
77  v.reserve(b.n+1);
78  v.push_back(a);
79  b.push_to(v);
80  return v;
81  }
82 
84  const ComparisonType& c)
85  {
86  v.push_back(c);
87  return v;
88  }
89 
91  const internal::ReplicateCompType& c)
92  {
93  for (std::size_t i = 0; i < c.n; ++i) v.push_back(c.type);
94  return v;
95  }
96 
98  const ComparisonType& c)
99  {
101  vv.reserve(v.size()+1);
102  vv.insert(vv.end(), v.begin(), v.end());
103  vv.push_back(c);
104  return vv;
105  }
106 
108  const internal::ReplicateCompType& c)
109  {
111  vv.reserve(v.size()+c.n);
112  vv.insert(vv.end(), v.begin(), v.end());
113  for (std::size_t i = 0; i < c.n; ++i) vv.push_back(c.type);
114  return vv;
115  }
116 
117  inline bool operator==(const ComparisonTypes_t& v,
118  const internal::ReplicateCompType& r)
119  {
120  if (v.size() != r.n) return false;
121  for (std::size_t i=0; i<v.size(); ++i)
122  {
123  if (v[i] != r.type) return false;
124  }
125  return true;
126  }
127 
128  inline std::ostream& operator<<(std::ostream& os,
129  const ComparisonTypes_t& comp)
130  {
131  os << "(";
132  for (ComparisonTypes_t::const_iterator it=comp.begin();
133  it!=comp.end(); ++it)
134  {
135  if (*it == Equality) {
136  os << "Equality";
137  } else if (*it == EqualToZero) {
138  os << "EqualToZero";
139  } else if (*it == Superior) {
140  os << "Superior";
141  } else if (*it == Inferior) {
142  os << "Inferior";
143  } else {
144  assert("false && ComparisonType out of range.");
145  }
146  if(it+1 != comp.end())
147  os << ", ";
148  }
149  os << ")";
150  return os;
151  }
152  } // namespace constraints
153 } // namespace hpp
154 
155 inline hpp::constraints::ComparisonTypes_t operator<<
156 (hpp::constraints::internal::ReplicateCompType c1,
157  hpp::constraints::internal::ReplicateCompType c2)
158 {
160  for (std::size_t i = 0; i < c2.n; ++i) vv.push_back(c2.type);
161  return vv;
162 }
163 
164 
165 #endif // HPP_CONSTRAINTS_COMOARISON_TYPES_HH
ComparisonType
Definition: fwd.hh:170
Definition: active-set-differentiable-function.hh:24
Definition: fwd.hh:172
Definition: fwd.hh:174
bool operator==(const ComparisonTypes_t &v, const internal::ReplicateCompType &r)
Definition: comparison-types.hh:117
Definition: fwd.hh:173
std::vector< ComparisonType > ComparisonTypes_t
Definition: fwd.hh:176
assert(d.lhs()._blocks()==d.rhs()._blocks())
Definition: fwd.hh:171
ComparisonTypes_t operator<<(const ComparisonType &a, const ComparisonType &b)
Definition: comparison-types.hh:54
internal::ReplicateCompType operator*(const int &n, const ComparisonType &c)
Definition: comparison-types.hh:45