JeVois  1.16
JeVois Smart Embedded Machine Vision Toolkit
Share this page:

#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 189 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. More...
 
virtual ~ParameterCore ()
 Destructor. More...
 
virtual const std::string & name () const override
 Get the parameter name. More...
 
virtual std::string descriptor () const override
 Get the parameter fully-qualified name, aka descriptor. More...
 
get () const
 Get the value of this Parameter. More...
 
void set (T const &newVal)
 Set the value of this Parameter. More...
 
virtual void strset (std::string const &valstring) override
 Set the value from a string representation of it. More...
 
virtual const std::string strget () const override
 Get the value as a string representation of it. More...
 
virtual const ParameterSummary summary () const override
 Get summary info about this parameter. More...
 
virtual void reset () override
 Reset this parameter to its default value. More...
 
void changeParameterDef (ParameterDef< T > const &def)
 Change the ParameterDef of this parameter. More...
 
void setCallback (std::function< void(T const &)> cb)
 Set the parameter's callback. More...
 
- Public Member Functions inherited from jevois::ParameterBase
 ParameterBase ()
 Constructor. More...
 
virtual ~ParameterBase ()
 Destructor, will remove the parameter from its owner component. More...
 
void freeze ()
 Freeze this parameter, it becomes read-only and will not show up in the help message. More...
 
void unFreeze ()
 Unfreeze this parameter, it becomes read-write and will show up in the help message. More...
 
void freeze (bool doit)
 Alternate syntax that can be used instead of freeze()/unFreeze(), useful for programmatic freezing. More...
 

Protected Member Functions

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

Additional Inherited Members

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

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.

◆ 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 const std::string& jevois::ParameterCore< T >::name ( ) const
overridevirtual

Get the parameter name.

Implements jevois::ParameterBase.

◆ owner()

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

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

◆ 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 and 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 const std::string 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 const ParameterSummary 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: