C12Adapter Opensource C++ Interface
MBuffer Class Reference

Buffer, a byte string with extra manipulation facilities. More...

Inheritance diagram for MBuffer:

Public Member Functions

 MBuffer ()
 Constructor of an empty unallocated buffer. More...
 
 ~MBuffer ()
 Attention, the destructor is not virtual.
 
MByteStringAccessAllBytes ()
 Access all bytes in the buffer.
 
const MByteStringAccessAllBytes () const
 Constant access all bytes in the buffer.
 
void Resize (unsigned size)
 Resize buffer. More...
 
void Reserve (unsigned capacity)
 Reserve the given number of bytes in the whole buffer. More...
 
void Clear ()
 Make buffer size equal to zero.
 
void Assign (unsigned size, char c)
 Assign the whole buffer with the given character of the given length. More...
 
void Assign (const MByteString &data)
 Assign the whole buffer with the given data. More...
 
void Assign (const char *buff, unsigned size)
 Assign the whole buffer with the given data. More...
 
void Append (char c)
 Append a character or byte to the buffer. More...
 
void Append (const MByteString &data)
 Append a chunk to the existing buffer. More...
 
void Append (const char *buff, unsigned size)
 Append a chunk determined by the pointer and size to the existing buffer. More...
 
void AppendIsoLength (unsigned len)
 Append ISO 8825 length BER representation to this buffer. More...
 
void AppendUidIfPresent (char tag, const MByteString &uid)
 Append ISO 8825 UID to this buffer, if the uid is given. More...
 
void AppendUnsigned (char tag, unsigned val)
 Append ISO 8825 unsigned value to this buffer. More...
 
char * GetTotalPtr ()
 Raw pointer to the whole buffer data. More...
 
const char * GetTotalPtr () const
 Constant raw pointer to the whole buffer data. More...
 
unsigned GetTotalSize () const
 Size of the whole buffer. More...
 

Protected Attributes

MByteString m_bytes
 Buffer internal holder.
 

Detailed Description

Buffer, a byte string with extra manipulation facilities.

The internal implementation is subject to change. The base class provides lightweight manipulation with an array of bytes similar to standard vector, except it can be 'read' sequentially like a stream with MBufferReader.

The real big reason for existence of this simple class is its child MBufferBidirectional, which is like std::deque, but more efficient for prepending the buffer with a 'header'.

There is also unrelated class MBufferCircular, variable capacity circular buffer.

Care must be taken as for efficiency reasons the destructor of this class is not virtual. No virtual functions exist either. Therefore, one should never hold this class with an owning generic pointer.

Constructor & Destructor Documentation

MBuffer::MBuffer ( )
inline

Constructor of an empty unallocated buffer.

See also
Clear - will restore buffer into empty state, however keeping all preallocated space.

Member Function Documentation

void MBuffer::Append ( char  c)
inline

Append a character or byte to the buffer.

Parameters
cCharacter.
void MBuffer::Append ( const MByteString data)
inline

Append a chunk to the existing buffer.

Parameters
dataBytes to be appended.
See also
Assign(const MByteString&) - Assign the whole buffer with the given data.
void MBuffer::Append ( const char *  buff,
unsigned  size 
)
inline

Append a chunk determined by the pointer and size to the existing buffer.

Parameters
buffPointer to the new data buffer.
sizeHow many bytes to copy from the buffer.
See also
Assign(const char*, unsigned) - Assign the whole buffer with the given data.
void MBuffer::AppendIsoLength ( unsigned  len)

Append ISO 8825 length BER representation to this buffer.

Parameters
lenISO 8825 length value.
void MBuffer::AppendUidIfPresent ( char  tag,
const MByteString uid 
)

Append ISO 8825 UID to this buffer, if the uid is given.

If the given uid is an empty string, nothing is done. Otherwise, added are:

  • Tag, one byte.
  • Data length and OID type, relative or absolute, all according to ISO 8825 encoding.
  • Uid Raw byte data, added as is (no conversion of any type is done).
Parameters
tagBER object tag of the UID.
uidChunk of raw bytes. If not empty, added together with the properly formed header.
void MBuffer::AppendUnsigned ( char  tag,
unsigned  val 
)

Append ISO 8825 unsigned value to this buffer.

Added are:

  • Tag, one byte.
  • Data length and type, ISO 8825 encoding.
  • Value Raw byte data, added as is (no conversion of any type is done).
Parameters
tagBER object tag of the UID.
valValue to add.
void MBuffer::Assign ( unsigned  size,
char  c 
)
inline

Assign the whole buffer with the given character of the given length.

Parameters
sizeCount of characters to assign.
cCharacter value to assign to the buffer.
void MBuffer::Assign ( const MByteString data)
inline

Assign the whole buffer with the given data.

Parameters
dataNew data for the buffer.
See also
Append(const MByteString&) - append a chunk to the existing buffer.
void MBuffer::Assign ( const char *  buff,
unsigned  size 
)
inline

Assign the whole buffer with the given data.

Parameters
buffPointer to the new data buffer.
sizeHow many bytes to copy from the buffer.
See also
Append(const char*, unsigned) - append a chunk to the existing buffer.
char* MBuffer::GetTotalPtr ( )
inline

Raw pointer to the whole buffer data.

Care must be taken as some children overwrite this method nonvirtually. It is always assumed that this class is manipulated through its nongeneric instance.

See also
GetTotalSize Size of this pointer data.
const char* MBuffer::GetTotalPtr ( ) const
inline

Constant raw pointer to the whole buffer data.

Care must be taken as some children overwrite this method nonvirtually. It is always assumed that this class is manipulated through its nongeneric instance.

See also
GetTotalSize Size of this pointer data.
unsigned MBuffer::GetTotalSize ( ) const
inline

Size of the whole buffer.

Care must be taken as some children overwrite this method nonvirtually. It is always assumed that this class is manipulated through its nongeneric instance.

See also
GetTotalPtr for the pointer to data
void MBuffer::Reserve ( unsigned  capacity)
inline

Reserve the given number of bytes in the whole buffer.

Keep the buffer size the same.

Parameters
capacityNew buffer capacity, how many bytes can be added efficiently.
See also
Resize - change both the internal buffer capacity and buffer size.
void MBuffer::Resize ( unsigned  size)
inline

Resize buffer.

The buffer will have a new size after the call.

Parameters
sizeNew buffer size.
See also
Reserve - change the internal buffer capacity, but not the size of the buffer.