iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::ParameterCore< T > Class Template Reference

#include <nrt/Core/Model/Parameter.H>

template<class T>
class nrt::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::preStart() has been called on the Component which owns the Parameter.

See examples in test-Component.C and test-Option.C

Definition at line 60 of file ModulePortHelpers.H.

Inheritance diagram for nrt::ParameterCore< T >:
nrt::ParameterBase

Public Member Functions

 ParameterCore (ParameterDef< T > const &def)
 Constructor. More...
 
virtual ~ParameterCore ()
 Destructor.
 
virtual std::string const & name () const
 Get the parameter name. If you need more info about this parameter, try summary()
 
get () const
 Get the value of this Parameter.
 
void set (T const &newVal)
 Set the value of this Parameter. More...
 
virtual void strset (std::string const &valstring)
 Set the value from a string representation of it. More...
 
virtual std::string const strget () const
 Get the value as a string representation of it.
 
virtual ParameterSummary const summary () const
 Get summary info about this parameter.
 
void changeParameterDef (ParameterDef< T > const &def)
 Create a Module Port for this Parameter. See Module.H for more on Module. More...
 
void setCallback (std::function< void(T const &)> cb)
 Set the parameter's callback. More...
 
- Public Member Functions inherited from nrt::ParameterBase
 ParameterBase ()
 Constructor.
 
virtual ~ParameterBase ()
 Destructor, will remove the parameter from its owner component.
 
Componentowner ()
 Get the Component to which this Parameter is attached, or nullptr.
 
Component const * owner () const
 Get the Component to which this Parameter is attached, or nullptr; const version.
 

Additional Inherited Members

- Protected Attributes inherited from nrt::ParameterBase
boost::shared_mutex itsMutex
 
Create a Module Port for this Parameter. See Module.H for more on Module.

/virtual void createPort(ModuleParamPort const ptype, std::string const & module, / std::string const & descriptor) = 0; More...

 

Constructor & Destructor Documentation

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

Constructor.

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

Definition at line 53 of file ParameterImpl.H.

Member Function Documentation

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

Set the value of this Parameter.

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

if (itsPoster) { std::shared_ptr<nrt::Message<T> > msg(new nrt::Message<T>(newVal)); itsPoster->doPost(msg); }

Definition at line 101 of file ParameterImpl.H.

References nrt::NoOnlineChanges, and nrt::exception::Exception::what().

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

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

Set the value from a string representation of it.

Exceptions
nrt::exception::ParameterExceptionif the given string cannot be converted (using boost::lexical_cast) to a valid Parameter value.

Implements nrt::ParameterBase.

Definition at line 160 of file ParameterImpl.H.

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

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

Create a Module Port for this Parameter. See Module.H for more on Module.

Note
This method will post() the current Parameter value as soon as the port is created Delete a Module Port for this Parameter. See Module.H for more on Module. /virtual void deletePort(ModuleParamPort const ptype); Set the topic of a Parameter Poster

Will throw if the port is not found, eg, it has not been created

Note
This method will post() the current Parameter value as soon as the topic is set Set the topic filter of a Parameter Checker

Will throw if the port is not found, eg, it has not been created Set the topic filter of a Parameter Subscriber

Will throw if the port is not found, eg, it has not been created Change the ParameterDef of this parameter

Use with caution, only people who know what they are doing should use this function

Definition at line 268 of file ParameterImpl.H.

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

template<typename T >
void nrt::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 this so you won't confuse users of your class. In most cases, just use NRT_DECLARE_PARAMETER_WITH_CALLBACK.

Default callback behavior is a no-op and the new value will be accepted. If overloading this function, check for acceptable values and trigger any action, then just return if all went well. Otherwise, throw nrt::exception::BadParameter to indicate that the proposed value is rejected.

The callback should examine the candidate value newval and (1) if it does not like it, throw nrt::exception::BadParameter, (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 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 92 of file ParameterImpl.H.


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