Keeps information about Node fields. More...
#include <InstantIO/Field.h>
Public Member Functions | |
Field (const std::string &name, const std::string &description, const std::string &defaultValue, const BasicFieldAccessor &fieldAccessor) | |
Creates a new Field object. | |
Field (const Field &other) | |
Creates a new Field object that is an exact copy of another Field object. | |
~Field () | |
Destroys the Field object. | |
const std::string & | getName () const |
Returns the name of the field. | |
const std::string & | getDescription () const |
Returns the description of the field. | |
const std::string & | getDefaultValue () const |
Returns the default value of the field. | |
void | set (Node &node, const std::string &value) const |
Sets the value of a field. | |
std::string | get (const Node &node) const |
Returns the value of the field. | |
bool | sameValue (const Node &node, const std::string &value) const |
Checks if a field is set to given value. |
Keeps information about Node fields.
Most Nodes need some kind of parameters when they are started, e.g. which serial port they should use to communicate with a device. The Field class contains meta information that describes one parameter of a Node. The meta information consists of:
For example, let's say you want to create a Node that operates a device that is connected to a serial port of the computer. So, you need to specify the number of the serial port and the baud rate. First, you have to write methods for setting and getting the port number and the baud rate:
class MyNode: public Node { public: ... void setPort(int port); int getPort(); void setBaudRate(int port); int getBaudRate(); ... };
Then, you have to create instances of the Field class that describe the parameters. Usually, you do this by creating a static array in the Node class:
class MyNode: public Node { public: ... static Field fields[2] = { Field( "port", "The serial port the device is connected to", "0", FieldAccessor<MyNode, int>(&MyNode::setPort, &MyNode::getPort) ), Field( "BaudRate", "The baud rate the device is operating at", "115200", FieldAccessor<MyNode, int>(&MyNode::setBaudRate, &MyNode::getBaudRate) ) }; ... };
Finally, you have to specify the fields when you create the Instance of the NodeType object that contains meta information about the Node:
static NodeType myType( "MyNode", &MyNode::create, "Example Node", 0, "Patrick D&auml;hne", MyNode::fields sizeof(MyNode::fields) / sizeof(Field));
InstantIO::Field::Field | ( | const std::string & | name, | |
const std::string & | description, | |||
const std::string & | defaultValue, | |||
const BasicFieldAccessor & | fieldAccessor | |||
) | [inline] |
Creates a new Field object.
name | The name of the field. The name is used to identify the field. | |
description | A description of the field. This description is not used by the system in any way. It solely serves documentation purposes. It contains information about the field in a human-readable way. Some user interfaces for managing the InstantIO system display the description to the user. | |
defaultValue | The default value of the field. The default value is a string representation of the value the field contains when the user does not explicitly specify a value. | |
fieldAccessor | A FieldAccessor object used to access the contents of the field. |
InstantIO::Field::Field | ( | const Field & | other | ) | [inline] |
Creates a new Field object that is an exact copy of another Field object.
other | The other Field object. |
const std::string& InstantIO::Field::getName | ( | ) | const [inline] |
Returns the name of the field.
The name is used to identify the field.
const std::string& InstantIO::Field::getDescription | ( | ) | const [inline] |
Returns the description of the field.
The description of the field is not used by the system in any way. It solely serves documentation purposes. It contains information about the field in a human-readable way. Some user interfaces for managing the InstantIO system display the description to the user.
const std::string& InstantIO::Field::getDefaultValue | ( | ) | const [inline] |
Returns the default value of the field.
The default value is a string representation of the value the field contains when the user does not explicitly specify a value.
void InstantIO::Field::set | ( | Node & | node, | |
const std::string & | value | |||
) | const [inline] |
std::string InstantIO::Field::get | ( | const Node & | node | ) | const [inline] |
bool InstantIO::Field::sameValue | ( | const Node & | node, | |
const std::string & | value | |||
) | const [inline] |
Checks if a field is set to given value.
node | The Node that contains the field. | |
value | The value we compare the field with. |