stk::Marshal Struct Reference

Struct Marshal is a data packer for sending and receiving parallel messages. More...

#include <Marshal.hpp>

List of all members.

Public Types

enum  {
  TYPE_CHECK_NONE = 0x00000000,
  TYPE_CHECK_POD = 0x00000001,
  TYPE_CHECK_LIST = 0x00000002,
  TYPE_CHECK_VECTOR = 0x00000004,
  TYPE_CHECK_ALL = 0xFFFFFFFF
}
 

Enumeration to activate type checking for std classes and plain old data.


Public Member Functions

 Marshal (unsigned type_check=TYPE_CHECK_NONE)
 Creates a new Marshal instance for put-to operations.
 Marshal (const std::string &s)
 Creates a new Marshal instance for get-from operations.
std::string str () const
 Member function str returns the string of packed bytes created by put-to operations to the stream.
size_t size () const
 Member function size returns the byte count of the string of packed bytes creates by put-to operations to the stream.
void write (const char *address, size_t byte_count)
 Member function write writer bytes to the packed byte stream.
void read (char *address, size_t byte_count)
 Member function read reads bytes from the packed byte stream.
 operator void * () const
 Member function operator void * returns the state of the packed byte stream.

Public Attributes

std::stringstream stream
 Packed byte stream to put-to or get-from.
unsigned m_typeCheck
 Type checking to activate.

Detailed Description

Struct Marshal is a data packer for sending and receiving parallel messages.

The data put-to (<<) is appended to the stream as a string of bytes, likewise data gotten-from (>>) is extracted from the stream into the object as a string of bytes.

The write() and read() functions perform the data movements to and from the packed stream.

The common implementation is the create a << and >> operator for an object which properly appends and extracts the object's members.

The object can put-to and get-from it's typeid() to add type checking. This operation ensures that the data types being read was the data type written before the data is extracted. This type checking can be disabled since it may be desired to put-to an object of one type, but get-from into an object of an extractable but different type.

The TYPE_CHECK bit masks can be provided at put-to Marshal construction to activate the type checking. The Marshaller send the type check code as the first message to allow the get-from to initialize properly.

The put-to operator and get-from operators for plain old data, std::string, std::vector and std::list have been implemented. Additional ones could be added here, or left to the developer using the marshaller.

The stream and type_check members were left as public due to the extensive use. If this proves bothersome, getter/setter methods could be introduced.

Definition at line 49 of file Marshal.hpp.


Constructor & Destructor Documentation

stk::Marshal::Marshal ( const std::string &  s  )  [explicit]

Creates a new Marshal instance for get-from operations.

Parameters:
s a std::string constant variable of packed bytes to extract using the get-from operators.

Definition at line 162 of file Marshal.cpp.


Member Function Documentation

std::string stk::Marshal::str (  )  const

Member function str returns the string of packed bytes created by put-to operations to the stream.

Returns:
a std::string created from the packed byte stream.

Definition at line 172 of file Marshal.cpp.

size_t stk::Marshal::size (  )  const

Member function size returns the byte count of the string of packed bytes creates by put-to operations to the stream.

Returns:
a size_t in bytes of the packed byte stream.

Definition at line 179 of file Marshal.cpp.

void stk::Marshal::write ( const char *  address,
size_t  byte_count 
)

Member function write writer bytes to the packed byte stream.

Parameters:
byte_count a size_t value of the number of packed bytes to write.
address a char constant pointer to get the bytes from.

Definition at line 192 of file Marshal.cpp.

void stk::Marshal::read ( char *  address,
size_t  byte_count 
)

Member function read reads bytes from the packed byte stream.

Parameters:
byte_count a size_t value of the number of packed bytes to read.
address a char constant pointer to put the bytes to.

Definition at line 201 of file Marshal.cpp.

stk::Marshal::operator void * (  )  const

Member function operator void * returns the state of the packed byte stream.

Returns:
a void const pointer which is non-zero if status is good.

Definition at line 185 of file Marshal.cpp.


The documentation for this struct was generated from the following files:
Generated on Wed Apr 13 10:05:49 2011 for Sierra Toolkit by  doxygen 1.6.3