JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches

#include <jevois/Component/Parameter.H>

template<typename T>
class jevois::ParameterCore< T >

A changeable parameter for a Component, core class.

Parameters are used to expose user-configurable settings for a Component. They can be specified from the command line and will be set by the time Component::postInit() is called on the Component which owns the Parameter. A Parameter may have a callback function which is invoked each time an attempt is made to change the Parameter value.

Definition at line 193 of file Parameter.H.

Inheritance diagram for jevois::ParameterCore< T >:
Collaboration diagram for jevois::ParameterCore< T >:

Public Member Functions

 ParameterCore (ParameterDef< T > const &def)
 Constructor.
 
virtual ~ParameterCore ()
 Destructor.
 
virtual std::string const & name () const override
 Get the parameter name.
 
virtual std::string descriptor () const override
 Get the parameter fully-qualified name, aka descriptor.
 
get () const
 Get the value of this Parameter.
 
void set (T const &newVal)
 Set the value of this Parameter.
 
virtual void strset (std::string const &valstring) override
 Set the value from a string representation of it.
 
virtual std::string const strget () const override
 Get the value as a string representation of it.
 
virtual ParameterSummary const summary () const override
 Get summary info about this parameter.
 
virtual void reset () override
 Reset this parameter to its default value.
 
ParameterDef< T > const & def () const
 Access to our parameter def.
 
void changeParameterDef (ParameterDef< T > const &def)
 Change the ParameterDef of this parameter.
 
void setCallback (std::function< void(T const &)> cb)
 Set the parameter's callback.
 
- Public Member Functions inherited from jevois::ParameterBase
 ParameterBase ()
 Constructor.
 
virtual ~ParameterBase ()
 Destructor, will remove the parameter from its owner component.
 
void freeze (bool doit)
 Freeze or un-freeze a parameter; frozen parameters cannot be set(), but get() is still allowed.
 
bool frozen () const
 Returns whether parameter is frozen.
 

Protected Member Functions

virtual Component const * owner () const =0
 Get the Component to which this Parameter is attached, or nullptr (individual parameters must override)
 

Additional Inherited Members

- Protected Attributes inherited from jevois::ParameterBase
boost::shared_mutex itsMutex
 Mutex to protect the parameter value.
 
volatile bool itsFrozen
 When true, parameter is frozen (read-only, does not show up in help message)
 
bool itsVirgin
 Param has not yet been explicitly set, need to call the callback (if any) at init time.
 

Constructor & Destructor Documentation

◆ ParameterCore()

template<typename T >
jevois::ParameterCore< T >::ParameterCore ( ParameterDef< T > const &  def)

Constructor.

Parameters
defA pointer to the definition for this parameter (given by a ParameterDef).

◆ ~ParameterCore()

template<typename T >
virtual jevois::ParameterCore< T >::~ParameterCore ( )
virtual

Destructor.

Member Function Documentation

◆ changeParameterDef()

template<typename T >
void jevois::ParameterCore< T >::changeParameterDef ( ParameterDef< T > const &  def)

Change the ParameterDef of this parameter.

Use with caution, only people who know what they are doing should use this function. Its thread safety and possible side effects are dubious.

◆ def()

template<typename T >
ParameterDef< T > const & jevois::ParameterCore< T >::def ( ) const

Access to our parameter def.

◆ descriptor()

template<typename T >
virtual std::string jevois::ParameterCore< T >::descriptor ( ) const
overridevirtual

Get the parameter fully-qualified name, aka descriptor.

Implements jevois::ParameterBase.

◆ get()

template<typename T >
T jevois::ParameterCore< T >::get ( ) const

Get the value of this Parameter.

◆ name()

template<typename T >
virtual std::string const & jevois::ParameterCore< T >::name ( ) const
overridevirtual

Get the parameter name.

Implements jevois::ParameterBase.

◆ owner()

template<typename T >
virtual Component const * jevois::ParameterCore< T >::owner ( ) const
protectedpure virtual

Get the Component to which this Parameter is attached, or nullptr (individual parameters must override)

Implemented in jevois::DynamicParameter< T >.

◆ reset()

template<typename T >
virtual void jevois::ParameterCore< T >::reset ( )
overridevirtual

Reset this parameter to its default value.

Implements jevois::ParameterBase.

◆ set()

template<typename T >
void jevois::ParameterCore< T >::set ( T const &  newVal)

Set the value of this Parameter.

Will throw jevois::exception::ParameterException if the new value is not accepted, in which case the old value will remain in the Parameter.

◆ setCallback()

template<typename T >
void jevois::ParameterCore< T >::setCallback ( std::function< void(T const &)>  cb)

Set the parameter's callback.

The callback function is called each time one tries to change the value of the parameter. Try to avoid using setCallback() so you won't confuse users of your class. In most cases, just use the convenience JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK() macro.

The callback should examine the candidate value newval and (1) if it does not like it, throw an std::range_error with a descriptive message of why the value is rejected, (2) otherwise, it is assumed that the value is accepted and the callback can then allocate resources or do other work with that value (the actual modification of the Parameter object is handled upstream and the callback does not need to worry about it: if it returns without throwing, the proposed value will become the new value of the Parameter). The Parameter is locked-up for writing as long as the callback is running, to avoid destruction of the parameter and/or concurrent parameter value changes by several different threads. Thus, callbacks should try to execute quickly, and should not call set(), etc on the parameter as this will always deadlock (get() is allowed if your callback needs to know the current value of the parameter).

◆ strget()

template<typename T >
virtual std::string const jevois::ParameterCore< T >::strget ( ) const
overridevirtual

Get the value as a string representation of it.

Implements jevois::ParameterBase.

◆ strset()

template<typename T >
virtual void jevois::ParameterCore< T >::strset ( std::string const &  valstring)
overridevirtual

Set the value from a string representation of it.

Exceptions
std::range_errorif the given string cannot be converted to a valid Parameter value.

Implements jevois::ParameterBase.

◆ summary()

template<typename T >
virtual ParameterSummary const jevois::ParameterCore< T >::summary ( ) const
overridevirtual

Get summary info about this parameter.

Implements jevois::ParameterBase.


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