MarlinMT  0.1.0
marlinmt::ParameterImpl Class Reference

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 >
get () const
 Get the parameter value. More...
 
template<typename T >
get (const T &fallback) const
 Get the parameter value. More...
 
template<typename 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...
 

Detailed Description

ParameterImpl class Abstract internal implementation of a parameter.

Definition at line 39 of file Parameter.h.

Member Typedef Documentation

◆ FromStrFunction

using marlinmt::ParameterImpl::FromStrFunction = std::function<void(ValueType, const std::string &)>
private

Definition at line 247 of file Parameter.h.

◆ ResetFunction

using marlinmt::ParameterImpl::ResetFunction = std::function<void()>
private

Definition at line 248 of file Parameter.h.

◆ StrFunction

using marlinmt::ParameterImpl::StrFunction = std::function<std::string(ValueType)>
private

Definition at line 246 of file Parameter.h.

◆ TypeFunction

using marlinmt::ParameterImpl::TypeFunction = std::function<std::string()>
private

Definition at line 245 of file Parameter.h.

◆ ValidatorFunction

Definition at line 41 of file Parameter.h.

◆ ValueType

using marlinmt::ParameterImpl::ValueType = std::shared_ptr<void>
private

Definition at line 244 of file Parameter.h.

Constructor & Destructor Documentation

◆ ParameterImpl() [1/3]

marlinmt::ParameterImpl::ParameterImpl ( )
delete

◆ ~ParameterImpl()

marlinmt::ParameterImpl::~ParameterImpl ( )
default

◆ ParameterImpl() [2/3]

template<typename T >
marlinmt::ParameterImpl::ParameterImpl ( EParameterType  paramType,
const std::string &  na,
const std::string &  desc,
std::shared_ptr< T >  addr 
)
inline

Constructor.

Parameters
paramTypethe parameter type
nathe parameter name
descthe parameter description
addrthe address of the parameter variable

Definition at line 56 of file Parameter.h.

◆ ParameterImpl() [3/3]

template<typename T >
marlinmt::ParameterImpl::ParameterImpl ( EParameterType  paramType,
const std::string &  na,
const std::string &  desc,
std::shared_ptr< T >  addr,
defVal 
)
inline

Constructor.

Parameters
paramTypethe parameter type
nathe parameter name
descthe parameter description
addrthe address of the parameter variable
defValthe default parameter value

Definition at line 80 of file Parameter.h.

References marlinmt::book::Flags::value().

Member Function Documentation

◆ checkType()

template<typename T >
void marlinmt::ParameterImpl::checkType ( ) const
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.

◆ construct()

template<typename T >
void marlinmt::ParameterImpl::construct ( )
inlineprivate

◆ createValidator()

template<typename T >
ValidatorFunction marlinmt::ParameterImpl::createValidator ( ValidatorFunctionT< T >  validatorT) const
inlineprivate

Construct the validator function.

Definition at line 270 of file Parameter.h.

◆ defaultStr()

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().

◆ description()

const std::string & marlinmt::ParameterImpl::description ( ) const

Get the parameter description.

Definition at line 19 of file Parameter.cc.

References _description.

◆ get() [1/2]

template<typename T >
T marlinmt::ParameterImpl::get ( ) 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.

◆ get() [2/2]

template<typename T >
T marlinmt::ParameterImpl::get ( const T &  fallback) const
inline

Get the parameter value.

The type must match the one on creation. If the parameter is not set, return the fallback value.

Parameters
fallbackthe fallback value if the parameter is not set

Definition at line 217 of file Parameter.h.

◆ getDefault()

template<typename T >
T marlinmt::ParameterImpl::getDefault ( ) const
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.

◆ hasDefault()

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().

◆ isSet()

bool marlinmt::ParameterImpl::isSet ( ) const

Whether the parameter has been set.

Definition at line 25 of file Parameter.cc.

References _isSet.

Referenced by str().

◆ isType()

template<typename T >
bool marlinmt::ParameterImpl::isType ( ) const
inline

Check whether the template parameter matches the internal implementation type.

Definition at line 150 of file Parameter.h.

◆ name()

const std::string & marlinmt::ParameterImpl::name ( ) const

Get the parameter name.

Definition at line 13 of file Parameter.cc.

References _name.

◆ reset()

void marlinmt::ParameterImpl::reset ( )

Reset the parameter value.

Definition at line 68 of file Parameter.cc.

References _isSet, and _resetFunction.

◆ set()

template<typename T >
void marlinmt::ParameterImpl::set ( const T &  val)
inline

Set the parameter value.

Throw if the type is not matching the one on creation

Parameters
valthe parameter value to set

Definition at line 182 of file Parameter.h.

References MARLINMT_THROW.

◆ setValidator()

template<typename T >
void marlinmt::ParameterImpl::setValidator ( ValidatorFunctionT< T >  validator)
inline

Set the parameter validator function.

Parameters
validatorthe user validator function

Definition at line 170 of file Parameter.h.

◆ str() [1/2]

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().

◆ str() [2/2]

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.

◆ type()

EParameterType marlinmt::ParameterImpl::type ( ) const

Get the parameter name.

Definition at line 7 of file Parameter.cc.

References _type.

◆ typeIndex()

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.

◆ typeStr()

std::string marlinmt::ParameterImpl::typeStr ( ) const

Get the parameter type as string.

Definition at line 56 of file Parameter.cc.

References _typeFunction.

Member Data Documentation

◆ _defaultValue

ValueType marlinmt::ParameterImpl::_defaultValue {nullptr}
private

The address to the parameter default value.

Definition at line 300 of file Parameter.h.

Referenced by defaultStr(), and hasDefault().

◆ _description

std::string marlinmt::ParameterImpl::_description {}
private

The parameter description.

Definition at line 284 of file Parameter.h.

Referenced by description().

◆ _fromStrFunction

FromStrFunction marlinmt::ParameterImpl::_fromStrFunction {}
private

Definition at line 290 of file Parameter.h.

Referenced by str().

◆ _isSet

bool marlinmt::ParameterImpl::_isSet {false}
private

Whether the parameter is set.

Definition at line 294 of file Parameter.h.

Referenced by isSet(), reset(), and str().

◆ _name

std::string marlinmt::ParameterImpl::_name {}
private

The parameter name.

Definition at line 282 of file Parameter.h.

Referenced by name().

◆ _resetFunction

ResetFunction marlinmt::ParameterImpl::_resetFunction {}
private

The function resetting the parameter value.

Definition at line 292 of file Parameter.h.

Referenced by reset().

◆ _strFunction

StrFunction marlinmt::ParameterImpl::_strFunction {}
private

The function converting the parameter value to string.

Definition at line 288 of file Parameter.h.

Referenced by defaultStr(), and str().

◆ _type

EParameterType marlinmt::ParameterImpl::_type {}
private

The parameter type.

Definition at line 280 of file Parameter.h.

Referenced by type().

◆ _typeFunction

TypeFunction marlinmt::ParameterImpl::_typeFunction {}
private

The function converting the parameter type to string.

Definition at line 286 of file Parameter.h.

Referenced by typeStr().

◆ _typeIndex

std::type_index marlinmt::ParameterImpl::_typeIndex
private

The type index object of the underlying parameter type.

Definition at line 296 of file Parameter.h.

Referenced by typeIndex().

◆ _validator

ValidatorFunction marlinmt::ParameterImpl::_validator {}
private

The parameter validator function.

Definition at line 302 of file Parameter.h.

◆ _value

ValueType marlinmt::ParameterImpl::_value {nullptr}
private

The address to the parameter value.

Definition at line 298 of file Parameter.h.

Referenced by str().


The documentation for this class was generated from the following files: