MarlinMT
0.1.0
|
ParameterImpl class Abstract internal implementation of a parameter. More...
#include <Parameter.h>
Public Types | |
using | ValidatorFunction = std::any |
Public Member Functions | |
ParameterImpl ()=delete | |
~ParameterImpl ()=default | |
template<typename T > | |
ParameterImpl (EParameterType paramType, const std::string &na, const std::string &desc, std::shared_ptr< T > addr) | |
Constructor. More... | |
template<typename T > | |
ParameterImpl (EParameterType paramType, const std::string &na, const std::string &desc, std::shared_ptr< T > addr, T defVal) | |
Constructor. More... | |
EParameterType | type () const |
Get the parameter name. More... | |
const std::string & | name () const |
Get the parameter name. More... | |
const std::string & | description () const |
Get the parameter description. More... | |
bool | isSet () const |
Whether the parameter has been set. More... | |
bool | hasDefault () const |
Whether the default has been at construct time. More... | |
std::string | str () const |
Get the parameter value as string. More... | |
std::string | defaultStr () const |
Get the default value as string. More... | |
void | str (const std::string &value) |
Set the parameter value from a string. More... | |
std::string | typeStr () const |
Get the parameter type as string. More... | |
const std::type_index & | typeIndex () const |
Get a type index object of the underlying type. More... | |
template<typename T > | |
bool | isType () const |
Check whether the template parameter matches the internal implementation type. More... | |
template<typename T > | |
void | checkType () const |
Throw an exception if the internal type doesn't match the template parameter type. More... | |
template<typename T > | |
void | setValidator (ValidatorFunctionT< T > validator) |
Set the parameter validator function. More... | |
template<typename T > | |
void | set (const T &val) |
Set the parameter value. More... | |
template<typename T > | |
T | get () const |
Get the parameter value. More... | |
template<typename T > | |
T | get (const T &fallback) const |
Get the parameter value. More... | |
template<typename T > | |
T | getDefault () const |
Get the default parameter value if set. More... | |
void | reset () |
Reset the parameter value. More... | |
Private Types | |
using | ValueType = std::shared_ptr< void > |
using | TypeFunction = std::function< std::string()> |
using | StrFunction = std::function< std::string(ValueType)> |
using | FromStrFunction = std::function< void(ValueType, const std::string &)> |
using | ResetFunction = std::function< void()> |
Private Member Functions | |
template<typename T > | |
void | construct () |
Construct the parameter (called from ctor) More... | |
template<typename T > | |
ValidatorFunction | createValidator (ValidatorFunctionT< T > validatorT) const |
Construct the validator function. More... | |
Private Attributes | |
EParameterType | _type {} |
The parameter type. More... | |
std::string | _name {} |
The parameter name. More... | |
std::string | _description {} |
The parameter description. More... | |
TypeFunction | _typeFunction {} |
The function converting the parameter type to string. More... | |
StrFunction | _strFunction {} |
The function converting the parameter value to string. More... | |
FromStrFunction | _fromStrFunction {} |
ResetFunction | _resetFunction {} |
The function resetting the parameter value. More... | |
bool | _isSet {false} |
Whether the parameter is set. More... | |
std::type_index | _typeIndex |
The type index object of the underlying parameter type. More... | |
ValueType | _value {nullptr} |
The address to the parameter value. More... | |
ValueType | _defaultValue {nullptr} |
The address to the parameter default value. More... | |
ValidatorFunction | _validator {} |
The parameter validator function. More... | |
ParameterImpl class Abstract internal implementation of a parameter.
Definition at line 39 of file Parameter.h.
|
private |
Definition at line 247 of file Parameter.h.
|
private |
Definition at line 248 of file Parameter.h.
|
private |
Definition at line 246 of file Parameter.h.
|
private |
Definition at line 245 of file Parameter.h.
using marlinmt::ParameterImpl::ValidatorFunction = std::any |
Definition at line 41 of file Parameter.h.
|
private |
Definition at line 244 of file Parameter.h.
|
delete |
|
default |
|
inline |
Constructor.
paramType | the parameter type |
na | the parameter name |
desc | the parameter description |
addr | the address of the parameter variable |
Definition at line 56 of file Parameter.h.
|
inline |
Constructor.
paramType | the parameter type |
na | the parameter name |
desc | the parameter description |
addr | the address of the parameter variable |
defVal | the default parameter value |
Definition at line 80 of file Parameter.h.
References marlinmt::book::Flags::value().
|
inline |
Throw an exception if the internal type doesn't match the template parameter type.
Definition at line 158 of file Parameter.h.
References MARLINMT_THROW.
|
inlineprivate |
Construct the parameter (called from ctor)
Definition at line 252 of file Parameter.h.
References marlinmt::details::convert< T >::from_string(), MARLINMT_THROW, marlinmt::details::convert< T >::to_string(), and marlinmt::book::Flags::value().
|
inlineprivate |
Construct the validator function.
Definition at line 270 of file Parameter.h.
std::string marlinmt::ParameterImpl::defaultStr | ( | ) | const |
Get the default value as string.
Definition at line 43 of file Parameter.cc.
References _defaultValue, _strFunction, and hasDefault().
const std::string & marlinmt::ParameterImpl::description | ( | ) | const |
|
inline |
Get the parameter value.
The type must match the one on creation. Throw if the parameter is not set
Definition at line 199 of file Parameter.h.
References MARLINMT_THROW.
|
inline |
Get the parameter value.
The type must match the one on creation. If the parameter is not set, return the fallback value.
fallback | the fallback value if the parameter is not set |
Definition at line 217 of file Parameter.h.
|
inline |
Get the default parameter value if set.
Throw if the default value has not been set
Definition at line 231 of file Parameter.h.
References MARLINMT_THROW.
bool marlinmt::ParameterImpl::hasDefault | ( | ) | const |
Whether the default has been at construct time.
Definition at line 31 of file Parameter.cc.
References _defaultValue.
Referenced by defaultStr().
bool marlinmt::ParameterImpl::isSet | ( | ) | const |
Whether the parameter has been set.
Definition at line 25 of file Parameter.cc.
References _isSet.
Referenced by str().
|
inline |
Check whether the template parameter matches the internal implementation type.
Definition at line 150 of file Parameter.h.
const std::string & marlinmt::ParameterImpl::name | ( | ) | const |
void marlinmt::ParameterImpl::reset | ( | ) |
Reset the parameter value.
Definition at line 68 of file Parameter.cc.
References _isSet, and _resetFunction.
|
inline |
Set the parameter value.
Throw if the type is not matching the one on creation
val | the parameter value to set |
Definition at line 182 of file Parameter.h.
References MARLINMT_THROW.
|
inline |
Set the parameter validator function.
validator | the user validator function |
Definition at line 170 of file Parameter.h.
std::string marlinmt::ParameterImpl::str | ( | ) | const |
Get the parameter value as string.
Definition at line 37 of file Parameter.cc.
References _strFunction, _value, and isSet().
void marlinmt::ParameterImpl::str | ( | const std::string & | value | ) |
Set the parameter value from a string.
Definition at line 49 of file Parameter.cc.
References _fromStrFunction, _isSet, and _value.
EParameterType marlinmt::ParameterImpl::type | ( | ) | const |
const std::type_index & marlinmt::ParameterImpl::typeIndex | ( | ) | const |
Get a type index object of the underlying type.
Definition at line 62 of file Parameter.cc.
References _typeIndex.
std::string marlinmt::ParameterImpl::typeStr | ( | ) | const |
Get the parameter type as string.
Definition at line 56 of file Parameter.cc.
References _typeFunction.
|
private |
The address to the parameter default value.
Definition at line 300 of file Parameter.h.
Referenced by defaultStr(), and hasDefault().
|
private |
|
private |
Definition at line 290 of file Parameter.h.
Referenced by str().
|
private |
Whether the parameter is set.
Definition at line 294 of file Parameter.h.
|
private |
|
private |
The function resetting the parameter value.
Definition at line 292 of file Parameter.h.
Referenced by reset().
|
private |
The function converting the parameter value to string.
Definition at line 288 of file Parameter.h.
Referenced by defaultStr(), and str().
|
private |
|
private |
The function converting the parameter type to string.
Definition at line 286 of file Parameter.h.
Referenced by typeStr().
|
private |
The type index object of the underlying parameter type.
Definition at line 296 of file Parameter.h.
Referenced by typeIndex().
|
private |
The parameter validator function.
Definition at line 302 of file Parameter.h.
|
private |
The address to the parameter value.
Definition at line 298 of file Parameter.h.
Referenced by str().