InstantIO::Encoder< T > Class Template Reference

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

#include <InstantIO/Encoder.h>

Inheritance diagram for InstantIO::Encoder< T >:
InstantIO::BasicEncoder

List of all members.

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

Detailed Description

template<class T>
class InstantIO::Encoder< T >

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

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

Member Function Documentation

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

Initializes the Encoder object.

Parameters:
label The label of the InSlot
description The description of the InSlot

Reimplemented from InstantIO::BasicEncoder.

template<class T>
virtual BasicInSlot* InstantIO::Encoder< T >::getInSlot (  )  const [inline, virtual]

Returns the InSlot we read the values that have to be encoded from.

Returns:
The InSlot

Implements InstantIO::BasicEncoder.

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

Parameters:
os The output stream you write the system and hardware independent byte representation to.
value The object you have to encode.
template<class T>
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.

Parameters:
os The stream we put the result into.
Returns:
The time stamp of the data value

Implements InstantIO::BasicEncoder.


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