MarlinMT  0.1.0
Parameter.cc
Go to the documentation of this file.
1 // -- marlinmt headers
2 #include <marlinmt/Parameter.h>
4 
5 namespace marlinmt {
6 
8  return _type ;
9  }
10 
11  //--------------------------------------------------------------------------
12 
13  const std::string& ParameterImpl::name() const {
14  return _name ;
15  }
16 
17  //--------------------------------------------------------------------------
18 
19  const std::string& ParameterImpl::description() const {
20  return _description ;
21  }
22 
23  //--------------------------------------------------------------------------
24 
25  bool ParameterImpl::isSet() const {
26  return _isSet ;
27  }
28 
29  //--------------------------------------------------------------------------
30 
32  return (nullptr != _defaultValue) ;
33  }
34 
35  //--------------------------------------------------------------------------
36 
37  std::string ParameterImpl::str() const {
38  return isSet() ? _strFunction( _value ) : "" ;
39  }
40 
41  //--------------------------------------------------------------------------
42 
43  std::string ParameterImpl::defaultStr() const {
44  return hasDefault() ? _strFunction( _defaultValue ) : "" ;
45  }
46 
47  //--------------------------------------------------------------------------
48 
49  void ParameterImpl::str( const std::string &value ) {
50  _fromStrFunction( _value, value ) ;
51  _isSet = true ;
52  }
53 
54  //--------------------------------------------------------------------------
55 
56  std::string ParameterImpl::typeStr() const {
57  return _typeFunction() ;
58  }
59 
60  //--------------------------------------------------------------------------
61 
62  const std::type_index &ParameterImpl::typeIndex() const {
63  return _typeIndex ;
64  }
65 
66  //--------------------------------------------------------------------------
67 
69  _resetFunction() ;
70  _isSet = false ;
71  }
72 
73  //--------------------------------------------------------------------------
74  //--------------------------------------------------------------------------
75 
76 
77  void Configurable::checkParameter( const std::string &name ) const {
78  if( exists( name ) ) {
79  MARLINMT_THROW( "Parameter '" + name + "' already present" ) ;
80  }
81  }
82 
83  //--------------------------------------------------------------------------
84 
85  bool Configurable::exists( const std::string &name ) const {
86  return _parameters.find( name ) != _parameters.end() ;
87  }
88 
89  //--------------------------------------------------------------------------
90 
91  bool Configurable::isSet( const std::string &name ) const {
92  auto iter = _parameters.find( name ) ;
93  if( iter == _parameters.end() ) {
94  return false ;
95  }
96  return iter->second->isSet() ;
97  }
98 
99  //--------------------------------------------------------------------------
100 
102  _parameters.clear() ;
103  }
104 
105  //--------------------------------------------------------------------------
106 
108  std::for_each( begin(), end(), []( auto &p ){ p.second->reset(); } ) ;
109  }
110 
111  //--------------------------------------------------------------------------
112 
114  return _parameters.begin() ;
115  }
116 
117  //--------------------------------------------------------------------------
118 
120  return _parameters.begin() ;
121  }
122 
123  //--------------------------------------------------------------------------
124 
126  return _parameters.end() ;
127  }
128 
129  //--------------------------------------------------------------------------
130 
132  return _parameters.end() ;
133  }
134 
135 }
TypeFunction _typeFunction
The function converting the parameter type to string.
Definition: Parameter.h:286
ParameterMap::const_iterator const_iterator
Definition: Parameter.h:319
void checkParameter(const std::string &name) const
Check if the parameter has been registered.
Definition: Parameter.cc:77
bool hasDefault() const
Whether the default has been at construct time.
Definition: Parameter.cc:31
ParameterMap::iterator iterator
Definition: Parameter.h:318
bool _isSet
Whether the parameter is set.
Definition: Parameter.h:294
EParameterType
EParameterType enumerator Enumerates parameter types supported by Marlin.
Definition: Parameter.h:27
std::string typeStr() const
Get the parameter type as string.
Definition: Parameter.cc:56
bool isSet() const
Whether the parameter has been set.
Definition: Parameter.cc:25
constexpr unsigned long long value(const Flag_t &flag)
Definition: Flags.h:106
std::string _name
The parameter name.
Definition: Parameter.h:282
ValueType _defaultValue
The address to the parameter default value.
Definition: Parameter.h:300
ResetFunction _resetFunction
The function resetting the parameter value.
Definition: Parameter.h:292
#define MARLINMT_THROW(message)
Definition: Exceptions.h:8
std::type_index _typeIndex
The type index object of the underlying parameter type.
Definition: Parameter.h:296
EParameterType _type
The parameter type.
Definition: Parameter.h:280
void reset()
Reset the parameter value.
Definition: Parameter.cc:68
void unset()
Unset all registered parameters.
Definition: Parameter.cc:107
std::string str() const
Get the parameter value as string.
Definition: Parameter.cc:37
const std::string & name() const
Get the parameter name.
Definition: Parameter.cc:13
const std::type_index & typeIndex() const
Get a type index object of the underlying type.
Definition: Parameter.cc:62
const std::string & description() const
Get the parameter description.
Definition: Parameter.cc:19
bool isSet(const std::string &name) const
Returns true if the parameter exists and is set, false otherwise.
Definition: Parameter.cc:91
bool exists(const std::string &name) const
Return true if the parameter has been registered.
Definition: Parameter.cc:85
void clear()
Remove all parameters.
Definition: Parameter.cc:101
FromStrFunction _fromStrFunction
Definition: Parameter.h:290
StrFunction _strFunction
The function converting the parameter value to string.
Definition: Parameter.h:288
EParameterType type() const
Get the parameter name.
Definition: Parameter.cc:7
ValueType _value
The address to the parameter value.
Definition: Parameter.h:298
std::string _description
The parameter description.
Definition: Parameter.h:284
std::string defaultStr() const
Get the default value as string.
Definition: Parameter.cc:43