GCC Code Coverage Report


Directory: ./
File: include/hpp/core/parameter.hh
Date: 2024-12-13 16:14:03
Exec Total Coverage
Lines: 4 4 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 //
2 // Copyright 2018 CNRS
3 //
4 // Author: Florent Lamiraux, Joseph Mirabel
5 //
6
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // 1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30
31 #ifndef HPP_CORE_PARAMETER_HH
32 #define HPP_CORE_PARAMETER_HH
33
34 #include <cassert>
35 #include <hpp/core/config.hh>
36 #include <hpp/core/fwd.hh>
37 #include <iostream>
38 #include <string>
39 #include <typeinfo>
40
41 namespace hpp {
42 namespace core {
43 /*
44 class Parameter;
45 class DYNAMIC_GRAPH_DLLAPI EitherType {
46 public:
47 EitherType(const Parameter& value);
48 ~EitherType();
49 operator bool () const;
50 operator unsigned () const;
51 operator int () const;
52 operator float () const;
53 operator double () const;
54 operator std::string () const;
55 operator Vector () const;
56 operator Eigen::MatrixXd () const;
57 operator Eigen::Matrix4d () const;
58 private:
59 const Parameter* value_;
60 };
61 */
62
63 class HPP_CORE_DLLAPI Parameter {
64 public:
65 enum Type {
66 NONE,
67 BOOL,
68 /// as \ref size_type
69 INT,
70 /// as \ref value_type
71 FLOAT,
72 STRING,
73 /// as \ref vector_t
74 VECTOR,
75 /// as \ref matrix_t
76 MATRIX,
77 NB_TYPES
78 };
79 ~Parameter();
80 void deleteValue();
81 explicit Parameter(const bool& value);
82 explicit Parameter(const size_type& value);
83 explicit Parameter(const value_type& value);
84 explicit Parameter(const std::string& value);
85 explicit Parameter(const vector_t& value);
86 explicit Parameter(const matrix_t& value);
87 /// Copy constructor
88 Parameter(const Parameter& value);
89 /// Construct an empty parameter (None)
90 explicit Parameter();
91 // operator assignement
92 Parameter operator=(const Parameter& value);
93 /// Return the type of the value
94 Type type() const;
95
96 /// Return the value as a castable value into the approriate type
97 ///
98 /// For instance,
99 /// \code
100 /// Parameter v1(5.0); // v1 is of type double
101 /// Parameter v2(3); // v2 is of type int
102 /// double x1 = v1.value();
103 /// double x2 = v2.value();
104 /// \endcode
105 /// The first assignment will succeed, while the second one will throw
106 /// an exception.
107 // const EitherType value () const;
108 /// Return the name of the type
109 static std::string typeName(Type type);
110
111 /// Output in a stream
112 HPP_CORE_DLLAPI friend std::ostream& operator<<(std::ostream& os,
113 const Parameter& value);
114
115 public:
116 // friend class EitherType;
117 bool boolValue() const;
118 size_type intValue() const;
119 value_type floatValue() const;
120 std::string stringValue() const;
121 vector_t vectorValue() const;
122 matrix_t matrixValue() const;
123 Type type_;
124
125 const void* const value_;
126 };
127
128 class HPP_CORE_DLLAPI ParameterDescription {
129 public:
130 600 ParameterDescription(Parameter::Type type, std::string name,
131 std::string doc = "",
132 Parameter defaultValue = Parameter())
133
2/4
✓ Branch 2 taken 600 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 600 times.
✗ Branch 6 not taken.
600 : name_(name), doc_(doc), type_(type), defaultValue_(defaultValue) {}
134
135 ParameterDescription() : type_(Parameter::NONE) {}
136
137 600 const std::string& name() const { return name_; }
138 42 const Parameter::Type& type() const { return type_; }
139 const std::string& doc() const { return doc_; }
140 const Parameter& defaultValue() const;
141
142 private:
143 std::string name_;
144 std::string doc_;
145 Parameter::Type type_;
146 Parameter defaultValue_;
147 };
148 } // namespace core
149 } // namespace hpp
150
151 #endif // HPP_CORE_PARAMETER_HH
152