Abstract superclass of all classes that decode objects. More...
#include <InstantIO/Decoder.h>
Public Member Functions | |
virtual | ~Decoder () |
Destroys the Decoder object. | |
virtual BasicOutSlot * | getOutSlot () const |
Returns the OutSlot we write the decoded values to. | |
virtual void | initialize (const std::string &label, const std::string &description) |
Initializes the Decoder object. | |
virtual T | decode (std::istream &is)=0 |
Decodes objects. | |
Protected Member Functions | |
Decoder () | |
Creates a new Decoder object. | |
virtual void | decodeAndPush (std::istream &is, TimeStamp timeStamp) |
Gets the binary representation of an object from a stream, decodes the object, and writes it to the OutSlot. |
Abstract superclass of all classes that decode objects.
The NetworkNode class uses decoders to decode values received from other InstantIO components on the network. Before any data type can be transferred via the network, a Decoder has to be written that transforms a system and hardware independent byte stream to data values. For some frequently used data types, decoders already exist in the InstantIO package, but when you need to transfer your own data types, you have to implement a Decoder.
For example, let's say you want to transfer boolean values via the network (a Decoder for boolean of course already exists in the InstantIO package, but for the sake of demonstrating the procedure whe nevertheless demonstrate how to create your own). First, you have to create a class that inherits from the Decoder class and implements the abstract decode method:
class MyIntDecoder: public Decoder<bool> { virtual bool decode(istream &is) { int c = is.get(); return c != 0; } }
Then, you have to create a corresponding Encoder class (see the documentation of this class for more information about how to do that). Finally, you have to create an instance of the Codec class so that the NetworkNode can actually access your Decoder (see documentation of the Codec class).
virtual BasicOutSlot* InstantIO::Decoder< T >::getOutSlot | ( | ) | const [inline, virtual] |
Returns the OutSlot we write the decoded values to.
Implements InstantIO::BasicDecoder.
virtual void InstantIO::Decoder< T >::initialize | ( | const std::string & | label, | |
const std::string & | description | |||
) | [inline, virtual] |
Initializes the Decoder object.
Reimplemented from InstantIO::BasicDecoder.
virtual T InstantIO::Decoder< T >::decode | ( | std::istream & | is | ) | [pure virtual] |
Decodes objects.
This method reads the binary representation of objects from an input stream and decodes objects from this binary representation. This method needs to be overwritten by your own implementations.
is | The input stream you read the system and hardware independent byte stream from. |
virtual void InstantIO::Decoder< T >::decodeAndPush | ( | std::istream & | is, | |
TimeStamp | timeStamp | |||
) | [inline, protected, virtual] |
Gets the binary representation of an object from a stream, decodes the object, and writes it to the OutSlot.
is | The stream we get the binary representation from. | |
timeStamp | The timestamp of the data value. |
Implements InstantIO::BasicDecoder.