PropertyDefinition< PropertyType > Class Template Reference

PropertyDefinition defines a property that will be available within the PropertyUser. More...

#include <ArmarXCore/core/application/properties/PropertyDefinition.h>

+ Inheritance diagram for PropertyDefinition< PropertyType >:

Public Types

typedef std::function< PropertyType(std::string)> PropertyFactoryFunction
 
using PropertyTypePtr = std::shared_ptr<PropertyType>
 
using PropertyValuesMap = std::map<std::string, ValueEntry>
 
using ValueEntry = std::pair<std::string, PropertyType>
 
- Public Types inherited from PropertyDefinitionBase
enum  PropertyConstness { eConstant , eModifiable }
 

Public Member Functions

bool expandEnvironmentVariables () const
 
std::string getDefaultAsString () override
 
PropertyType getDefaultValue ()
 
std::string getDescription () const
 
PropertyFactoryFunction getFactory () const
 
std::string getMatchRegex () const
 
double getMax () const
 
double getMin () const
 
std::string getPropertyName () const
 
PropertyType getValue (const std::string &prefix, Ice::PropertiesPtr)
 
PropertyValuesMapgetValueMap ()
 
bool isCaseInsensitive () const
 
bool isSet (const std::string &prefix, Ice::PropertiesPtr iceProperties) const
 
PropertyDefinition< PropertyType > & map (const std::map< std::string, PropertyType > &values)
 
template<class T>
std::enable_if_t< std::is_same_v< T, PropertyType > &&!std::is_same_v< T, std::string >, PropertyDefinition< T > & > map (const std::map< T, std::string > &values)
 
PropertyDefinition< PropertyType > & map (const std::string &valueString, PropertyType value)
 Maps a string value onto a value of the specified template type.
 
template<class T>
std::enable_if_t< meta::properties::MapPropertyValuePlugin< T >::value, PropertyDefinition< PropertyType > & > map (const T &values)
 
 PropertyDefinition (PropertyType *setterRef, const std::string &propertyName, const std::string &description, PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
 Constructs a property definition of a required property.
 
 PropertyDefinition (PropertyType *setterRef, const std::string &propertyName, PropertyType defaultValue, const std::string &description, PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
 Constructs a property definition of an optional property.
 
 PropertyDefinition (std::function< void(const PropertyType &)> setter, const std::string &propertyName, PropertyType defaultValue, const std::string &description, PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
 
bool removeQuotes () const
 
PropertyDefinition< PropertyType > & setCaseInsensitive (bool isCaseInsensitive)
 Sets whether the property value matching is case insensitive.
 
PropertyDefinition< PropertyType > & setExpandEnvironmentVariables (bool expand)
 Sets whether for string values environment varbiale expanding should be considered.
 
PropertyDefinition< PropertyType > & setFactory (const PropertyFactoryFunction &func)
 Sets the factory function that creates the specified template type from the actual string value.
 
PropertyDefinition< PropertyType > & setMatchRegex (const std::string &expr)
 Sets the regular expression which the value has to be matched with.
 
PropertyDefinition< PropertyType > & setMax (double max)
 Sets the max allowed numeric value.
 
template<class T = PropertyType>
PropertyDefinition< PropertyType > & setMax (std::array< T, 1 > max)
 
PropertyDefinition< PropertyType > & setMin (double min)
 Sets the min allowed numeric value.
 
template<class T = PropertyType>
PropertyDefinition< PropertyType > & setMin (std::array< T, 1 > min)
 
PropertyDefinition< PropertyType > & setRemoveQuotes (bool removeQuotes)
 Sets whether for string values leading and trailing quotes should be removed.
 
std::string toString (PropertyDefinitionFormatter &formatter, const std::string &value) override
 
virtual void writeValueToSetter (const std::string &prefix, Ice::PropertiesPtr) override
 
- Public Member Functions inherited from PropertyDefinitionBase
bool isConstant () const
 
bool isRequired () const
 
bool isSet (std::string const &prefix, std::string const &propertyName, Ice::PropertiesPtr const &iceProperties) const
 
 PropertyDefinitionBase (bool required=true, PropertyConstness constness=eConstant)
 
virtual ~PropertyDefinitionBase ()
 

Static Public Member Functions

static void removeQuotes (const std::string &input, std::string &output)
 Checks first and last character of input and in case both are quotes, they are removed and the remaining result is stored in output.
 
- Static Public Member Functions inherited from PropertyDefinitionBase
static std::string icePropertyGet (Ice::PropertiesPtr const &iceProperties, std::string const &key)
 

Protected Attributes

bool caseInsensitive
 Case sensitivity indicator.
 
PropertyType defaultValue
 Fallback/Default property value.
 
std::string description
 Property description.
 
bool expandEnvVars
 Exand environments variables indicator (standard: true)
 
PropertyFactoryFunction factory
 Builder function.
 
double max
 Upper bound of numeric values (used for numeric value retrieval without mapping)
 
double min
 Lower bound of numeric values (used for numeric value retrieval without mapping)
 
std::string propertyName
 Property name.
 
PropertyValuesMap propertyValuesMap
 Main property map.
 
std::string regex
 Regular expression to approve a required value pattern.
 
std::optional< std::function< void(const PropertyType &)> > setter
 
PropertyType * setterRef
 Reference to a variable to set.
 
bool stringRemoveQuotes
 Remove leading and trailing quotes indicator (standard: true) First and last character of a string property value are checked for quotes.
 
- Protected Attributes inherited from PropertyDefinitionBase
PropertyConstness constness
 
bool required
 If set to true, the property must be explicitely set through configuration parameters.
 

Detailed Description

template<typename PropertyType>
class armarx::PropertyDefinition< PropertyType >

PropertyDefinition defines a property that will be available within the PropertyUser.

PropertyDefinition provides the definition and description of a property that may be definined in a config file or passed via command line as an option. Depending which constructor is used a property is either required or optional. In the latter case a default value has to be specified.

The property specific value type (PropertyType) can be arbitrary, yet it is devided into these three groups which are handled internally differently:

  • String values
  • Arithmetic values (integral & floating point types)
  • Custom objects (Classes, Structs, Enums)

Fluent Interface

All setters are self referential and therefor can be chained to simplify the implementation and increase the readability.

Example

PropertyDefinition<float> frameRateDef("MyFrameRate", "Capture frame rate");
frameRateDef
.setMatchRegex("\\d+(.\\d*)?")
.setMin(0.0f)
.setMax(60.0f);
PropertyDefinition(PropertyType *setterRef, const std::string &propertyName, const std::string &description, PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Constructs a property definition of a required property.

Definition at line 119 of file PropertyDefinition.h.

Member Typedef Documentation

◆ PropertyFactoryFunction

template<typename PropertyType>
typedef std::function<PropertyType(std::string)> PropertyFactoryFunction

Definition at line 125 of file PropertyDefinition.h.

◆ PropertyTypePtr

template<typename PropertyType>
using PropertyTypePtr = std::shared_ptr<PropertyType>

Definition at line 122 of file PropertyDefinition.h.

◆ PropertyValuesMap

template<typename PropertyType>
using PropertyValuesMap = std::map<std::string, ValueEntry>

Definition at line 124 of file PropertyDefinition.h.

◆ ValueEntry

template<typename PropertyType>
using ValueEntry = std::pair<std::string, PropertyType>

Definition at line 123 of file PropertyDefinition.h.

Constructor & Destructor Documentation

◆ PropertyDefinition() [1/3]

template<typename PropertyType>
PropertyDefinition ( PropertyType * setterRef,
const std::string & propertyName,
const std::string & description,
PropertyDefinitionBase::PropertyConstness constness = PropertyDefinitionBase::eConstant )

Constructs a property definition of a required property.

Parameters
setterRefSetter
propertyNameName of the property used in config files
descriptionMandatory property description

Definition at line 59 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ PropertyDefinition() [2/3]

template<typename PropertyType>
PropertyDefinition ( PropertyType * setterRef,
const std::string & propertyName,
PropertyType defaultValue,
const std::string & description,
PropertyDefinitionBase::PropertyConstness constness = PropertyDefinitionBase::eConstant )
inline

Constructs a property definition of an optional property.

Parameters
setterRefSetter
propertyNameName of the property used in config files
defaultValueProperty default value of the type PropertyType
descriptionMandatory property description

Definition at line 80 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ PropertyDefinition() [3/3]

template<typename PropertyType>
PropertyDefinition ( std::function< void(const PropertyType &)> setter,
const std::string & propertyName,
PropertyType defaultValue,
const std::string & description,
PropertyDefinitionBase::PropertyConstness constness = PropertyDefinitionBase::eConstant )
inline

Definition at line 103 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ expandEnvironmentVariables()

template<typename PropertyType>
bool expandEnvironmentVariables ( ) const

Definition at line 283 of file PropertyDefinition.hpp.

◆ getDefaultAsString()

template<typename PropertyType>
std::string getDefaultAsString ( )
overridevirtual

Implements PropertyDefinitionBase.

Definition at line 393 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultValue()

template<typename PropertyType>
PropertyType getDefaultValue ( )

Definition at line 339 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDescription()

template<typename PropertyType>
std::string getDescription ( ) const

Definition at line 325 of file PropertyDefinition.hpp.

◆ getFactory()

template<typename PropertyType>
PropertyDefinition< PropertyType >::PropertyFactoryFunction getFactory ( ) const

Definition at line 354 of file PropertyDefinition.hpp.

◆ getMatchRegex()

template<typename PropertyType>
std::string getMatchRegex ( ) const

Definition at line 297 of file PropertyDefinition.hpp.

◆ getMax()

template<typename PropertyType>
double getMax ( ) const

Definition at line 311 of file PropertyDefinition.hpp.

◆ getMin()

template<typename PropertyType>
double getMin ( ) const

Definition at line 304 of file PropertyDefinition.hpp.

◆ getPropertyName()

template<typename PropertyType>
std::string getPropertyName ( ) const

Definition at line 318 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ getValue()

template<typename PropertyType>
PropertyType getValue ( const std::string & prefix,
Ice::PropertiesPtr iceProperties )

Definition at line 488 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValueMap()

template<typename PropertyType>
PropertyDefinition< PropertyType >::PropertyValuesMap & getValueMap ( )

Definition at line 332 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ isCaseInsensitive()

template<typename PropertyType>
bool isCaseInsensitive ( ) const

Definition at line 276 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ isSet()

template<typename PropertyType>
bool isSet ( const std::string & prefix,
Ice::PropertiesPtr iceProperties ) const

Definition at line 729 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ map() [1/4]

template<typename PropertyType>
PropertyDefinition< PropertyType > & map ( const std::map< std::string, PropertyType > & values)
inline

Definition at line 148 of file PropertyDefinition.hpp.

◆ map() [2/4]

template<typename PropertyType>
template<class T>
std::enable_if_t< std::is_same_v< T, PropertyType > &&!std::is_same_v< T, std::string >, PropertyDefinition< T > & > map ( const std::map< T, std::string > & values)
inline

Definition at line 161 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ map() [3/4]

template<typename PropertyType>
PropertyDefinition< PropertyType > & map ( const std::string & valueString,
PropertyType value )
inline

Maps a string value onto a value of the specified template type.

Parameters
valueStringProperty string value key
valueProperty value
Returns
self reference

Definition at line 130 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ map() [4/4]

template<typename PropertyType>
template<class T>
std::enable_if_t< meta::properties::MapPropertyValuePlugin< T >::value, PropertyDefinition< PropertyType > & > map ( const T & values)
inline

Definition at line 186 of file PropertyDefinition.h.

◆ removeQuotes() [1/2]

template<typename PropertyType>
bool removeQuotes ( ) const

Definition at line 290 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ removeQuotes() [2/2]

template<typename PropertyType>
void removeQuotes ( const std::string & input,
std::string & output )
static

Checks first and last character of input and in case both are quotes, they are removed and the remaining result is stored in output.

Definition at line 820 of file PropertyDefinition.hpp.

◆ setCaseInsensitive()

template<typename PropertyType>
PropertyDefinition< PropertyType > & setCaseInsensitive ( bool isCaseInsensitive)

Sets whether the property value matching is case insensitive.

Parameters
isCaseInsensitiveCase sensitivity state
Returns
self reference

Definition at line 181 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ setExpandEnvironmentVariables()

template<typename PropertyType>
PropertyDefinition< PropertyType > & setExpandEnvironmentVariables ( bool expand)

Sets whether for string values environment varbiale expanding should be considered.

Parameters
expandExpand entries like '${ENV_VAR}' to the according values of the environment.
Returns
self reference

Definition at line 215 of file PropertyDefinition.hpp.

◆ setFactory()

template<typename PropertyType>
PropertyDefinition< PropertyType > & setFactory ( const PropertyFactoryFunction & func)

Sets the factory function that creates the specified template type from the actual string value.

Parameters
functhe factory function
Returns
self reference

Definition at line 172 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ setMatchRegex()

template<typename PropertyType>
PropertyDefinition< PropertyType > & setMatchRegex ( const std::string & expr)

Sets the regular expression which the value has to be matched with.

Parameters
exprValue regular expression
Returns
self reference

Definition at line 231 of file PropertyDefinition.hpp.

◆ setMax() [1/2]

template<typename PropertyType>
PropertyDefinition< PropertyType > & setMax ( double max)

Sets the max allowed numeric value.

Parameters
maxMax. allowed value
Returns
self reference

Definition at line 258 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ setMax() [2/2]

template<typename PropertyType>
template<class T = PropertyType>
PropertyDefinition< PropertyType > & setMax ( std::array< T, 1 > max)
inline

Definition at line 264 of file PropertyDefinition.h.

◆ setMin() [1/2]

template<typename PropertyType>
PropertyDefinition< PropertyType > & setMin ( double min)

Sets the min allowed numeric value.

Parameters
minMin. allowed value
Returns
self reference

Definition at line 240 of file PropertyDefinition.hpp.

+ Here is the caller graph for this function:

◆ setMin() [2/2]

template<typename PropertyType>
template<class T = PropertyType>
PropertyDefinition< PropertyType > & setMin ( std::array< T, 1 > min)
inline

Definition at line 248 of file PropertyDefinition.h.

◆ setRemoveQuotes()

template<typename PropertyType>
PropertyDefinition< PropertyType > & setRemoveQuotes ( bool removeQuotes)

Sets whether for string values leading and trailing quotes should be removed.

Parameters
removeQuotesThe indicator.
Returns
self reference

Definition at line 223 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ toString()

template<typename PropertyType>
std::string toString ( PropertyDefinitionFormatter & formatter,
const std::string & value )
overridevirtual
See also
PropertyDefinitionBase::toString()

Implements PropertyDefinitionBase.

Definition at line 361 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

◆ writeValueToSetter()

template<typename PropertyType>
void writeValueToSetter ( const std::string & prefix,
Ice::PropertiesPtr iceProperties )
overridevirtual

Implements PropertyDefinitionBase.

Definition at line 497 of file PropertyDefinition.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ caseInsensitive

template<typename PropertyType>
bool caseInsensitive
protected

Case sensitivity indicator.

Definition at line 338 of file PropertyDefinition.h.

◆ defaultValue

template<typename PropertyType>
PropertyType defaultValue
protected

Fallback/Default property value.

Definition at line 316 of file PropertyDefinition.h.

◆ description

template<typename PropertyType>
std::string description
protected

Property description.

Definition at line 311 of file PropertyDefinition.h.

◆ expandEnvVars

template<typename PropertyType>
bool expandEnvVars
protected

Exand environments variables indicator (standard: true)

Definition at line 343 of file PropertyDefinition.h.

◆ factory

template<typename PropertyType>
PropertyFactoryFunction factory
protected

Builder function.

Definition at line 328 of file PropertyDefinition.h.

◆ max

template<typename PropertyType>
double max
protected

Upper bound of numeric values (used for numeric value retrieval without mapping)

Definition at line 358 of file PropertyDefinition.h.

◆ min

template<typename PropertyType>
double min
protected

Lower bound of numeric values (used for numeric value retrieval without mapping)

Definition at line 364 of file PropertyDefinition.h.

◆ propertyName

template<typename PropertyType>
std::string propertyName
protected

Property name.

Definition at line 306 of file PropertyDefinition.h.

◆ propertyValuesMap

template<typename PropertyType>
PropertyValuesMap propertyValuesMap
protected

Main property map.

Definition at line 301 of file PropertyDefinition.h.

◆ regex

template<typename PropertyType>
std::string regex
protected

Regular expression to approve a required value pattern.

Definition at line 333 of file PropertyDefinition.h.

◆ setter

template<typename PropertyType>
std::optional<std::function<void(const PropertyType&)> > setter
protected

Definition at line 323 of file PropertyDefinition.h.

◆ setterRef

template<typename PropertyType>
PropertyType* setterRef
protected

Reference to a variable to set.

Definition at line 321 of file PropertyDefinition.h.

◆ stringRemoveQuotes

template<typename PropertyType>
bool stringRemoveQuotes
protected

Remove leading and trailing quotes indicator (standard: true) First and last character of a string property value are checked for quotes.

E.g. "test" -> test 'test' -> test

Definition at line 352 of file PropertyDefinition.h.


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