Public Member Functions | List of all members
sdf::v12::Param Class Reference

A parameter class. More...

#include <sdf/sdf.hh>

Public Member Functions

 Param (const Param &_param)
 Copy constructor Note that the updateFunc member does not get copied. More...
 
 Param (const std::string &_key, const std::string &_typeName, const std::string &_default, bool _required, const std::string &_description="")
 Constructor. More...
 
 Param (const std::string &_key, const std::string &_typeName, const std::string &_default, bool _required, const std::string &_minValue, const std::string &_maxValue, const std::string &_description="")
 Constructor with min and max values. More...
 
 Param (Param &&_param) noexcept=default
 Move constructor. More...
 
virtual ~Param ()
 Destructor. More...
 
ParamPtr Clone () const
 Clone the parameter. More...
 
template<typename T >
bool Get (T &_value) const
 Get the value of the parameter. More...
 
bool GetAny (std::any &_anyVal) const
 Get the value of the parameter as a std::any. More...
 
std::string GetAsString (const PrintConfig &_config=PrintConfig()) const
 Get the value as a string. More...
 
template<typename T >
bool GetDefault (T &_value) const
 Get the default value of the parameter. More...
 
std::string GetDefaultAsString (const PrintConfig &_config=PrintConfig()) const
 Get the default value as a string. More...
 
std::string GetDescription () const
 Get the description of the parameter. More...
 
const std::string & GetKey () const
 Get the key value. More...
 
std::optional< std::string > GetMaxValueAsString (const PrintConfig &_config=PrintConfig()) const
 Get the maximum allowed value as a string. More...
 
std::optional< std::string > GetMinValueAsString (const PrintConfig &_config=PrintConfig()) const
 Get the minimum allowed value as a string. More...
 
ElementPtr GetParentElement () const
 Get the parent Element of this Param. More...
 
bool GetRequired () const
 Return whether the parameter is required. More...
 
bool GetSet () const
 Return true if the parameter has been set. More...
 
const std::string & GetTypeName () const
 Get the type name value. More...
 
bool IgnoresParentElementAttribute () const
 Return true if the parameter ignores the parent element's attributes, or if the parameter has no parent element. More...
 
template<typename Type >
bool IsType () const
 Return true if the param is a particular type. More...
 
Paramoperator= (const Param &_param)
 Copy assignment operator Note that the updateFunc member will not get copied. More...
 
Paramoperator= (Param &&_param) noexcept=default
 Move assignment operator. More...
 
bool Reparse ()
 Reparse the parameter value. More...
 
void Reset ()
 Reset the parameter to the default value. More...
 
template<typename T >
bool Set (const T &_value)
 Set the parameter's value. More...
 
void SetDescription (const std::string &_desc)
 Set the description of the parameter. More...
 
bool SetFromString (const std::string &_value)
 Set the parameter value from a string. More...
 
bool SetFromString (const std::string &_value, bool _ignoreParentAttributes)
 Set the parameter value from a string. More...
 
bool SetParentElement (ElementPtr _parentElement)
 Set the parent Element of this Param. More...
 
template<typename T >
void SetUpdateFunc (T _updateFunc)
 Set the update function. More...
 
void Update ()
 Set the parameter's value using the updateFunc. More...
 
bool ValidateValue () const
 Validate the value against minimum and maximum allowed values. More...
 

Detailed Description

A parameter class.

Constructor & Destructor Documentation

◆ Param() [1/4]

sdf::v12::Param::Param ( const std::string &  _key,
const std::string &  _typeName,
const std::string &  _default,
bool  _required,
const std::string &  _description = "" 
)

Constructor.

Parameters
[in]_keyKey for the parameter.
[in]_typeNameString name for the value type (double, int,...).
[in]_defaultDefault value.
[in]_requiredTrue if the parameter is required to be set.
[in]_descriptionDescription of the parameter.
Exceptions
sdf::AssertionInternalErrorif an invalid type is given.

◆ Param() [2/4]

sdf::v12::Param::Param ( const std::string &  _key,
const std::string &  _typeName,
const std::string &  _default,
bool  _required,
const std::string &  _minValue,
const std::string &  _maxValue,
const std::string &  _description = "" 
)

Constructor with min and max values.

Parameters
[in]_keyKey for the parameter.
[in]_typeNameString name for the value type (double, int,...).
[in]_defaultDefault value.
[in]_requiredTrue if the parameter is required to be set.
[in]_minValueMinimum allowed value for the parameter.
[in]_maxValueMaximum allowed value for the parameter.
[in]_descriptionDescription of the parameter.
Exceptions
sdf::AssertionInternalErrorif an invalid type is given.

◆ Param() [3/4]

sdf::v12::Param::Param ( const Param _param)

Copy constructor Note that the updateFunc member does not get copied.

Parameters
[in]_paramParam to copy

◆ Param() [4/4]

sdf::v12::Param::Param ( Param &&  _param)
defaultnoexcept

Move constructor.

Parameters
[in]_paramParam to move from

◆ ~Param()

virtual sdf::v12::Param::~Param ( )
virtual

Destructor.

Member Function Documentation

◆ Clone()

ParamPtr sdf::v12::Param::Clone ( ) const

Clone the parameter.

Returns
A new parameter that is the clone of this.

◆ Get()

template<typename T >
bool sdf::v12::Param::Get ( T &  _value) const

Get the value of the parameter.

Parameters
[out]_valueThe value of the parameter.
Returns
True if parameter was successfully cast to the value type passed in.

References sdf::v12::lowercase(), and sdferr.

◆ GetAny()

bool sdf::v12::Param::GetAny ( std::any &  _anyVal) const

Get the value of the parameter as a std::any.

Parameters
[out]_anyValThe std::any object to set.
Returns
True if successfully fetched _anyVal, false otherwise.

◆ GetAsString()

std::string sdf::v12::Param::GetAsString ( const PrintConfig _config = PrintConfig()) const

Get the value as a string.

Parameters
[in]_configConfiguration for conversion to string.
Returns
String containing the value of the parameter.

◆ GetDefault()

template<typename T >
bool sdf::v12::Param::GetDefault ( T &  _value) const

Get the default value of the parameter.

Parameters
[out]_valueThe default value of the parameter.
Returns
True if parameter was successfully cast to the value type passed in.

References sdferr.

◆ GetDefaultAsString()

std::string sdf::v12::Param::GetDefaultAsString ( const PrintConfig _config = PrintConfig()) const

Get the default value as a string.

Parameters
[in]_configConfiguration for conversion to string.
Returns
String containing the default value of the parameter.

◆ GetDescription()

std::string sdf::v12::Param::GetDescription ( ) const

Get the description of the parameter.

Returns
The description of the parameter.

◆ GetKey()

const std::string& sdf::v12::Param::GetKey ( ) const

Get the key value.

Returns
The key.

◆ GetMaxValueAsString()

std::optional<std::string> sdf::v12::Param::GetMaxValueAsString ( const PrintConfig _config = PrintConfig()) const

Get the maximum allowed value as a string.

Parameters
[in]_configConfiguration for conversion to string.
Returns
Returns a string containing the maximum allowed value of the parameter if the maximum value is specified in the SDFormat description of the parameter. nullopt otherwise.

◆ GetMinValueAsString()

std::optional<std::string> sdf::v12::Param::GetMinValueAsString ( const PrintConfig _config = PrintConfig()) const

Get the minimum allowed value as a string.

Parameters
[in]_configConfiguration for conversion to string.
Returns
Returns a string containing the minimum allowed value of the parameter if the minimum value is specified in the SDFormat description of the parameter. nullopt otherwise.

◆ GetParentElement()

ElementPtr sdf::v12::Param::GetParentElement ( ) const

Get the parent Element of this Param.

Returns
Pointer to this Param's parent Element, nullptr if there is no parent Element.

◆ GetRequired()

bool sdf::v12::Param::GetRequired ( ) const

Return whether the parameter is required.

Returns
True if the parameter is required.

◆ GetSet()

bool sdf::v12::Param::GetSet ( ) const

Return true if the parameter has been set.

Returns
True if the parameter has been set.

◆ GetTypeName()

const std::string& sdf::v12::Param::GetTypeName ( ) const

Get the type name value.

Returns
The type name.

◆ IgnoresParentElementAttribute()

bool sdf::v12::Param::IgnoresParentElementAttribute ( ) const

Return true if the parameter ignores the parent element's attributes, or if the parameter has no parent element.

Returns
True if the parameter ignores the parent element's attributes, or if the parameter has no parent element.

◆ IsType()

template<typename Type >
bool sdf::v12::Param::IsType

Return true if the param is a particular type.

Returns
True if the type held by this Param matches the Type template parameter.

◆ operator=() [1/2]

Param& sdf::v12::Param::operator= ( const Param _param)

Copy assignment operator Note that the updateFunc member will not get copied.

Parameters
[in]_paramThe parameter to set values from.
Returns
*This

◆ operator=() [2/2]

Param& sdf::v12::Param::operator= ( Param &&  _param)
defaultnoexcept

Move assignment operator.

Parameters
[in]_paramParam to move from
Returns
Reference to this

◆ Reparse()

bool sdf::v12::Param::Reparse ( )

Reparse the parameter value.

This should be called after the parent element's attributes have been modified, in the event that the value was set using SetFromString or posesses a default value, and that the final parsed value is dependent on the attributes of the parent element. For example, the rotation component of a pose element can be parsed as degrees or radians, depending on the attribute @degrees of the parent element. If however the value was explicitly set using the Set<T> function, reparsing would not change the value.

Returns
True if the parameter value has been reparsed successfully.
See also
bool SetFromString(const std::string &_value)
bool Set(const T &_value)

◆ Reset()

void sdf::v12::Param::Reset ( )

Reset the parameter to the default value.

◆ Set()

template<typename T >
bool sdf::v12::Param::Set ( const T &  _value)

Set the parameter's value.

The passed in value value must have an input and output stream operator.

Parameters
[in]_valueThe value to set the parameter to.
Returns
True if the value was successfully set.

References sdferr.

◆ SetDescription()

void sdf::v12::Param::SetDescription ( const std::string &  _desc)

Set the description of the parameter.

Parameters
[in]_descNew description for the parameter.

◆ SetFromString() [1/2]

bool sdf::v12::Param::SetFromString ( const std::string &  _value)

Set the parameter value from a string.

Parameters
[in]_valueNew value for the parameter in string form.

◆ SetFromString() [2/2]

bool sdf::v12::Param::SetFromString ( const std::string &  _value,
bool  _ignoreParentAttributes 
)

Set the parameter value from a string.

Parameters
[in]_valueNew value for the parameter in string form.
[in]_ignoreParentAttributesWhether to ignore parent element attributes when parsing value from string as well as subsequent reparses.

◆ SetParentElement()

bool sdf::v12::Param::SetParentElement ( ElementPtr  _parentElement)

Set the parent Element of this Param.

Parameters
[in]_parentElementPointer to new parent Element. A nullptr can provided to remove the current parent Element.
Returns
True if the parent Element was set and the value was reparsed successfully.

◆ SetUpdateFunc()

template<typename T >
void sdf::v12::Param::SetUpdateFunc ( _updateFunc)

Set the update function.

The updateFunc will be used to set the parameter's value when Param::Update is called.

Parameters
[in]_updateFuncFunction pointer to an update function.

◆ Update()

void sdf::v12::Param::Update ( )

Set the parameter's value using the updateFunc.

See also
Param::SetUpdateFunc

◆ ValidateValue()

bool sdf::v12::Param::ValidateValue ( ) const

Validate the value against minimum and maximum allowed values.

Returns
True if the value is valid

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