ImFusion C++ SDK 4.4.0
ImFusion::Parameter< T > Class Template Reference

#include <ImFusion/Core/Parameter.h>

The Parameter class represents a single parameter of a Configurable entity. More...

Inheritance diagram for ImFusion::Parameter< T >:

Detailed Description

template<typename T>
class ImFusion::Parameter< T >

The Parameter class represents a single parameter of a Configurable entity.

It is intended to be used as member of Configurable classes and enables you to reduce the amount of boilerplate code needed to implement the pair of configure()/configuration() functions for each individual class member that is supposed to be serialized. In order for this to work each Parameter must be registered with the parent Configurable instance. This can be automatized by passing it as additional argument to the corresponding constructor overload. Registration is preserved across copies/moves/assignments, and removed on destruction.

Parameters wrap a regular type T and make it serializable to/from the Properties interface. Since it provides a cast- and assignment operator, it can be used like a variable of type T directly:

Parameter<int> count("count", 0);
int other = count;
count = 5;
Parameter(const std::string &name, U &&value)
Creates a Parameter that will be configured under the given name and with the given initial value.
Definition Parameter.h:201

Any getter access is restricted to const access. To change the parameter you need to explicitly set it. This ensures the signalValueChanged to be emitted whenever the param changes.

By convention, public Parameter members use the p_ prefix for the variable name (instead of the common m_ prefix) in order to make their semantics easier to identify in code.

Template Parameters
TUnderlying type of the parameter, must be supported by Properties::setParam().
See also
SubProperty, SubPropertyList
Examples
ExampleAlgorithm.h, and Serialization.cpp.

Public Member Functions

template<typename U>
 Parameter (const std::string &name, U &&value)
 Creates a Parameter that will be configured under the given name and with the given initial value.
template<typename U>
 Parameter (const std::string &name, U &&value, Configurable *parent)
 Create a Parameter that is directly registered with the parent Configurable instance.
template<typename U>
 Parameter (const std::string &name, U &&value, Configurable &parent)
 Parameter (const Parameter< T > &other)
 Parameter (Parameter< T > &&other)
Parameter< T > & operator= (const Parameter< T > &other)
 Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.
Parameter< T > & operator= (Parameter< T > &other)
 Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.
Parameter< T > & operator= (Parameter< T > &&other)
 Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.
template<typename U>
Parameter< T > & operator= (U &&value)
 Updates the Parameter's stored value, emits the signalValueChanged if needed.
template<typename U>
void setValue (U &&value)
 Updates the Parameter's stored value, emits the signalValueChanged if needed.
const T & value () const
 Returns the currently stored value.
 operator const T & () const
 Returns the currently stored value.
void setDefault (const T &defaultValue)
 Sets the default value for this parameter.
void removeDefault ()
 Removes the default value for this parameter.
std::optional< T > defaultValue () const
 Returns the default value of this parameter if specified.
void setType (Properties::ParamType type)
 Sets an optional custom ParamType.
template<typename Q = T>
std::enable_if_t< std::is_arithmetic_v< Q > > setRange (T min, T max)
 Set the min/max parameter attributes of arithmetic parameters.
template<typename Q = T>
std::enable_if_t< std::is_same_v< Q, std::optional< typename Q::value_type > > &&std::is_arithmetic_v< typename Q::value_type > > setRange (typename Q::value_type min, typename Q::value_type max)
 Set the min/max parameter attributes of optional arithmetic parameters.
void configure (const Properties *p) override
 Configure this parameter/sub property by de-serializing the given Properties.
void configuration (Properties *p) const override
 Serialize the current parameter/sub property state into the given Properties object.
Public Member Functions inherited from ImFusion::ParameterBase
 ParameterBase (const std::string &name)
const Configurable * parent () const
 Return the parent Configurable instance that this parameter is registered with.
virtual const std::stringname () const
 Returns parameter name, can only be set during construction.
void setAttribute (const std::string &key, const std::string &value)
 Add the given attribute key-value pair to the set of parameter attributes.
void removeAttribute (const std::string &key)
 Remove the attribute with the given key.
const std::map< std::string, std::string > & attributes () const
 Get the attribute map.
void setLabel (const std::string &label)
 Sets an optional label for the Parameter if displayed in the UI.
