JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit

#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 183 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 std::string const & 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 std::string const strget () const override
 Get the value as a string representation of it. More...
 
virtual ParameterSummary const summary () const override
 Get summary info about this parameter. 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...
 

Protected Member Functions

virtual Component const * owner () 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

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

Constructor.

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

Definition at line 46 of file ParameterImpl.H.

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

Destructor.

Definition at line 52 of file ParameterImpl.H.

Member Function Documentation

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

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.

Definition at line 151 of file ParameterImpl.H.

References jevois::ParameterDef< T >::defaultValue().

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

Get the parameter fully-qualified name, aka descriptor.

Implements jevois::ParameterBase.

Definition at line 65 of file ParameterImpl.H.

References jevois::Component::descriptor().

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

Get the value of this Parameter.

Definition at line 73 of file ParameterImpl.H.

Referenced by jevois::Component::getParamVal().

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

Get the parameter name.

Implements jevois::ParameterBase.

Definition at line 60 of file ParameterImpl.H.

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)

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

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.

Definition at line 89 of file ParameterImpl.H.

Referenced by jevois::Component::setParamVal(), and jevois::ParameterCore< T >::strset().

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

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).

Definition at line 81 of file ParameterImpl.H.

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

Get the value as a string representation of it.

Implements jevois::ParameterBase.

Definition at line 146 of file ParameterImpl.H.

References jevois::detail::paramStringFromVal().

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

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.

Definition at line 141 of file ParameterImpl.H.

References jevois::ParameterCore< T >::set().


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