InstantIO::Decoder< T > Class Template Reference

Abstract superclass of all classes that decode objects. More...

#include <InstantIO/Decoder.h>

Inheritance diagram for InstantIO::Decoder< T >:
InstantIO::BasicDecoder

List of all members.

Public Member Functions

virtual ~Decoder ()
 Destroys the Decoder object.
virtual BasicOutSlotgetOutSlot () 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.

Detailed Description

template<class T>
class InstantIO::Decoder< T >

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).

Author:
Patrick Dähne
See also:
NetworkNode NetworkNode
Encoder Encoder
Codec Codec

Member Function Documentation

template<class T >
virtual BasicOutSlot* InstantIO::Decoder< T >::getOutSlot (  )  const [inline, virtual]

Returns the OutSlot we write the decoded values to.

Returns:
The OutSlot

Implements InstantIO::BasicDecoder.

template<class T >
virtual void InstantIO::Decoder< T >::initialize ( const std::string &  label,
const std::string &  description 
) [inline, virtual]

Initializes the Decoder object.

Parameters:
label The label of the OutSlot
description The description of the OutSlot

Reimplemented from InstantIO::BasicDecoder.

template<class T >
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.

Parameters:
is The input stream you read the system and hardware independent byte stream from.
Returns:
The decoded object you create from the byte stream
template<class T >
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.

Parameters:
is The stream we get the binary representation from.
timeStamp The timestamp of the data value.

Implements InstantIO::BasicDecoder.


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