ifw-core 6.0.0
Loading...
Searching...
No Matches
parameter.hpp
Go to the documentation of this file.
1
6#ifndef IFW_CORE_UTILS_PARAMETER_HPP_
7#define IFW_CORE_UTILS_PARAMETER_HPP_
8
9#include <string>
10
11#include <boost/lexical_cast.hpp>
12
13#include <ifw/fnd/defs/dataType.hpp>
14
17
18
20
21 const std::string NO_VALUE = "__NO__VALUE__";
22
24 class Parameter {
25 public:
26
27 Parameter();
28
30 Parameter(const std::string name,
31 const std::string value,
32 const std::string comment = "");
33
35 template <class TYPE>
36 Parameter(const std::string name,
37 const TYPE& value,
38 const std::string comment = "") {
39 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
40 SetName(name);
41 SetValue(value);
42 SetComment(comment);
43 }
44
46 Parameter(const Parameter& source);
47
48 ~Parameter();
49
52
54 Parameter& SetName(const std::string name);
55
57 Parameter& SetLowLevelName(const std::string name);
58
60 Parameter& SetMetaName(const std::string name);
61
63 bool NameDefined(const std::string& name, const bool tolerant = false) const;
64
66 bool MatchName(const std::string& name_regex) const;
67
69 const std::string& GetName() const;
70
72 const std::string& GetLowLevelName() const;
73
75 const std::string& GetMetaName() const;
76
78 std::string GetNames() const;
79
81 Parameter& SetValue(const std::string& value,
82 const ifw::fnd::datatype::DataType data_type =
83 ifw::fnd::datatype::DataType::UNSPECIFIED);
84
86 Parameter& SetValue(const char* value,
87 const ifw::fnd::datatype::DataType data_type =
88 ifw::fnd::datatype::DataType::UNSPECIFIED);
89
91 template <class TYPE>
92 Parameter& SetValue(TYPE value) {
93 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
95 return *this;
96 }
97
99 const std::string& GetValue() const;
100
102 ifw::fnd::datatype::DataType GetDataType() const;
103
105 bool NoValue() const;
106
108 template <class TYPE>
109 void GetValue(TYPE& value) const {
110 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
112 //value = boost::l_exical_cast<TYPE>(m_value);
113 }
114
116 template <class TYPE>
117 TYPE GetValue() const {
118 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
119 TYPE tmp_value;
121 return tmp_value;
122 //return boost::l_exical_cast<TYPE>(m_value);
123 }
124
127 bool GetValueAsBool() const;
128
131 int64_t GetValueAsInt() const;
132
135 int64_t GetValueAsInt64() const;
136
139 double GetValueAsDouble() const;
140
142 Parameter& SetComment(const std::string& comment);
143
145 const std::string& GetComment() const;
146
148 std::string ToString() const;
149
151 Parameter& operator = (const Parameter& source);
152
153 protected:
154 std::string m_name;
155 std::string m_low_level_name;
156 std::string m_meta_name;
157 std::string m_value;
158 std::string m_comment;
159 std::string m_no_value;
160
161 ifw::fnd::datatype::DataType m_data_type{ifw::fnd::datatype::DataType::UNSPECIFIED};
162
163 private:
164 void _Copy(const Parameter& source);
165 };
166
167}
168
169#endif // !IFW_CORE_UTILS_PARAMETER_HPP_
Class to handle information for one parameter.
Definition parameter.hpp:24
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:124
const std::string & GetLowLevelName() const
Return the low level parameter name.
Definition parameter.cpp:82
bool NoValue() const
Return true if no value has been set for the parameter.
Definition parameter.cpp:149
Parameter()
Definition parameter.cpp:12
Parameter & SetLowLevelName(const std::string name)
Set the low level parameter name.
Definition parameter.cpp:65
const std::string & GetComment() const
Get parameter comment.
Definition parameter.cpp:154
int64_t GetValueAsInt64() const
Return value as 64 bit integer. If string representaion of value is not a 64 bit integer,...
Definition parameter.cpp:188
Parameter(const std::string name, const TYPE &value, const std::string comment="")
Constructor settting internal members.
Definition parameter.hpp:36
Parameter & SetComment(const std::string &comment)
Set parameter comment.
Definition parameter.cpp:177
ifw::fnd::datatype::DataType m_data_type
Definition parameter.hpp:161
std::string ToString() const
Print out parameter.
Definition parameter.cpp:159
void GetValue(TYPE &value) const
Get parameter value as its native data type.
Definition parameter.hpp:109
Parameter & SetValue(TYPE value)
Set parameter value as its native data type.
Definition parameter.hpp:92
bool NameDefined(const std::string &name, const bool tolerant=false) const
Check if a given name is defined in the object.
Definition parameter.cpp:100
bool GetValueAsBool() const
Return value as a boolean. If string representaion of value is not a boolean, the behaviour is undefi...
Definition parameter.cpp:183
const std::string & GetValue() const
Get parameter value as a string.
Definition parameter.cpp:139
std::string m_meta_name
Definition parameter.hpp:156
TYPE GetValue() const
Get parameter value as its native data type.
Definition parameter.hpp:117
double GetValueAsDouble() const
Return value as a double. If string representaion of value is not a double, the behaviour is undefine...
Definition parameter.cpp:198
std::string m_name
Definition parameter.hpp:154
const std::string & GetMetaName() const
Return Meta-data parameter name.
Definition parameter.cpp:87
std::string m_low_level_name
Definition parameter.hpp:155
ifw::fnd::datatype::DataType GetDataType() const
Return the data type for the parameter, if defined.
Definition parameter.cpp:203
std::string m_comment
Definition parameter.hpp:158
Parameter & SetMetaName(const std::string name)
Set Meta-data parameter name.
Definition parameter.cpp:71
Parameter & SetValue(const std::string &value, const ifw::fnd::datatype::DataType data_type=ifw::fnd::datatype::DataType::UNSPECIFIED)
Set parameter value.
Definition parameter.cpp:92
Parameter & SetName(const std::string name)
Set parameter name.
Definition parameter.cpp:59
~Parameter()
Definition parameter.cpp:31
std::string GetNames() const
Generate a string summarising the three possible names (<name 1>/<name 2>/<name 3>).
Definition parameter.cpp:119
Parameter & Clear()
Clear the internal members.
Definition parameter.cpp:41
std::string m_value
Definition parameter.hpp:157
Parameter & operator=(const Parameter &source)
Copy operator.
Definition parameter.cpp:35
std::string m_no_value
Definition parameter.hpp:159
int64_t GetValueAsInt() const
Return value as integer. If string representaion of value is not an integer, the behaviour is undefin...
Definition parameter.cpp:193
const std::string & GetName() const
Return parameter name.
Definition parameter.cpp:77
log4cplus::Logger & Logger()
Definition tools.cpp:19
void Convert(const std::string &str_value, std::string &native_value)
Handle case: Conversion of std::string to std::string.
Definition conversion.cpp:52
std::string NbToStr(const TYPE number, const std::string &format="")
Convert the given value to a string representation.
Definition conversion.hpp:38
Definition parameter.hpp:19
const std::string NO_VALUE
Definition parameter.hpp:21