ifw-core  5.0.0-pre2
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 <core/utils/base/base.hpp>
15 
16 
17 namespace core::utils::param {
18 
19  const std::string NO_VALUE = "__NO__VALUE__";
20 
22  class Parameter {
23  public:
24 
25  Parameter();
26 
28  Parameter(const std::string name,
29  const std::string value,
30  const std::string comment = "");
31 
33  template <class TYPE>
34  Parameter(const std::string name,
35  const TYPE& value,
36  const std::string comment = "") {
37  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
38  SetName(name);
39  SetValue(value);
40  SetComment(comment);
41  }
42 
44  Parameter(const Parameter& source);
45 
46  ~Parameter();
47 
49  Parameter& Clear();
50 
52  Parameter& SetName(const std::string name);
53 
55  Parameter& SetLowLevelName(const std::string name);
56 
58  Parameter& SetMetaName(const std::string name);
59 
61  bool NameDefined(const std::string& name, const bool tolerant = false) const;
62 
64  bool MatchName(const std::string& name_regex) const;
65 
67  const std::string& GetName() const;
68 
70  const std::string& GetLowLevelName() const;
71 
73  const std::string& GetMetaName() const;
74 
76  std::string GetNames() const;
77 
79  Parameter& SetValue(const std::string& value);
80 
82  Parameter& SetValue(const char* value);
83 
85  template <class TYPE>
86  Parameter& SetValue(TYPE value) {
87  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
89  return *this;
90  }
91 
93  const std::string& GetValue() const;
94 
96  bool NoValue() const;
97 
99  template <class TYPE>
100  void GetValue(TYPE& value) const {
101  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
103  //value = boost::l_exical_cast<TYPE>(m_value);
104  }
105 
107  template <class TYPE>
108  TYPE GetValue() const {
109  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
110  TYPE tmp_value;
112  return tmp_value;
113  //return boost::l_exical_cast<TYPE>(m_value);
114  }
115 
118  bool GetValueAsBool() const;
119 
122  int64_t GetValueAsInt() const;
123 
126  int64_t GetValueAsInt64() const;
127 
130  double GetValueAsDouble() const;
131 
133  Parameter& SetComment(const std::string& comment);
134 
136  const std::string& GetComment() const;
137 
139  std::string ToString() const;
140 
142  Parameter& operator = (const Parameter& source);
143 
144  protected:
145  std::string m_name;
146  std::string m_low_level_name;
147  std::string m_meta_name;
148  std::string m_value;
149  std::string m_comment;
150  std::string m_no_value;
151 
152  private:
153  void _Copy(const Parameter& source);
154  };
155 
156 }
157 
158 #endif // !IFW_CORE_UTILS_PARAMETER_HPP_
Class to handle information for one parameter.
Definition: parameter.hpp:22
double GetValueAsDouble() const
Return value as a double. If string representaion of value is not a double, the behaviour is undefine...
Definition: parameter.cpp:193
const std::string & GetComment() const
Get parameter comment.
Definition: parameter.cpp:149
Parameter(const std::string name, const TYPE &value, const std::string comment="")
Constructor settting internal members.
Definition: parameter.hpp:34
TYPE GetValue() const
Get parameter value as its native data type.
Definition: parameter.hpp:108
Parameter & Clear()
Clear the internal members.
Definition: parameter.cpp:41
std::string m_comment
Definition: parameter.hpp:149
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:121
int64_t GetValueAsInt() const
Return value as integer. If string representaion of value is not an integer, the behaviour is undefin...
Definition: parameter.cpp:188
std::string m_low_level_name
Definition: parameter.hpp:146
Parameter & operator=(const Parameter &source)
Copy operator.
Definition: parameter.cpp:35
Parameter & SetComment(const std::string &comment)
Set parameter comment.
Definition: parameter.cpp:172
Parameter & SetMetaName(const std::string name)
Set Meta-data parameter name.
Definition: parameter.cpp:70
Parameter & SetLowLevelName(const std::string name)
Set the low level parameter name.
Definition: parameter.cpp:64
int64_t GetValueAsInt64() const
Return value as 64 bit integer. If string representaion of value is not a 64 bit integer,...
Definition: parameter.cpp:183
std::string m_name
Definition: parameter.hpp:145
const std::string & GetName() const
Return parameter name.
Definition: parameter.cpp:76
bool GetValueAsBool() const
Return value as a boolean. If string representaion of value is not a boolean, the behaviour is undefi...
Definition: parameter.cpp:178
~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:116
const std::string & GetValue() const
Get parameter value as a string.
Definition: parameter.cpp:134
std::string m_no_value
Definition: parameter.hpp:150
const std::string & GetMetaName() const
Return Meta-data parameter name.
Definition: parameter.cpp:86
Parameter & SetValue(TYPE value)
Set parameter value as its native data type.
Definition: parameter.hpp:86
bool NoValue() const
Return true if no value has been set for the parameter.
Definition: parameter.cpp:144
Parameter()
Definition: parameter.cpp:12
std::string m_meta_name
Definition: parameter.hpp:147
Parameter & SetName(const std::string name)
Set parameter name.
Definition: parameter.cpp:58
Parameter & SetValue(const std::string &value)
Set parameter value.
Definition: parameter.cpp:91
std::string ToString() const
Print out parameter.
Definition: parameter.cpp:154
void GetValue(TYPE &value) const
Get parameter value as its native data type.
Definition: parameter.hpp:100
bool NameDefined(const std::string &name, const bool tolerant=false) const
Check if a given name is defined in the object.
Definition: parameter.cpp:97
std::string m_value
Definition: parameter.hpp:148
const std::string & GetLowLevelName() const
Return the low level parameter name.
Definition: parameter.cpp:81
log4cplus::Logger & Logger()
Definition: tools.cpp:18
std::string NbToStr(const TYPE number, const std::string &format="")
Convert the given value to a string representation.
Definition: conversion.hpp:38
void Convert(const std::string &str_value, std::string &native_value)
Handle case: Conversion of std::string to std::string.
Definition: conversion.cpp:51
Definition: parameter.hpp:17
const std::string NO_VALUE
Definition: parameter.hpp:19