GCC Code Coverage Report


Directory: ./
File: include/hpp/constraints/comparison-types.hh
Date: 2025-05-05 12:19:30
Exec Total Coverage
Lines: 46 61 75.4%
Branches: 25 64 39.1%

Line Branch Exec Source
1 // Copyright (c) 2020 CNRS, Airbus SAS
2 // Author: Florent Lamiraux
3 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr), Florent Lamiraux
4 //
5
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 // DAMAGE.
29
30 #ifndef HPP_CONSTRAINTS_COMOARISON_TYPES_HH
31 #define HPP_CONSTRAINTS_COMOARISON_TYPES_HH
32
33 #include <hpp/constraints/fwd.hh>
34 #include <iostream>
35 #include <vector>
36
37 namespace hpp {
38 namespace constraints {
39 namespace internal {
40 /// \cond HIDDEN_SYMBOLS
41 struct ReplicateCompType {
42 ComparisonType type;
43 std::size_t n;
44
45 5 void push_to(ComparisonTypes_t& v) const {
46
2/2
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 5 times.
22 for (std::size_t i = 0; i < n; ++i) v.push_back(type);
47 5 }
48 // Cast to ComparisonTypes_t
49
1/2
✓ Branch 2 taken 6418 times.
✗ Branch 3 not taken.
6418 operator ComparisonTypes_t() const { return ComparisonTypes_t(n, type); }
50 }; // struct ReplicateCompType
51 /// \endcond
52 } // namespace internal
53 6434 inline internal::ReplicateCompType operator*(const int& n,
54 const ComparisonType& c) {
55 internal::ReplicateCompType cts;
56 6434 cts.type = c;
57 6434 cts.n = (std::size_t)n;
58 6434 return cts;
59 }
60
61 10 inline ComparisonTypes_t operator<<(const ComparisonType& a,
62 const ComparisonType& b) {
63
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 ComparisonTypes_t v(2);
64 10 v[0] = a;
65 10 v[1] = b;
66 10 return v;
67 }
68
69 1 inline ComparisonTypes_t operator<<(const internal::ReplicateCompType& a,
70 const ComparisonType& b) {
71 1 ComparisonTypes_t v;
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 v.reserve(a.n + 1);
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 a.push_to(v);
74
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 v.push_back(b);
75 1 return v;
76 }
77
78 4 inline ComparisonTypes_t operator<<(const ComparisonType& a,
79 const internal::ReplicateCompType& b) {
80 4 ComparisonTypes_t v;
81
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 v.reserve(b.n + 1);
82
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 v.push_back(a);
83
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 b.push_to(v);
84 4 return v;
85 }
86
87 inline ComparisonTypes_t& operator<<(ComparisonTypes_t& v,
88 const ComparisonType& c) {
89 v.push_back(c);
90 return v;
91 }
92
93 inline ComparisonTypes_t& operator<<(ComparisonTypes_t& v,
94 const internal::ReplicateCompType& c) {
95 for (std::size_t i = 0; i < c.n; ++i) v.push_back(c.type);
96 return v;
97 }
98
99 24 inline ComparisonTypes_t operator<<(const ComparisonTypes_t& v,
100 const ComparisonType& c) {
101 24 ComparisonTypes_t vv;
102
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 vv.reserve(v.size() + 1);
103
1/2
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
24 vv.insert(vv.end(), v.begin(), v.end());
104
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 vv.push_back(c);
105 24 return vv;
106 }
107
108 8 inline ComparisonTypes_t operator<<(const ComparisonTypes_t& v,
109 const internal::ReplicateCompType& c) {
110 8 ComparisonTypes_t vv;
111
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 vv.reserve(v.size() + c.n);
112
1/2
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
8 vv.insert(vv.end(), v.begin(), v.end());
113
3/4
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 8 times.
29 for (std::size_t i = 0; i < c.n; ++i) vv.push_back(c.type);
114 8 return vv;
115 }
116
117 2 inline bool operator==(const ComparisonTypes_t& v,
118 const internal::ReplicateCompType& r) {
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (v.size() != r.n) return false;
120
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
8 for (std::size_t i = 0; i < v.size(); ++i) {
121
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 if (v[i] != r.type) return false;
122 }
123 2 return true;
124 }
125
126 inline std::ostream& operator<<(std::ostream& os,
127 const ComparisonTypes_t& comp) {
128 os << "(";
129 for (ComparisonTypes_t::const_iterator it = comp.begin(); it != comp.end();
130 ++it) {
131 if (*it == Equality) {
132 os << "Equality";
133 } else if (*it == EqualToZero) {
134 os << "EqualToZero";
135 } else if (*it == Superior) {
136 os << "Superior";
137 } else if (*it == Inferior) {
138 os << "Inferior";
139 } else {
140 assert("false && ComparisonType out of range.");
141 }
142 if (it + 1 != comp.end()) os << ", ";
143 }
144 os << ")";
145 return os;
146 }
147 } // namespace constraints
148 } // namespace hpp
149
150 1 inline hpp::constraints::ComparisonTypes_t operator<<(
151 hpp::constraints::internal::ReplicateCompType c1,
152 hpp::constraints::internal::ReplicateCompType c2) {
153 1 hpp::constraints::ComparisonTypes_t vv(c1);
154
3/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
3 for (std::size_t i = 0; i < c2.n; ++i) vv.push_back(c2.type);
155 1 return vv;
156 }
157
158 #endif // HPP_CONSTRAINTS_COMOARISON_TYPES_HH
159