JeVois
1.22
JeVois Smart Embedded Machine Vision Toolkit
|
|
#include <jevois/Component/Parameter.H>
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.
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. | |
T | 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. | |
jevois::ParameterCore< T >::ParameterCore | ( | ParameterDef< T > const & | def | ) |
Constructor.
def | A pointer to the definition for this parameter (given by a ParameterDef). |
|
virtual |
Destructor.
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.
ParameterDef< T > const & jevois::ParameterCore< T >::def | ( | ) | const |
Access to our parameter def.
|
overridevirtual |
Get the parameter fully-qualified name, aka descriptor.
Implements jevois::ParameterBase.
T jevois::ParameterCore< T >::get | ( | ) | const |
Get the value of this Parameter.
|
overridevirtual |
Get the parameter name.
Implements jevois::ParameterBase.
|
protectedpure virtual |
Get the Component to which this Parameter is attached, or nullptr (individual parameters must override)
Implemented in jevois::DynamicParameter< T >.
|
overridevirtual |
Reset this parameter to its default value.
Implements jevois::ParameterBase.
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.
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).
|
overridevirtual |
Get the value as a string representation of it.
Implements jevois::ParameterBase.
|
overridevirtual |
Set the value from a string representation of it.
std::range_error | if the given string cannot be converted to a valid Parameter value. |
Implements jevois::ParameterBase.
|
overridevirtual |
Get summary info about this parameter.
Implements jevois::ParameterBase.