Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
Hg::MsgBuffer< StorageT > Class Template Reference

MsgBuffer Template Definition. This abstracts the behavior of the buffer with respect to the Byte-Order of the message. More...

#include <msg_buffer.h>

Public Member Functions

 MsgBuffer ()
 Default Constructor.
 
 MsgBuffer (size_t n)
 Fill Constructor. More...
 
 MsgBuffer (const MsgBuffer &rhs)
 Copy Constructor. More...
 
 ~MsgBuffer ()
 Destructor.
 
void assign (const_pointer pBuffer, size_t n)
 Assigns the contents of an incoming raw memory buffer to the message buffer. More...
 
size_t capacity () const
 Return the number of bytes reserved for use by this buffer. More...
 
void clear ()
 Releases any resources associated with this object.
 
MsgBuffer clone () const
 Creates a full copy of the message buffer. More...
 
const_pointer data () const
 Provides access to the packed memory buffer. More...
 
bool empty () const
 Indicates if memory is currently managed by this buffer. More...
 
template<typename T >
size_t get_data (T &value, std::ptrdiff_t pos) const
 Parameterized function that returns data from a specified offset in the buffer. More...
 
size_t get_range (void *pBuffer, size_t length, size_t pos) const
 Parameterized function that reads a range of data from the buffer. More...
 
std::ptrdiff_t offset () const
 Returns the offset used to access the buffer. More...
 
void offset (std::ptrdiff_t new_offset)
 Assigns a new base offset for memory access to this object. More...
 
MsgBufferoperator= (const MsgBuffer &rhs)
 Assignment Operator. More...
 
void resize (size_t n)
 Resizes the buffer to contain n elements. More...
 
template<typename T >
size_t set_data (const T &value, size_t pos)
 Parameterized function that writes data to a specified offset in the buffer. More...
 
template<typename InputIt >
size_t set_range (InputIt first, InputIt last, size_t pos)
 Parameterized function that writes a range of data to the buffer. More...
 
size_t size () const
 Reports the current size of the buffer in use. More...
 
void zero ()
 Zeroes the contents of the buffer if they have been assigned.
 

Detailed Description

template<typename StorageT>
class Hg::MsgBuffer< StorageT >

MsgBuffer Template Definition. This abstracts the behavior of the buffer with respect to the Byte-Order of the message.

Template Parameters
StorageT[typename] The storage_t that manages the type of object used in the underlying buffer for the packet data. This policy also provides the capabilities to read/write to the buffer.

Definition at line 34 of file msg_buffer.h.

Constructor & Destructor Documentation

template<typename StorageT>
Hg::MsgBuffer< StorageT >::MsgBuffer ( size_t  n)
inlineexplicit

Fill Constructor.

Parameters
nThe number of bytes to allocate for the buffer.
valThe value to fill each item in the allocated buffer if supplied.

Definition at line 63 of file msg_buffer.h.

template<typename StorageT>
Hg::MsgBuffer< StorageT >::MsgBuffer ( const MsgBuffer< StorageT > &  rhs)
inline

Copy Constructor.

Parameters
rhsThe input object to be copied.
Note
This object's copy constructor only performs a shallow copy of the message buffer. Use the clone operation to make a separate copy of the buffer.

Definition at line 85 of file msg_buffer.h.

Member Function Documentation

template<typename StorageT>
void Hg::MsgBuffer< StorageT >::assign ( const_pointer  pBuffer,
size_t  n 
)
inline

Assigns the contents of an incoming raw memory buffer to the message buffer.

Parameters
pBufferA memory buffer whose contents will be assigned to this message object. The values of the buffer are copied into the message.
nThe number of bytes held in p_buffer.

Definition at line 209 of file msg_buffer.h.

template<typename StorageT>
size_t Hg::MsgBuffer< StorageT >::capacity ( ) const
inline

Return the number of bytes reserved for use by this buffer.

Returns
The allocated buffer size is returned. This packet buffer must be valid for a non-zero value to be returned.

Definition at line 132 of file msg_buffer.h.

template<typename StorageT>
MsgBuffer Hg::MsgBuffer< StorageT >::clone ( ) const
inline

Creates a full copy of the message buffer.

Returns
A deep copy of this objects packet buffer.
Note
clone performs a buffer allocation according to the storage policy provided to the MsgBuffer. Therefore a new memory buffer is created for the cloned copy to exist within.

Definition at line 451 of file msg_buffer.h.

template<typename StorageT>
const_pointer Hg::MsgBuffer< StorageT >::data ( ) const
inline

Provides access to the packed memory buffer.

Returns
Returns a constant pointer to the buffer that contains the packed memory. 0 is returned if there is no memory associated with the buffer.

