WSF
UtBuffer Class Reference

#include <UtBuffer.hpp>

Public Member Functions

 UtBuffer (int aBytes)
 Construct the buffer with a grow-able buffer of size aBytes.
 UtBuffer (char *aData, int aBytes, bool aCanGrow=false)
 Construct the buffer with a user buffer, see SetBuffer().
 UtBuffer (const UtBuffer &aSrc)
 Construct a copy of aSrc.
 UtBuffer ()
 Construct the buffer with a default size, and allow growth.
UtBufferoperator= (const UtBuffer &)=delete
 ~UtBuffer ()
void EnableByteSwap (bool aSwapBytes)
 Disable or Enable byte swapping.
void SetBigEndian ()
 Enable byte swapping if the local machine is little-endian.
void SetLittleEndian ()
 Enable byte-swapping if the local machine is big-endian.
void SetNativeByteOrder ()
 Disable byte swapping.
void Dispose ()
void SetBuffer (char *aData, size_t aBytes, bool aCanGrow=false)
void SetPutPos (size_t aPos)
 Set the current offset used to put data.
size_t & GetPutPos ()
 Get the current offset used to put data.
size_t GetPutPos () const
 Set the current offset used to put data.
void SetGetPos (size_t aPos)
 Set the current offset used to get data.
size_t & GetGetPos ()
 Get the current offset used to get data.
size_t GetGetPos () const
 Get the current offset used to get data.
char * GetBuffer ()
 Returns a pointer to the internal buffer.
const char * GetBuffer () const
 Returns a pointer to the internal buffer.
size_t GetBytes () const
 Returns the size of the internal buffer.
void PutRaw (const char *aBuffer, size_t aBytes)
 Writes a sequence of aBytes to the buffer.
void GetRaw (char *aBuffer, size_t aBytes)
 Reads a sequence of aBytes to the buffer.
void Reset ()
 Set the put/get positions to the start of the buffer.
void Move (size_t aBeginOffset, size_t aEndOffset, size_t aNewBegin)
 Move a set of bytes within the buffer.
void Grow (size_t aNewSize)
 Grow the buffer so it is at least as large as aNewSize.
void GrowBy (size_t aBytes)
 Grow the buffer by an increment of at least aBytes.
size_t GetValidBytes () const
 Return the difference between the write position and the read position.
void SwapBuffer (UtBuffer &aRhs)
 Swap the internal buffers between this and aRhs.
void * ReleaseBuffer ()
template<typename T>
void Put (const T &aVal)
template<typename T>
void Get (T &aVal)
bool CheckPutSpace (size_t aPutSize)

Static Public Attributes

static const int cDEFAULT_BUFFER_SIZE = 1024

Protected Member Functions

template<int BYTES>
void PutP (const char *aBuffer)
template<int BYTES>
void GetP (char *aBuffer)

Protected Attributes

char * mBuffer
size_t mBytes
size_t mGetPos
size_t mPutPos
bool mCanGrow
bool mSwapBytes

Detailed Description

A simple buffer with operations to read/write to memory. Note: Put methods will grow the buffer if the 'grow' option is set. Otherwise, all Put and Get methods require the user to know that there is enough space to do the operation!

Constructor & Destructor Documentation

◆ UtBuffer() [1/4]

UtBuffer::UtBuffer ( int aBytes)
inline

Construct the buffer with a grow-able buffer of size aBytes.

References mBuffer, mCanGrow, SetBigEndian(), and SetBuffer().

Referenced by operator=(), SwapBuffer(), and UtBuffer().

◆ UtBuffer() [2/4]

UtBuffer::UtBuffer ( char * aData,
int aBytes,
bool aCanGrow = false )
inline

Construct the buffer with a user buffer, see SetBuffer().

References mBuffer, mCanGrow, SetBigEndian(), and SetBuffer().

◆ UtBuffer() [3/4]

UtBuffer::UtBuffer ( const UtBuffer & aSrc)
inline

Construct a copy of aSrc.

References mBuffer, mBytes, mCanGrow, mGetPos, mPutPos, mSwapBytes, and UtBuffer().

◆ UtBuffer() [4/4]

UtBuffer::UtBuffer ( )
inline

Construct the buffer with a default size, and allow growth.

References cDEFAULT_BUFFER_SIZE, mBuffer, mCanGrow, SetBigEndian(), and SetBuffer().

◆ ~UtBuffer()

UtBuffer::~UtBuffer ( )
inline

References Dispose().

Member Function Documentation

◆ CheckPutSpace()

bool UtBuffer::CheckPutSpace ( size_t aPutSize)
inline

◆ Dispose()

void UtBuffer::Dispose ( )
inline

References mBuffer, and mCanGrow.

Referenced by SetBuffer(), and ~UtBuffer().

◆ EnableByteSwap()

void UtBuffer::EnableByteSwap ( bool aSwapBytes)
inline

Disable or Enable byte swapping.

References mSwapBytes.

Referenced by SetBigEndian(), SetLittleEndian(), and SetNativeByteOrder().

◆ Get()

template<typename T>
void UtBuffer::Get ( T & aVal)
inline

Get a basic type from the buffer. This should only be used for basic types (char, int, float) This will perform a byte-swap if that option is enabled

References GetP().

◆ GetBuffer() [1/2]

char * UtBuffer::GetBuffer ( )
inline

Returns a pointer to the internal buffer.

References mBuffer.

Referenced by UtPackMessageStream::ReadMessageFromIStream(), and UtPackMessageStreamO::Write().

◆ GetBuffer() [2/2]

const char * UtBuffer::GetBuffer ( ) const
inline

Returns a pointer to the internal buffer.

References mBuffer.

◆ GetBytes()

size_t UtBuffer::GetBytes ( ) const
inline

Returns the size of the internal buffer.

References mBytes.

◆ GetGetPos() [1/2]

size_t & UtBuffer::GetGetPos ( )
inline

Get the current offset used to get data.

References mGetPos.

◆ GetGetPos() [2/2]

size_t UtBuffer::GetGetPos ( ) const
inline

Get the current offset used to get data.

References mGetPos.

◆ GetP()

template<int BYTES>
void UtBuffer::GetP ( char * aBuffer)
inlineprotected

References mBuffer, mGetPos, and mSwapBytes.

Referenced by Get().

◆ GetPutPos() [1/2]

size_t & UtBuffer::GetPutPos ( )
inline

Get the current offset used to put data.

References mPutPos.

Referenced by UtPackMessageStream::ReadMessageFromIStream(), and UtPackMessageStreamO::Write().

◆ GetPutPos() [2/2]

size_t UtBuffer::GetPutPos ( ) const
inline

Set the current offset used to put data.

References mPutPos.

◆ GetRaw()

void UtBuffer::GetRaw ( char * aBuffer,
size_t aBytes )
inline

Reads a sequence of aBytes to the buffer.

References mBuffer, and mGetPos.

◆ GetValidBytes()

size_t UtBuffer::GetValidBytes ( ) const
inline

Return the difference between the write position and the read position.

References mGetPos, and mPutPos.

◆ Grow()

void UtBuffer::Grow ( size_t aNewSize)
inline

Grow the buffer so it is at least as large as aNewSize.

References GrowBy(), and mBytes.

◆ GrowBy()

void UtBuffer::GrowBy ( size_t aBytes)

Grow the buffer by an increment of at least aBytes.

Enlarges the buffer to a new size.

References mBuffer, and mBytes.

Referenced by CheckPutSpace(), and Grow().

◆ Move()

void UtBuffer::Move ( size_t aBeginOffset,
size_t aEndOffset,
size_t aNewBegin )

Move a set of bytes within the buffer.

References mBuffer.

◆ operator=()

UtBuffer & UtBuffer::operator= ( const UtBuffer & )
delete

References UtBuffer().

◆ Put()

template<typename T>
void UtBuffer::Put ( const T & aVal)
inline

Put a basic type into the buffer. This should only be used for basic types (char, int, float). This will perform a byte-swap if that option is enabled

References PutP().

Referenced by UtPackMessageStreamO::Write(), and UtPackMessageStream::WriteMessageToOStream().

◆ PutP()

template<int BYTES>
void UtBuffer::PutP ( const char * aBuffer)
inlineprotected

References CheckPutSpace(), mBuffer, mPutPos, and mSwapBytes.

Referenced by Put().

◆ PutRaw()

void UtBuffer::PutRaw ( const char * aBuffer,
size_t aBytes )
inline

Writes a sequence of aBytes to the buffer.

References CheckPutSpace(), mBuffer, and mPutPos.

◆ ReleaseBuffer()

void * UtBuffer::ReleaseBuffer ( )
inline

References mBuffer, and mBytes.

◆ Reset()

void UtBuffer::Reset ( )
inline

Set the put/get positions to the start of the buffer.

References mGetPos, and mPutPos.

Referenced by UtPackMessageStreamO::Write(), and UtPackMessageStream::WriteMessageToOStream().

◆ SetBigEndian()

void UtBuffer::SetBigEndian ( )

Enable byte swapping if the local machine is little-endian.

Enables translation of calls to Put() and Get() to/from big endian.

References EnableByteSwap().

Referenced by UtBuffer(), UtBuffer(), and UtBuffer().

◆ SetBuffer()

void UtBuffer::SetBuffer ( char * aData,
size_t aBytes,
bool aCanGrow = false )
inline

Use a user-created buffer.

Parameters
aDataPointer to the buffer
aBytesLength of the buffer in bytes
aCanGrowIf 'true', UtBuffer takes ownership of the buffer and allows resizing If 'false', UtBuffer will not delete the buffer or resize.

References Dispose(), mBuffer, mBytes, mCanGrow, mGetPos, and mPutPos.

Referenced by UtBuffer(), UtBuffer(), and UtBuffer().

◆ SetGetPos()

void UtBuffer::SetGetPos ( size_t aPos)
inline

Set the current offset used to get data.

References mGetPos.

Referenced by UtPackMessageStreamO::Write().

◆ SetLittleEndian()

void UtBuffer::SetLittleEndian ( )

Enable byte-swapping if the local machine is big-endian.

References EnableByteSwap().

◆ SetNativeByteOrder()

void UtBuffer::SetNativeByteOrder ( )

Disable byte swapping.

Configures Put() and Get() to use native byte ordering.

References EnableByteSwap().

◆ SetPutPos()

void UtBuffer::SetPutPos ( size_t aPos)
inline

◆ SwapBuffer()

void UtBuffer::SwapBuffer ( UtBuffer & aRhs)
inline

Swap the internal buffers between this and aRhs.

References mBuffer, mBytes, mCanGrow, mGetPos, mPutPos, std::swap(), and UtBuffer().

Member Data Documentation

◆ cDEFAULT_BUFFER_SIZE

const int UtBuffer::cDEFAULT_BUFFER_SIZE = 1024
static

Referenced by UtBuffer().

◆ mBuffer

◆ mBytes

size_t UtBuffer::mBytes
protected

◆ mCanGrow

bool UtBuffer::mCanGrow
protected

◆ mGetPos

size_t UtBuffer::mGetPos
protected

◆ mPutPos

◆ mSwapBytes

bool UtBuffer::mSwapBytes
protected

Referenced by EnableByteSwap(), GetP(), PutP(), and UtBuffer().


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved