ifw-core 7.0.0
 
Loading...
Searching...
No Matches
parameter.hpp
Go to the documentation of this file.
1
6
7#ifndef IFW_CORE_UTILS_PARAMETER_HPP_
8#define IFW_CORE_UTILS_PARAMETER_HPP_
9
10#include <string>
11
12#include <boost/lexical_cast.hpp>
13
14#include <ifw/fnd/defs/dataType.hpp>
15
18
19
21
22 const std::string NO_VALUE = "__NO__VALUE__";
23
25 class Parameter {
26 public:
27
28 Parameter();
29
31 Parameter(const std::string name,
32 const std::string value,
33 const std::string comment = "");
34
36 template <class TYPE>
37 Parameter(const std::string name,
38 const TYPE& value,
39 const std::string comment = "") {
40 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
41 SetName(name);
42 SetValue(value);
43 SetComment(comment);
44 }
45
47 Parameter(const Parameter& source);
48
49 ~Parameter();
50
53
55 Parameter& SetName(const std::string name);
56
58 Parameter& SetLowLevelName(const std::string name);
59
61 Parameter& SetMetaName(const std::string name);
62
64 bool NameDefined(const std::string& name, const bool tolerant = false) const;
65
67 bool MatchName(const std::string& name_regex) const;
68
70 const std::string& GetName() const;
71
73 const std::string& GetLowLevelName() const;
74
76 const std::string& GetMetaName() const;
77
79 std::string GetNames() const;
80
82 Parameter& SetValue(const std::string& value,
83 const ifw::fnd::datatype::DataType data_type =
84 ifw::fnd::datatype::DataType::UNSPECIFIED);
85
87 Parameter& SetValue(const char* value,
88 const ifw::fnd::datatype::DataType data_type =
89 ifw::fnd::datatype::DataType::UNSPECIFIED);
90
92 template <class TYPE>
93 Parameter& SetValue(TYPE value) {
94 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
96 return *this;
97 }
98
100 const std::string& GetValue() const;
101
103 ifw::fnd::datatype::DataType GetDataType() const;
104
106 bool NoValue() const;
107
109 template <class TYPE>
110 void GetValue(TYPE& value) const {
111 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
113 //value = boost::l_exical_cast<TYPE>(m_value);
114 }
115
117 template <class TYPE>
118 TYPE GetValue() const {
119 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
120 TYPE tmp_value;
122 return tmp_value;
123 //return boost::l_exical_cast<TYPE>(m_value);
124 }
125
128 bool GetValueAsBool() const;
129
132 int64_t GetValueAsInt() const;
133
136 int64_t GetValueAsInt64() const;
137
140 double GetValueAsDouble() const;
141
143 Parameter& SetComment(const std::string& comment);
144
146 const std::string& GetComment() const;
147
149 std::string ToString() const;
150
152 Parameter& operator = (const Parameter& source);
153
154 protected:
155 std::string m_name;
156 std::string m_low_level_name;
157 std::string m_meta_name;
158 std::string m_value;
159 std::string m_comment;
160 std::string m_no_value;
161
162 ifw::fnd::datatype::DataType m_data_type{ifw::fnd::datatype::DataType::UNSPECIFIED};
163
164 private:
165 void _Copy(const Parameter& source);
166 };
167
168}
169
170#endif // !IFW_CORE_UTILS_PARAMETER_HPP_
Class to handle information for one parameter.
Definition parameter.hpp:25
bool MatchName(const std::string &name_regex) const
Check if a given name is defined in the object; name specified as a regex.
Definition parameter.cpp:125
const std::string & GetLowLevelName() const
Return the low level parameter name.
Definition parameter.cpp:83
bool NoValue() const
Return true if no value has been set for the parameter.
Definition parameter.cpp:150
Parameter()
Definition parameter.cpp:13
Parameter & SetLowLevelName(const std::string name)
Set the low level parameter name.
Definition parameter.cpp:66
const std::string & GetComment() const
Get parameter comment.
Definition parameter.cpp:155
int64_t GetValueAsInt64() const
Return value as 64 bit integer. If string representaion of value is not a 64 bit integer,...
Definition parameter.cpp:189
Parameter(const std::string name, const TYPE &value, const std::string comment="")
Constructor settting internal members.
Definition parameter.hpp:37
Parameter & SetComment(const std::string &comment)
Set parameter comment.
Definition parameter.cpp:178
ifw::fnd::datatype::DataType m_data_type
Definition parameter.hpp:162
std::string ToString() const
Print out parameter.
Definition parameter.cpp:160
void GetValue(TYPE &value) const
Get parameter value as its native data type.
Definition parameter.hpp:110
Parameter & SetValue(TYPE value)
Set parameter value as its native data type.
Definition parameter.hpp:93
bool NameDefined(const std::string &name, const bool tolerant=false) const
Check if a given name is defined in the object.
Definition parameter.cpp:101
bool GetValueAsBool() const
Return value as a boolean. If string representaion of value is not a boolean, the behaviour is undefi...
Definition parameter.cpp:184
const std::string & GetValue() const
Get parameter value as a string.
Definition parameter.cpp:140
std::string m_meta_name
Definition parameter.hpp:157
TYPE GetValue() const
Get parameter value as its native data type.
Definition parameter.hpp:118
double GetValueAsDouble() const
Return value as a double. If string representaion of value is not a double, the behaviour is undefine...
Definition parameter.cpp:199
std::string m_name
Definition parameter.hpp:155
const std::string & GetMetaName() const
Return Meta-data parameter name.
Definition parameter.cpp:88
std::string m_low_level_name
Definition parameter.hpp:156
ifw::fnd::datatype::DataType GetDataType() const
Return the data type for the parameter, if defined.
Definition parameter.cpp:204
std::string m_comment
Definition parameter.hpp:159
Parameter & SetMetaName(const std::string name)
Set Meta-data parameter name.
Definition parameter.cpp:72
Parameter & SetValue(const std::string &value, const ifw::fnd::datatype::DataType data_type=ifw::fnd::datatype::DataType::UNSPECIFIED)
Set parameter value.
Definition parameter.cpp:93
Parameter & SetName(const std::string name)
Set parameter name.
Definition parameter.cpp:60
~Parameter()
Definition parameter.cpp:32
std::string GetNames() const
Generate a string summarising the three possible names (<name 1>/<name 2>/<name 3>).
Definition parameter.cpp:120
Parameter & Clear()
Clear the internal members.
Definition parameter.cpp:42
std::string m_value
Definition parameter.hpp:158
Parameter & operator=(const Parameter &source)
Copy operator.
Definition parameter.cpp:36
std::string m_no_value
Definition parameter.hpp:160
int64_t GetValueAsInt() const
Return value as integer. If string representaion of value is not an integer, the behaviour is undefin...
Definition parameter.cpp:194
const std::string & GetName() const
Return parameter name.
Definition parameter.cpp:78
log4cplus::Logger & Logger()
Definition tools.cpp:20
void Convert(const std::string &str_value, std::string &native_value)
Handle case: Conversion of std::string to std::string.
Definition conversion.cpp:53
std::string NbToStr(const TYPE number, const std::string &format="")
Convert the given value to a string representation.
Definition conversion.hpp:39
Definition parameter.hpp:20
const std::string NO_VALUE
Definition parameter.hpp:22