C12Adapter Opensource C++ Interface
|
Buffer, a byte string with extra manipulation facilities. More...
Public Member Functions | |
MBuffer () | |
Constructor of an empty unallocated buffer. More... | |
~MBuffer () | |
Attention, the destructor is not virtual. | |
MByteString & | AccessAllBytes () |
Access all bytes in the buffer. | |
const MByteString & | AccessAllBytes () 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. | |
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.
|
inline |
Constructor of an empty unallocated buffer.
|
inline |
Append a character or byte to the buffer.
c | Character. |
|
inline |
Append a chunk to the existing buffer.
data | Bytes to be appended. |
|
inline |
Append a chunk determined by the pointer and size to the existing buffer.
buff | Pointer to the new data buffer. |
size | How many bytes to copy from the buffer. |
void MBuffer::AppendIsoLength | ( | unsigned | len | ) |
Append ISO 8825 length BER representation to this buffer.
len | ISO 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 | BER object tag of the UID. |
uid | Chunk 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 | BER object tag of the UID. |
val | Value to add. |
|
inline |
Assign the whole buffer with the given character of the given length.
size | Count of characters to assign. |
c | Character value to assign to the buffer. |
|
inline |
Assign the whole buffer with the given data.
data | New data for the buffer. |
|
inline |
Assign the whole buffer with the given data.
buff | Pointer to the new data buffer. |
size | How many bytes to copy from the buffer. |
|
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.
|
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.
|
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.
|
inline |
Reserve the given number of bytes in the whole buffer.
Keep the buffer size the same.
capacity | New buffer capacity, how many bytes can be added efficiently. |
|
inline |
Resize buffer.
The buffer will have a new size after the call.
size | New buffer size. |