Definition at line 183 of file msg_buffer.h.

template<typename StorageT>
bool Hg::MsgBuffer< StorageT >::empty ( ) const
inline

Indicates if memory is currently managed by this buffer.

Returns
true - The buffer is empty. false- There is memory allocated and managed by this buffer.

Definition at line 121 of file msg_buffer.h.

template<typename StorageT>
template<typename T >
size_t Hg::MsgBuffer< StorageT >::get_data ( T &  value,
std::ptrdiff_t  pos 
) const
inline

Parameterized function that returns data from a specified offset in the buffer.

Template Parameters
T[typename] The parameterized type to be returned to the caller.
Parameters
valueAccepts the value read from the packet buffer.
posThe offset from the beginning of the buffer to read the output value.
Returns
The number of bytes read from the buffer is returned. It is possible for a successful case to return 0.

Definition at line 264 of file msg_buffer.h.

template<typename StorageT>
size_t Hg::MsgBuffer< StorageT >::get_range ( void *  pBuffer,
size_t  length,
size_t  pos 
) const
inline

Parameterized function that reads a range of data from the buffer.

Template Parameters
T[typename] The parameterized type to be read by the caller.
Parameters
pBufferPointer to the first element in the array to be written into.
lengthThe number of bytes to read in. pBuffer must contain at least length number of bytes.
posThe offset from the beginning of the buffer to read the input value.
Returns
The number of bytes read from the buffer is returned. It is possible for a successful case to return 0.

Definition at line 310 of file msg_buffer.h.

template<typename StorageT>
std::ptrdiff_t Hg::MsgBuffer< StorageT >::offset ( ) const
inline

Returns the offset used to access the buffer.

Returns the offset used to access the buffer relative to the first index in the buffer. The default offset is zero. Alternate offsets are allowed to facilitate nested packet structures as well as dynamically formatted structures.

Returns
A number of bytes greater than 0 is returned.

Definition at line 236 of file msg_buffer.h.

template<typename StorageT>
void Hg::MsgBuffer< StorageT >::offset ( std::ptrdiff_t  new_offset)
inline

Assigns a new base offset for memory access to this object.

Parameters
new_offsetThe offset from the beginning of the supplied buffer.

Definition at line 246 of file msg_buffer.h.

template<typename StorageT>
MsgBuffer& Hg::MsgBuffer< StorageT >::operator= ( const MsgBuffer< StorageT > &  rhs)
inline

Assignment Operator.

Parameters
rhs(right-hand side) The input object to be copied.
Note
This object's copy constructor only performs a shallow copy of the message buffer. Use the clone operation to make a separate copy of the buffer.

Definition at line 108 of file msg_buffer.h.

template<typename StorageT>
void Hg::MsgBuffer< StorageT >::resize ( size_t  n)
inline

Resizes the buffer to contain n elements.

Parameters
nThe number of elements to allocate for the buffer.
valOptional value to be copied into each element allocated.

Definition at line 165 of file msg_buffer.h.

template<typename StorageT>
template<typename T >
size_t Hg::MsgBuffer< StorageT >::set_data ( const T &  value,
size_t  pos 
)
inline

Parameterized function that writes data to a specified offset in the buffer.

Template Parameters
T[typename] The parameterized type to be written by the caller.
Parameters
valueContains the value to write to the packet buffer.
posThe offset from the beginning of the buffer to write the input value.
Returns
The number of bytes written to the buffer is returned. It is possible for a successful case to return 0.

Definition at line 354 of file msg_buffer.h.

template<typename StorageT>
template<typename InputIt >
size_t Hg::MsgBuffer< StorageT >::set_range ( InputIt  first,
InputIt  last,
size_t  pos 
)
inline

Parameterized function that writes a range of data to the buffer.

Template Parameters
T[typename] The parameterized type to be written by the caller.
Parameters
firstContains the first item to write to the buffer.
lastContains the item one past the last item to write. This item may point to an element that is not valid to de-reference. Similar to C+++ Standard Library.

Last must be greater than than the first time, and they must be part of the same range of elements otherwise the behavior is undefined.

Parameters
posThe offset from the beginning of the buffer to write the input value.
Returns
The number of bytes written to the buffer is returned. It is possible for a successful case to return 0.

Definition at line 405 of file msg_buffer.h.

template<typename StorageT>
size_t Hg::MsgBuffer< StorageT >::size ( ) const
inline

Reports the current size of the buffer in use.

Returns
The number of bytes in use in the allocated buffer. If there is no internal buffer, 0 is returned.

Definition at line 143 of file msg_buffer.h.


The documentation for this class was generated from the following file: