C12Adapter Opensource C++ Interface
MBufferBidirectional Class Reference

Buffer where the data can be added to both the beginning and the end of the buffer. More...

Inheritance diagram for MBufferBidirectional:

Public Member Functions

 MBufferBidirectional ()
 Construct an empty bidirectional buffer. More...
 
 ~MBufferBidirectional ()
 Attention, the destructor is not virtual!
 
const char * GetTotalPtr () const
 Raw pointer to the whole buffer data. More...
 
unsigned GetTotalSize () const
 Size of the whole buffer data. More...
 
unsigned GetHeaderSize () const
 Size of the header part of the buffer. More...
 
char * GetBodyPtr ()
 Raw pointer to the whole body part of the data. More...
 
const char * GetBodyPtr () const
 Raw constant pointer to the whole body part of the data. More...
 
unsigned GetBodySize () const
 Size of the body part of the buffer. More...
 
void ClearWithReserve (unsigned headerSize, unsigned totalCapacity)
 Clear the data, but keep reserved the byte space. More...
 
void Assign (const MByteString &data)
 Assign the given data to the body, and clear the header. More...
 
void Assign (const char *buff, unsigned size)
 Assign the given pointer and size to the body, and clear the header. More...
 
void Prepend (char c)
 Prepend a character at the header of the bidirectional buffer. More...
 
void Prepend (const MByteString &data)
 Prepend bytes at the header of the bidirectional buffer. More...
 
void Prepend (const char *buff, unsigned size)
 Prepend bytes at the header of the bidirectional buffer. More...
 
void PrependIsoLength (unsigned len)
 Prepend ISO 8825 length to the header of the bidirectional buffer. More...
 
void PrependUidIfPresent (char tag, const MByteString &uid)
 Prepend ISO 8825 UID to the header of this buffer, if the uid is given. More...
 
void PrependUnsigned (char tag, unsigned val)
 Prepend ISO 8825 unsigned value to the header of this buffer. More...
 
- Public Member Functions inherited from MBuffer
 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...
 

Additional Inherited Members

- Protected Attributes inherited from MBuffer
MByteString m_bytes
 Buffer internal holder.
 

Detailed Description

Buffer where the data can be added to both the beginning and the end of the buffer.

The left part of the bidirectional buffer is the header, it is prepended. The right part of the bidirectional buffer is the body, it is appended.

The internal implementation of this class is subject to change.

Constructor & Destructor Documentation

MBufferBidirectional::MBufferBidirectional ( )
inline

Construct an empty bidirectional buffer.

No preallocation is made.

Member Function Documentation

void MBufferBidirectional::Assign ( const MByteString data)

Assign the given data to the body, and clear the header.

The data will be assigned to the right of the bidirectional buffer.

Parameters
dataBytes that will comprise the body of the buffer.
void MBufferBidirectional::Assign ( const char *  buff,
unsigned  size 
)

Assign the given pointer and size to the body, and clear the header.

The data will be assigned to the right of the bidirectional buffer.

Parameters
buffByte pointer that will comprise the body of the buffer.
sizeSize of the data pointed by buff.
void MBufferBidirectional::ClearWithReserve ( unsigned  headerSize,
unsigned  totalCapacity 
)

Clear the data, but keep reserved the byte space.

Parameters
headerSizeHow many bytes to reserve for the header.
totalCapacityTotal capacity, should not be smaller than the header size.
char* MBufferBidirectional::GetBodyPtr ( )
inline

Raw pointer to the whole body part of the data.

See also
GetBodySize Size of this pointer data.
const char* MBufferBidirectional::GetBodyPtr ( ) const
inline

Raw constant pointer to the whole body part of the data.

See also
GetBodySize Size of this pointer data.
unsigned MBufferBidirectional::GetBodySize ( ) const
inline

Size of the body part of the buffer.

Header is at the beginning of the total data.

See also
GetBodyPtr for the pointer to body data.
unsigned MBufferBidirectional::GetHeaderSize ( ) const
inline

Size of the header part of the buffer.

Header is at the beginning of the total data.

See also
GetTotalPtr for the pointer to header data, same as total data pointer.
const char* MBufferBidirectional::GetTotalPtr ( ) const
inline

Raw pointer to the whole buffer data.

Care must be taken as the base class has nonvirtual method with the same name. It is always assumed that this class is manipulated through its nongeneric instance.

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

Size of the whole buffer data.

Care must be taken as the base class has nonvirtual method with the same name. It is always assumed that this class is manipulated through its nongeneric instance.

See also
GetTotalPtr for the pointer to data.
GetHeaderSize Size of the header part of the total buffer.
void MBufferBidirectional::Prepend ( char  c)

Prepend a character at the header of the bidirectional buffer.

Parameters
cCharacter or byte to prepend.
See also
MBuffer::Append(char) Append a byte or character to the body, parent call.
void MBufferBidirectional::Prepend ( const MByteString data)

Prepend bytes at the header of the bidirectional buffer.

Parameters
dataBytes to be prepended to the left of the buffer.
See also
MBuffer::Append(const MByteString&) Append data to the body, parent call.
void MBufferBidirectional::Prepend ( const char *  buff,
unsigned  size 
)

Prepend bytes at the header of the bidirectional buffer.

Parameters
buffPointer to bytes that will be prepended to the left of the buffer.
sizeSize of the data at the pointer.
See also
MBuffer::Append(const char*, unsigned) Append data to the body, parent call.
void MBufferBidirectional::PrependIsoLength ( unsigned  len)

Prepend ISO 8825 length to the header of the bidirectional buffer.

Parameters
lenValue of length.
See also
MBuffer::AppendIsoLength Append ISO length to the body, parent call.
void MBufferBidirectional::PrependUidIfPresent ( char  tag,
const MByteString uid 
)

Prepend ISO 8825 UID to the header of 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.
See also
MBuffer::AppendUidIfPresent Append uid to the body, parent call.
void MBufferBidirectional::PrependUnsigned ( char  tag,
unsigned  val 
)

Prepend ISO 8825 unsigned value to the header of 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.
See also
MBuffer::AppendUnsigned Append unsigned value to the body, parent call.