InstantIO::Field Class Reference

Keeps information about Node fields. More...

#include <InstantIO/Field.h>

List of all members.

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.

Detailed Description

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&amp;auml;hne",
   MyNode::fields
   sizeof(MyNode::fields) / sizeof(Field));
 

Author:
Patrick Dähne
See also:
Node Node
NodeType NodeType

Constructor & Destructor Documentation

InstantIO::Field::Field ( const std::string &  name,
const std::string &  description,
const std::string &  defaultValue,
const BasicFieldAccessor fieldAccessor 
) [inline]

Creates a new Field object.

Parameters:
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.

Parameters:
other The other Field object.

Member Function Documentation

const std::string& InstantIO::Field::getName (  )  const [inline]

Returns the name of the field.

The name is used to identify the field.

Returns:
The name of 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.

Returns:
The description of the field.
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.

Returns:
The default value.
void InstantIO::Field::set ( Node node,
const std::string &  value 
) const [inline]

Sets the value of a field.

Use this method to set fields of a Node.

Parameters:
node The Node object whose field you want to set.
value A string representation of the new value of the field.
std::string InstantIO::Field::get ( const Node node  )  const [inline]

Returns the value of the field.

Use this method to read fields of a Node.

Parameters:
node The Node object whose field you want to get.
Returns:
A string representation of the field's value.
bool InstantIO::Field::sameValue ( const Node node,
const std::string &  value 
) const [inline]

Checks if a field is set to given value.

Parameters:
node The Node that contains the field.
value The value we compare the field with.
Returns:
true when the field has the given value, false otherwise.

The documentation for this class was generated from the following file:
Generated on Thu Jul 31 17:17:32 2014 by  doxygen 1.6.3