Robot Simulator of the Robotics Group for Self-Organization of Control: Configurable Class Reference

# Configurable Class Reference

Abstact class for configurable objects. More...

`#include <configurable.h>`

Inherits BackCaller.

Inherited by AbstractController, AbstractModel, AbstractRobot, ControllerNet, CopyWiring, ForceBoostWiring, Base, Gripper, OdeConfig, Operator, MotorNoiseWiring, QLearning, and WiredController.

Collaboration diagram for Configurable:
[legend]

List of all members.

## Classes
struct | matchId
| nice predicate function for finding by ID More...
## Public Types
typedef std::string | paramkey
typedef std::string | paramdescr
typedef double | paramval
typedef std::list< std::pair < paramkey, paramval > > | paramlist
typedef std::map< paramkey, paramval * > | parammap
typedef bool | parambool
typedef std::list< std::pair < paramkey, parambool > > | paramboollist
typedef std::map< paramkey, parambool * > | paramboolmap
typedef int | paramint
typedef std::list< std::pair < paramkey, paramint > > | paramintlist
typedef std::map< paramkey, paramint * > | paramintmap
typedef std::map< paramkey, paramdescr > | paramdescrmap
typedef std::pair< paramval, paramval > | paramvalBounds
typedef std::map< paramkey, paramvalBounds > | paramvalBoundsMap
typedef std::pair< paramint, paramint > | paramintBounds
typedef std::map< paramkey, paramintBounds > | paramintBoundsMap
typedef std::pair< paramkey, paramval * > | paramvalpair
typedef std::pair< paramkey, parambool * > | paramboolpair
typedef std::pair< paramkey, paramint * > | paramintpair
typedef std::vector < Configurable * > | configurableList
## Public Member Functions
| Configurable ()
| Configurable (const std::string &name, const std::string &revision)
| intialise with name and revision (use "$ID$")
virtual | ~Configurable ()
virtual void | notifyOnChange (const paramkey &key)
| Is called when a parameter was changes via setParam().
virtual void | addParameter (const paramkey &key, paramval *val, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
| This is the new style for adding configurable parameters.
virtual void | addParameter (const paramkey &key, paramval *val, const paramdescr &descr=paramdescr())
| See addParameter(const paramkey& key, paramval* val, paramval minBound, paramval maxBound, const paramdescr& descr).
virtual void | addParameter (const paramkey &key, parambool *val, const paramdescr &descr=paramdescr())
| See addParameter(const paramkey& key, paramval* val) but for bool values.
virtual void | addParameter (const paramkey &key, paramint *val, paramint minBound, paramint maxBound, const paramdescr &descr=paramdescr())
| See addParameter(const paramkey& key, paramval* val) but for int values.
virtual void | addParameter (const paramkey &key, paramint *val, const paramdescr &descr=paramdescr())
virtual void | addParameterDef (const paramkey &key, paramval *val, paramval def, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
| This function is only provided for convenience.
virtual void | addParameterDef (const paramkey &key, paramval *val, paramval def, const paramdescr &descr=paramdescr())
virtual void | addParameterDef (const paramkey &key, parambool *val, parambool def, const paramdescr &descr=paramdescr())
| See addParameterDef(const paramkey&, paramval*, paramval).
virtual void | addParameterDef (const paramkey &key, paramint *val, paramint def, paramint minBound, paramint maxBound, const paramdescr &descr=paramdescr())
| See addParameterDef(const paramkey&, paramval*, paramval).
virtual void | addParameterDef (const paramkey &key, paramint *val, paramint def, const paramdescr &descr=paramdescr())
virtual void | setParamDescr (const paramkey &key, const paramdescr &descr, bool traverseChildren=true)
| sets a description for the given parameter
int | getId () const
| return the id of the configurable objects, which is created by random on initialisation
virtual paramkey | getName () const
| return the name of the object
virtual paramkey | getRevision () const
| returns the revision of the object
virtual void | setName (const paramkey &name, bool callSetNameOfInspectable=true)
| Sets the name of the configurable.
virtual void | setRevision (const paramkey &revision)
| sets the revision Hint: { return "$ID$"; }
virtual paramval | getParam (const paramkey &key, bool traverseChildren=true) const
| returns the value of the requested parameter or 0 (+ error message to stderr) if unknown.
virtual bool | hasParam (const paramkey &key, bool traverseChildren=true) const
| Returns if the requested parameter is part of the configurable or their children.
virtual bool | setParam (const paramkey &key, paramval val, bool traverseChildren=true)
| sets the value of the given parameter or does nothing if unknown.
virtual void | setParamBounds (const paramkey &key, paramval minBound, paramval maxBound, bool traverseChildren=true)
| Sets the bounds (minBound and maxBound) of the given parameter.
virtual void | setParamBounds (const paramkey &key, paramint minBound, paramint maxBound, bool traverseChildren=true)
virtual void | setParamBounds (const paramkey &key, paramvalBounds bounds, bool traverseChildren=true)
virtual void | setParamBounds (const paramkey &key, paramintBounds bounds, bool traverseChildren=true)
virtual paramlist | getParamList () const
| The list of all parameters with there value as allocated lists.
virtual std::list< paramkey > | getAllParamNames (bool traverseChildren=true)
| returns all names that are configureable
virtual parammap | getParamValMap () const
virtual paramintmap | getParamIntMap () const
virtual paramboolmap | getParamBoolMap () const
virtual paramdescr | getParamDescr (const paramkey &key, bool traverseChildren=true) const
| returns the description for the given parameter
virtual paramvalBounds | getParamvalBounds (const paramkey &key, bool traverseChildren=true) const
virtual paramintBounds | getParamintBounds (const paramkey &key, bool traverseChildren=true) const
virtual bool | hasParamDescr (const paramkey &key, bool traverseChildren=true) const
virtual bool | hasParamvalBounds (const paramkey &key, bool traverseChildren=true) const
virtual bool | hasParamintBounds (const paramkey &key, bool traverseChildren=true) const
virtual bool | storeCfg (const char *filenamestem, const std::list< std::string > &comments=std::list< std::string >())
| stores the key values paires into the file : filenamestem.cfg including the comments given in the list
virtual bool | restoreCfg (const char *filenamestem)
| restores the key values paires from the file : filenamestem.cfg
void | print (FILE *f, const char *prefix, int columns=90, bool traverseChildren=true) const
| prints the keys, values and descriptions to the file. Each line is prefixed
bool | parse (FILE *f, const char *prefix=0, bool traverseChildren=true)
| parses the configuration from the given file
virtual void | addConfigurable (Configurable *conf)
| Adds a configurable as a child object.
virtual void | removeConfigurable (Configurable *conf)
| Removes a configurable as a child object.
virtual const configurableList & | getConfigurables () const
| Returns the list containing all configurable children.
virtual void | configurableChanged ()
| Indicates that the configurable itself or the configurable children attached to this configurable have changed.
## Static Public Member Functions
static void | insertCVSInfo (paramkey &str, const char *file, const char *revision)
| This is a utility function for inserting the filename and the revision number at the beginning of the given string buffer str and terminates it.
## Static Public Attributes
static const CallbackableType | CALLBACK_CONFIGURABLE_CHANGED = 11
## Protected Member Functions
void | copyParameters (const Configurable &, bool traverseChildren=true)
| copies the internal params of the given configurable
void | printdescr (FILE *f, const char *prefix, const paramkey &key, int columns, int indent) const

## Detailed Description

Abstact class for configurable objects.

Sort of Hashmap interface. Parameters are double, int or boolean values

The Configurator is a (planned) external tool that can be used for changing the values of configurable objects.

Protocoll for Configurator:

     To Configurator (BNF notation):
     Conf         := <Comp>*
     Comp         := <CompName> <Pair>*
     CompName     := [<string>][<int>]<newline>
     Pair         := <alphanum>=<double><newline>

the remaining tags are self explanatory

Example

     [Component name which can contain spaces and digits and .,- ][ID1]
     key1 = value1
     key2 = value2
     .
     .
     [Other Component name which can contain spaces and digits and .,- ][ID2]
     key3 = value3

Answer: (from Communicator to Simulation environment)
1. On change of a parameter:

     [ID] key=newvalue

or

     key=newvalue

the latter one means that the parameter is changed in all components

2. Request of the description as defined above.

     #Something I don\'t care

## Member Typedef Documentation

typedef std::vector<Configurable*> configurableList

typedef bool parambool

typedef std::list<std::pair<paramkey, parambool> > paramboollist

typedef std::map<paramkey, parambool*> paramboolmap

typedef std::pair<paramkey, parambool*> paramboolpair

typedef std::string paramdescr

typedef std::map<paramkey, paramdescr> paramdescrmap

typedef int paramint

typedef std::pair<paramint, paramint> paramintBounds

typedef std::map<paramkey, paramintBounds> paramintBoundsMap

typedef std::list<std::pair<paramkey, paramint> > paramintlist

typedef std::map<paramkey, paramint*> paramintmap

typedef std::pair<paramkey, paramint*> paramintpair

typedef std::string paramkey

Examples:
  integration/main.cpp.

typedef std::list<std::pair<paramkey, paramval> > paramlist

Examples:
  integration/main.cpp.

typedef std::map<paramkey, paramval*> parammap

typedef double paramval

Examples:
  integration/main.cpp.

typedef std::pair<paramval, paramval> paramvalBounds

typedef std::map<paramkey, paramvalBounds> paramvalBoundsMap

typedef std::pair<paramkey, paramval*> paramvalpair

## Constructor & Destructor Documentation

Configurable | ( |  | ) | `[inline]`

Configurable | ( | const std::string & | name,
|  | const std::string & | revision |
| ) |  |  | `[inline]`

intialise with name and revision (use "$ID$")

virtual ~Configurable | ( |  | ) | `[inline, virtual]`

## Member Function Documentation

void addConfigurable | ( | Configurable * | conf | ) | `[virtual]`

Adds a configurable as a child object.

Parameters:

  | conf | the instance to add

virtual void addParameter | ( | const paramkey & | key,
|  | paramint * | val,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

virtual void addParameter | ( | const paramkey & | key,
|  | paramint * | val,
|  | paramint | minBound,
|  | paramint | maxBound,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

See addParameter(const paramkey& key, paramval* val) but for int values.

virtual void addParameter | ( | const paramkey & | key,
|  | parambool * | val,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

See addParameter(const paramkey& key, paramval* val) but for bool values.

virtual void addParameter | ( | const paramkey & | key,
|  | paramval * | val,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

See addParameter(const paramkey& key, paramval* val, paramval minBound, paramval maxBound, const paramdescr& descr).

virtual void addParameter | ( | const paramkey & | key,
|  | paramval * | val,
|  | paramval | minBound,
|  | paramval | maxBound,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

This is the new style for adding configurable parameters.

Just call this function for each parameter and you are done. If you need to do some special treatment for setting (or getting) of the parameter you can handle this by overloading getParam and setParam

virtual void addParameterDef | ( | const paramkey & | key,
|  | paramint * | val,
|  | paramint | def,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

virtual void addParameterDef | ( | const paramkey & | key,
|  | paramint * | val,
|  | paramint | def,
|  | paramint | minBound,
|  | paramint | maxBound,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

See addParameterDef(const paramkey&, paramval*, paramval).

virtual void addParameterDef | ( | const paramkey & | key,
|  | parambool * | val,
|  | parambool | def,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

See addParameterDef(const paramkey&, paramval*, paramval).

virtual void addParameterDef | ( | const paramkey & | key,
|  | paramval * | val,
|  | paramval | def,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

virtual void addParameterDef | ( | const paramkey & | key,
|  | paramval * | val,
|  | paramval | def,
|  | paramval | minBound,
|  | paramval | maxBound,
|  | const paramdescr & | descr = `paramdescr()` |
| ) |  |  | `[inline, virtual]`

This function is only provided for convenience.

It does the same as addParameter but set the variable to the default value

void configurableChanged | ( |  | ) | `[virtual]`

Indicates that the configurable itself or the configurable children attached to this configurable have changed.

This method must be called manually so that the Configurator GUI can react at the changes. This is done through the callbackable interface (using CallbackableType CALLBACK_CONFIGURABLE_CHANGED).

void copyParameters | ( | const Configurable & | c,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[protected]`

copies the internal params of the given configurable

std::list< Configurable::paramkey > getAllParamNames | ( | bool | traverseChildren = `true` | ) | `[virtual]`

returns all names that are configureable

const Configurable::configurableList & getConfigurables | ( |  | ) | const`[virtual]`

Returns the list containing all configurable children.

int getId | ( |  | ) | const`[inline]`

return the id of the configurable objects, which is created by random on initialisation

virtual paramkey getName | ( |  | ) | const`[inline, virtual]`

return the name of the object

Reimplemented in Elman, InvertNChannelController, and Arm.

Configurable::paramval getParam | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

returns the value of the requested parameter or 0 (+ error message to stderr) if unknown.

Reimplemented in MyRobot.

virtual paramboolmap getParamBoolMap | ( |  | ) | const`[inline, virtual]`

Configurable::paramdescr getParamDescr | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

returns the description for the given parameter

Configurable::paramintBounds getParamintBounds | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

virtual paramintmap getParamIntMap | ( |  | ) | const`[inline, virtual]`

virtual paramlist getParamList | ( |  | ) | const`[inline, virtual]`

The list of all parameters with there value as allocated lists.

Note that these are only parameters that are managed manually (with setParam, getParam)

See also:
  getAllParamNames()

Returns:
  list of key-value pairs

Reimplemented in use_java_controller, and MyRobot.

Configurable::paramvalBounds getParamvalBounds | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

virtual parammap getParamValMap | ( |  | ) | const`[inline, virtual]`

virtual paramkey getRevision | ( |  | ) | const`[inline, virtual]`

returns the revision of the object

bool hasParam | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

Returns if the requested parameter is part of the configurable or their children.

Parameters:

  | key | to search for

Returns:
  true if key found, otherwise false

bool hasParamDescr | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

bool hasParamintBounds | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

bool hasParamvalBounds | ( | const paramkey & | key,
|  | bool | traverseChildren = `true` |
| ) |  |  | const`[virtual]`

void insertCVSInfo | ( | paramkey & | str,
|  | const char * | file,
|  | const char * | revision |
| ) |  |  | `[static]`

This is a utility function for inserting the filename and the revision number at the beginning of the given string buffer str and terminates it.

Parameters:

  | str | buffer (call by reference) that should have space for file+revision+2 characters
  | file | filename given by CVS i.e. $RCSfile$
  | revision | revision number given by CVS i.e. $Revision$

virtual void notifyOnChange | ( | const paramkey & | key | ) | `[inline, virtual]`

Is called when a parameter was changes via setParam().

Note that it is not called of parameters of childs are changed, then there notifyOnChange() method is called. The key and of the changed parameter (use getParam() to retrieve its actual value). Overload this function when special actions have to be taken on parameter changes.

Reimplemented in AbstractIAFController, ClassicReinforce, FFNNController, OdeConfig, AddSensors2RobotAdapter, Arm, CaterPillar, DefaultCaterPillar, Hand, Hexapod, HurlingSnake, RobotChain, Schlange, SchlangeServo, SchlangeServo2, Skeleton, SliderWheelie, Sphererobot3Masses, Uwo, VierBeiner, and PullToPointOperator.

bool parse | ( | FILE * | f,
|  | const char * | prefix = `0`,
|  | bool | traverseChildren = `true` |
| ) |  |  |

parses the configuration from the given file

void print | ( | FILE * | f,
|  | const char * | prefix,
|  | int | columns = `90`,
|  | bool | traverseChildren = `true` |
| ) |  |  | const

prints the keys, values and descriptions to the file. Each line is prefixed

Examples:
  directconnect/directconnect.cpp.

void printdescr | ( | FILE * | f,
|  | const char * | prefix,
|  | const paramkey & | key,
|  | int | columns,
|  | int | indent |
| ) |  |  | const`[protected]`

void removeConfigurable | ( | Configurable * | conf | ) | `[virtual]`

Removes a configurable as a child object.

Parameters:

  | conf | the instance to remove

bool restoreCfg | ( | const char * | filenamestem | ) | `[virtual]`

restores the key values paires from the file : filenamestem.cfg

void setName | ( | const paramkey & | name,
|  | bool | callSetNameOfInspectable = `true` |
| ) |  |  | `[virtual]`

Sets the name of the configurable.

Parameters:

  | name | the name to set
  | callSetNameOfInspectable | if true and if this instance is also inspectable, call automatically setNameOfInspectable(name).

bool setParam | ( | const paramkey & | key,
|  | paramval | val,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

sets the value of the given parameter or does nothing if unknown.

Reimplemented in MyRobot.

Examples:
  directconnect/directconnect.cpp, integration/main.cpp, and template_sphererobot/main.cpp.

void setParamBounds | ( | const paramkey & | key,
|  | paramintBounds | bounds,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

void setParamBounds | ( | const paramkey & | key,
|  | paramvalBounds | bounds,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

void setParamBounds | ( | const paramkey & | key,
|  | paramint | minBound,
|  | paramint | maxBound,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

void setParamBounds | ( | const paramkey & | key,
|  | paramval | minBound,
|  | paramval | maxBound,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

Sets the bounds (minBound and maxBound) of the given parameter.

Not useful for parambool. If minBound=maxBound, it is threated as that no bound is given.

void setParamDescr | ( | const paramkey & | key,
|  | const paramdescr & | descr,
|  | bool | traverseChildren = `true` |
| ) |  |  | `[virtual]`

sets a description for the given parameter

virtual void setRevision | ( | const paramkey & | revision | ) | `[inline, virtual]`

sets the revision Hint: { return "$ID$"; }

bool storeCfg | ( | const char * | filenamestem,
|  | const std::list< std::string > & | comments = `std::list<std::string>()` |
| ) |  |  | `[virtual]`

stores the key values paires into the file : filenamestem.cfg including the comments given in the list

## Member Data Documentation

const CallbackableType CALLBACK_CONFIGURABLE_CHANGED = 11`[static]`

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

- configurable.h
- configurable.cpp