ReplicaNet and RNLobby  1
Public Member Functions | List of all members
DynamicMessageHelper Class Reference

#include <MessageHelper.h>

Inheritance diagram for DynamicMessageHelper:
Inheritance graph
[legend]
Collaboration diagram for DynamicMessageHelper:
Collaboration graph
[legend]

Public Member Functions

 DynamicMessageHelper ()
 
 DynamicMessageHelper (const int size)
 
 DynamicMessageHelper (const void *message, const int size)
 
virtual ~DynamicMessageHelper ()
 
void SetBufferSize (const int size=1024)
 
int GetBufferSize (void)
 
void SetSize (const int size)
 
void AddVariable (const void *variable, const int size)
 
void AddData (const void *data, const int size)
 
void FreeBuffer (void)
 
void EnsureBufferAllocated (void)
 
bool Write (const char *filename, const bool rawData=false)
 
bool Read (const char *filename, const bool rawData=false)
 
template<typename T >
void operator<< (const T &rhs)
 
template<typename T >
void operator>> (T &rhs)
 
void operator<< (const char *rhs)
 
void operator<< (const std::string &rhs)
 
void operator>> (std::string &rhs)
 
void operator<< (const DynamicMessageHelper &rhs)
 
void operator>> (DynamicMessageHelper &rhs)
 
bool operator== (const DynamicMessageHelper &rhs) const
 
bool operator!= (const DynamicMessageHelper &rhs) const
 
void operator<< (const bool &rhs)
 
void operator>> (bool &rhs)
 
bool ReadAsHex (const std::string &data)
 
- Public Member Functions inherited from MessageHelper
 MessageHelper ()
 
virtual ~MessageHelper ()
 
void SetBuffer (void *const buffer)
 
void * GetBuffer (void) const
 
void * GetCurrentPosition (void) const
 
void GetVariable (void *const variable, const int size)
 
void GetData (void *const data, const int size)
 
void SkipData (const int size)
 
int GetSize (void) const
 
void SetSize (const int size)
 
void AddInteger (const int value)
 
void AddFloat (const float value)
 
int GetInteger (void)
 
float GetFloat (void)
 
std::string DumpAsHex (const bool csv=true) const
 
void SetGuardSize (const int size=-1)
 
void SanityCheckGuardSize (const int newSize=0)
 
int GetLastSizeAdded (void) const
 
template<typename T >
void operator<< (const T &rhs)
 
template<typename T >
void operator>> (T &rhs)
 
void operator<< (const char *rhs)
 
void operator<< (const std::string &rhs)
 
void operator>> (std::string &rhs)
 
void operator<< (const bool &rhs)
 
void operator>> (bool &rhs)
 

Additional Inherited Members

- Static Public Member Functions inherited from MessageHelper
static void AddVariable (void *buffer, const void *variable, const int size)
 Adds data to a buffer with endian checking.
 
static void GetVariable (const void *buffer, void *const variable, const int size)
 Adds data from a buffer with endian checking.
 
static int GetInt (const void *buffer, const int offset)
 
static short GetShort (const void *buffer, const int offset)
 
static void SetInt (void *buffer, const int offset, const int value)
 
static void SetShort (void *buffer, const int offset, const short value)
 
static std::string DumpAsHex (const void *data, const int size, const bool csv=true)
 
- Protected Attributes inherited from MessageHelper
int mLastSizeAdded
 

Detailed Description

This extends the interface provided by MessageHelper to include a data buffer that dynamically grows to accommodate new data.

Constructor & Destructor Documentation

The ctor performs some basic initialisation

DynamicMessageHelper ( const int  size)

The ctor performs some basic initialisation.

Parameters
sizeIf size is greater than 0 then the buffer is allocated to be that size.
DynamicMessageHelper ( const void *  message,
const int  size 
)

The ctor performs some basic initialisation.

Parameters
messageIf message is not null then the data is copied to the message for size bytes. If message is null then a buffer of size is allocated but there is no copy of data.
sizeIf size is greater than 0 then the buffer is allocated to be that size.
virtual ~DynamicMessageHelper ( )
virtual

The dtor makes sure everything is tidy

Member Function Documentation

void AddData ( const void *  data,
const int  size 
)
virtual

Adds a data block of a specified size to the message buffer without using any endian checking

Parameters
datathe pointer to the data
sizethe size of the data

Reimplemented from MessageHelper.

void AddVariable ( const void *  variable,
const int  size 
)
virtual

Adds a variable of a specified size to the message buffer while using an endian check to preserve the value between platforms with different endian formats

Parameters
variablethe pointer to the variable
sizethe size of the data

Reimplemented from MessageHelper.

void EnsureBufferAllocated ( void  )

This ensures the buffer is allocated.

void FreeBuffer ( void  )

This frees the buffer used by this class and sets the current size to 0. This also calls SetBufferSize() to reset the size to the default value.

int GetBufferSize ( void  )

Gets the value configured by SetBufferSize().

Returns
The value configured by SetBufferSize().
bool Read ( const char *  filename,
const bool  rawData = false 
)

Reads the contents of a file to this class. GetBufferSize() will return the size of the message in the file and GetSize() will return 0.

Parameters
rawDataIf true this will read the raw data of the file and not check for the DynamicMessageHelper file header.
bool ReadAsHex ( const std::string &  data)

Reads a hex encoded buffer without commas and converts it to binary data from the current position of the buffer. If there is an error reading the data then the result of the buffer is undefined.

Returns
Success returns true, failure returns false.
void SetBufferSize ( const int  size = 1024)

Sets the data buffer size to use while constructing or deconstructing this message. Any previous buffer is freed. The buffer is not allocated immediately, buffer allocation happens when data is added to the buffer. To force an allocation of the buffer use EnsureBufferAllocated().

Parameters
bufferthe buffer pointer to set. The default size is 1024 bytes.
void SetSize ( const int  size)

Sets the current size of the message in bytes, allocating a buffer if required.

Parameters
thesize of the message in bytes
bool Write ( const char *  filename,
const bool  rawData = false 
)

Writes the contents of this class to a file.

Parameters
rawDataIf true this will write the raw data of the file and not add the DynamicMessageHelper file header.