Abstract superclass of all classes that encode objects. More...
#include <InstantIO/Encoder.h>
Public Member Functions | |
virtual | ~Encoder () |
Destroys the Encoder object. | |
virtual void | initialize (const std::string &label, const std::string &description) |
Initializes the Encoder object. | |
virtual BasicInSlot * | getInSlot () const |
Returns the InSlot we read the values that have to be encoded from. | |
virtual void | encode (std::ostream &os, const T &value)=0 |
Encodes objects. | |
Protected Member Functions | |
Encoder () | |
Creates a new Encoder object. | |
virtual TimeStamp | popAndEncode (std::ostream &os) |
Reads a value from the InSlot and encodes it into an output stream. |
Abstract superclass of all classes that encode objects.
The NetworkNode class uses encoders to encode values before they are sent to other InstantIO components on the network. Before any data type can be transferred via the network, an Encoder has to be written that transforms the data values to a system and hardware independent byte stream. For some frequently used data types, encoders already exist in the InstantIO package, but when you need to transfer your own data types, you have to implement an Encoder.
For example, let's say you want to transfer boolean values via the network (an Encoder 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 Encoder class and implements the abstract encode method:
class MyIntEncoder: public Encoder<bool> { virtual void encode(ostream &os, const bool &value) { os.put(value == true ? 1 : 0); } }
Then, you have to create a corresponding Decoder 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 Encoder (see documentation of the Codec class).
virtual void InstantIO::Encoder< T >::initialize | ( | const std::string & | label, | |
const std::string & | description | |||
) | [inline, virtual] |
Initializes the Encoder object.
Reimplemented from InstantIO::BasicEncoder.
virtual BasicInSlot* InstantIO::Encoder< T >::getInSlot | ( | ) | const [inline, virtual] |
Returns the InSlot we read the values that have to be encoded from.
Implements InstantIO::BasicEncoder.
virtual void InstantIO::Encoder< T >::encode | ( | std::ostream & | os, | |
const T & | value | |||
) | [pure virtual] |
Encodes objects.
This method encodes objects into their binary representation and writes this binary representation into an output stream. This method needs to be overwritten by your own implementations.
os | The output stream you write the system and hardware independent byte representation to. | |
value | The object you have to encode. |
virtual TimeStamp InstantIO::Encoder< T >::popAndEncode | ( | std::ostream & | os | ) | [inline, protected, virtual] |
Reads a value from the InSlot and encodes it into an output stream.
os | The stream we put the result into. |
Implements InstantIO::BasicEncoder.