GCC Code Coverage Report


Directory: ./
File: include/hpp/core/constraint.hh
Date: 2024-08-10 11:29:48
Exec Total Coverage
Lines: 5 9 55.6%
Branches: 0 0 -%

Line Branch Exec Source
1 //
2 // Copyright (c) 2014 CNRS
3 // Authors: 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_CORE_CONSTRAINT_HH
31 #define HPP_CORE_CONSTRAINT_HH
32
33 #include <hpp/core/config.hh>
34 #include <hpp/core/fwd.hh>
35 #include <hpp/util/serialization-fwd.hh>
36 #include <ostream>
37
38 namespace hpp {
39 namespace core {
40 /// \addtogroup constraints
41 /// \{
42
43 /// Constraint applicable to a robot configuration
44 ///
45 /// Constraint::apply takes as input a configuration and changes it into
46 /// a configuration satisfying the constraint.
47 ///
48 /// User should define impl_compute in derived classes.
49 class HPP_CORE_DLLAPI Constraint {
50 public:
51 /// Function that applies the constraint
52 /// \param configuration initial configuration and result
53 /// \return true if constraint applied successfully, false if failure.
54 bool apply(ConfigurationOut_t configuration);
55 /// Get name of constraint
56 64 const std::string& name() const { return name_; }
57
58 /// Check whether a configuration statisfies the constraint.
59 ///
60 /// \param config the configuration to check
61 virtual bool isSatisfied(ConfigurationIn_t config) = 0;
62
63 /// Check whether a configuration statisfies the constraint.
64 ///
65 /// \param config the configuration to check
66 /// \retval error error expressed as a vector. Size and content depends
67 /// on implementations
68 virtual bool isSatisfied(ConfigurationIn_t config, vector_t& error) = 0;
69
70 /// return shared pointer to copy
71 virtual ConstraintPtr_t copy() const = 0;
72
73 14823510 virtual ~Constraint() {};
74
75 protected:
76 /// User defined implementation of the constraint.
77 virtual bool impl_compute(ConfigurationOut_t configuration) = 0;
78 /// Constructor
79 150 Constraint(const std::string& name) : name_(name), weak_() {}
80 7411863 Constraint(const Constraint& constraint) : name_(constraint.name_), weak_() {}
81 /// Store shared pointer to itself
82 7412013 void init(const ConstraintPtr_t& self) { weak_ = self; }
83
84 private:
85 virtual std::ostream& print(std::ostream& os) const = 0;
86
87 virtual void addLockedJoint(const LockedJointPtr_t&) {}
88
89 std::string name_;
90 ConstraintWkPtr_t weak_;
91 friend class ConstraintSet;
92 friend class constraints::LockedJoint;
93 friend class ConfigProjector;
94 friend std::ostream& operator<<(std::ostream& os, const Constraint&);
95
96 Constraint() {}
97 HPP_SERIALIZABLE();
98 }; // class Constraint
99 inline std::ostream& operator<<(std::ostream& os,
100 const Constraint& constraint) {
101 return constraint.print(os);
102 }
103 /// \}
104 } // namespace core
105 } // namespace hpp
106 #endif // HPP_CORE_CONSTRAINT_HH
107