void addDeprecatedName (const std::string &deprecatedName)
 Adds an optional alternative parameter name that should be used for param lookup for during configure() in case de-serialization from m_name was not successful.
const std::vector< std::string > & deprecatedNames () const
 Returns the list of deprecated parameter names that should be used for param lookup (see addDeprecatedName()).

Protected Attributes

m_value
std::optional< T > m_defaultValue
Properties::ParamType m_type = Properties::ParamType::Unknown
Protected Attributes inherited from ImFusion::ParameterBase
Configurable * m_parent = nullptr
const std::string m_name
std::vector< std::stringm_deprecatedNames
std::map< std::string, std::stringm_attributes

Additional Inherited Members

Public Attributes inherited from ImFusion::ParameterBase
Signal signalValueChanged
 Signal gets emitted when the underlying value of the Parameter/SubProperty has changed (either through setValue() or configure()).
Protected Member Functions inherited from ImFusion::ParameterBase
void setParentFromCopy (const ParameterBase &other)
 Helper function to be called from a copy/move ctor in order to correctly set the parent relation ship to the new parent Configurable.

Constructor & Destructor Documentation

◆ Parameter() [1/2]

template<typename T>
template<typename U>
ImFusion::Parameter< T >::Parameter ( const std::string & name,
U && value )

Creates a Parameter that will be configured under the given name and with the given initial value.

The initial value will also be used as default value.

◆ Parameter() [2/2]

template<typename T>
template<typename U>
ImFusion::Parameter< T >::Parameter ( const std::string & name,
U && value,
Configurable * parent )

Create a Parameter that is directly registered with the parent Configurable instance.

The parent instance is stored and thus must have a lifetime longer than this object.

Member Function Documentation

◆ operator=() [1/3]

template<typename T>
Parameter< T > & ImFusion::Parameter< T >::operator= ( const Parameter< T > & other)

Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.

Expects name and deprecated names to be the same and will not change the parent relationship. Use *this = other.value() if you want to assign only the value from other

◆ operator=() [2/3]

template<typename T>
Parameter< T > & ImFusion::Parameter< T >::operator= ( Parameter< T > & other)

Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.

Expects name and deprecated names to be the same and will not change the parent relationship. Use *this = other.value() if you want to assign only the value from other

Note
This implementation is required as otherwise operator=(U&&) will be picked up as non-const assign operator.

◆ operator=() [3/3]

template<typename T>
Parameter< T > & ImFusion::Parameter< T >::operator= ( Parameter< T > && other)

Assigns value, default value, type, and attributes from another Parameter instance of the same type and emits signalValueChanged.

Expects name and deprecated names to be the same and will not change the parent relationship. Use *this = other.value() if you want to assign only the value from other

◆ setType()

template<typename T>
void ImFusion::Parameter< T >::setType ( Properties::ParamType type)
inline

Sets an optional custom ParamType.

If not set explicitly, it is deduced from T.

See also
Properties::setParamType()

◆ setRange() [1/2]

template<typename T>
template<typename Q = T>
std::enable_if_t< std::is_arithmetic_v< Q > > ImFusion::Parameter< T >::setRange ( T min,
T max )
inline

Set the min/max parameter attributes of arithmetic parameters.

See also
Properties::setParamAttributes()

◆ setRange() [2/2]

template<typename T>
template<typename Q = T>
std::enable_if_t< std::is_same_v< Q, std::optional< typename Q::value_type > > &&std::is_arithmetic_v< typename Q::value_type > > ImFusion::Parameter< T >::setRange ( typename Q::value_type min,
typename Q::value_type max )
inline

Set the min/max parameter attributes of optional arithmetic parameters.

See also
Properties::setParamAttributes()

◆ configure()

template<typename T>
void ImFusion::Parameter< T >::configure ( const Properties * p)
overridevirtual

Configure this parameter/sub property by de-serializing the given Properties.

Implements ImFusion::ParameterBase.

◆ configuration()

template<typename T>
void ImFusion::Parameter< T >::configuration ( Properties * p) const
overridevirtual

Serialize the current parameter/sub property state into the given Properties object.

Implements ImFusion::ParameterBase.


The documentation for this class was generated from the following file:
  • ImFusion/Core/Parameter.h
Search Tab / S to search, Esc to close