#include <blob.hpp>
Public Types | |
typedef ::ptrdiff_t | bsize_t |
typedef ::byte | bitem_t |
Public Member Functions | |
FORCEINLINE | CBlobBaseSimple () |
default constructor - initializes empty blob | |
FORCEINLINE | CBlobBaseSimple (const bitem_t *p, bsize_t num_bytes) |
constructor - create blob with data | |
FORCEINLINE | CBlobBaseSimple (const CBlobBaseSimple &src) |
copy constructor | |
FORCEINLINE | CBlobBaseSimple (CHdr *const &pHdr_1) |
move constructor - take ownership of blob data | |
FORCEINLINE | ~CBlobBaseSimple () |
destructor | |
FORCEINLINE bool | IsEmpty () const |
return true if blob doesn't contain valid data | |
FORCEINLINE bsize_t | RawSize () const |
return the number of valid data bytes in the blob | |
FORCEINLINE bsize_t | MaxRawSize () const |
return the current blob capacity in bytes | |
FORCEINLINE bitem_t * | RawData () |
return pointer to the first byte of data - non-const version | |
FORCEINLINE const bitem_t * | RawData () const |
return pointer to the first byte of data - const version | |
FORCEINLINE void | Clear () |
return the 32 bit CRC of valid data in the blob | |
FORCEINLINE void | Free () |
free the blob's memory | |
FORCEINLINE void | CopyFrom (const CBlobBaseSimple &src) |
copy data from another blob - replaces any existing blob's data | |
FORCEINLINE void | MoveFrom (CBlobBaseSimple &src) |
overtake ownership of data buffer from the source blob - source blob will become empty | |
FORCEINLINE void | Swap (CBlobBaseSimple &src) |
swap buffers (with data) between two blobs (this and source blob) | |
FORCEINLINE void | AppendRaw (const void *p, bsize_t num_bytes) |
append new bytes at the end of existing data bytes - reallocates if necessary | |
FORCEINLINE void | AppendRaw (const CBlobBaseSimple &src) |
append bytes from given source blob to the end of existing data bytes - reallocates if necessary | |
FORCEINLINE bitem_t * | MakeRawFreeSpace (bsize_t num_bytes) |
Reallocate if there is no free space for num_bytes bytes. | |
FORCEINLINE bitem_t * | GrowRawSize (bsize_t num_bytes) |
Increase RawSize() by num_bytes. | |
FORCEINLINE void | ReduceRawSize (bsize_t num_bytes) |
Decrease RawSize() by num_bytes. | |
void | SmartAlloc (bsize_t new_size) |
reallocate blob data if needed | |
FORCEINLINE void | FixTail () const |
fixing the four bytes at the end of blob data - useful when blob is used to hold string | |
Static Public Member Functions | |
static FORCEINLINE bsize_t | AllocPolicy (bsize_t min_alloc) |
simple allocation policy - can be optimized later | |
static FORCEINLINE CHdr * | RawAlloc (bsize_t num_bytes) |
all allocation should happen here | |
static FORCEINLINE void | RawFree (CHdr *p) |
all deallocations should happen here | |
Static Public Attributes | |
static const bsize_t | Ttail_reserve = 4 |
four extra bytes will be always allocated and zeroed at the end | |
Protected Member Functions | |
FORCEINLINE void | InitEmpty () |
initialize the empty blob by setting the ptr_u.m_pHdr_1 pointer to the static CHdr with both m_size and m_max_size containing zero | |
FORCEINLINE void | Init (CHdr *hdr) |
initialize blob by attaching it to the given header followed by data | |
FORCEINLINE CHdr & | Hdr () |
blob header accessor - use it rather than using the pointer arithmetics directly - non-const version | |
FORCEINLINE const CHdr & | Hdr () const |
blob header accessor - use it rather than using the pointer arithmetics directly - const version | |
FORCEINLINE bsize_t & | RawSizeRef () |
return reference to the actual blob size - used when the size needs to be modified | |
Protected Attributes | |
union { | |
bitem_t * m_pData | |
ptr to the first byte of data | |
CHdr * m_pHdr_1 | |
ptr just after the CHdr holding m_size and m_max_size | |
} | ptr_u |
type used as class member | |
Data Structures | |
struct | CHdr |
header of the allocated memory block More... |
Item is byte. The word 'simple' means:
Internal member layout: 1. The only class member is pointer to the first item (see union ptr_u). 2. Allocated block contains the blob header (see CHdr) followed by the raw byte data. Always, when it allocates memory the allocated size is: sizeof(CHdr) + <data capacity>=""> 3. Two 'virtual' members (m_size and m_max_size) are stored in the CHdr at beginning of the alloated block. 4. The pointter (in ptr_u) pobsize_ts behind the header (to the first data byte). When memory block is allocated, the sizeof(CHdr) it added to it. 5. Benefits of this layout:
Definition at line 49 of file blob.hpp.
FORCEINLINE void CBlobBaseSimple::Clear | ( | ) | [inline] |
return the 32 bit CRC of valid data in the blob
invalidate blob's data - doesn't free buffer
Definition at line 174 of file blob.hpp.
References RawSizeRef().
Referenced by CopyFrom(), and CStrT< char, false >::operator=().
FORCEINLINE bitem_t* CBlobBaseSimple::MakeRawFreeSpace | ( | bsize_t | num_bytes | ) | [inline] |
Reallocate if there is no free space for num_bytes bytes.
Definition at line 230 of file blob.hpp.
References MaxRawSize(), ptr_u, RawSize(), and SmartAlloc().
Referenced by GrowRawSize().
FORCEINLINE bitem_t* CBlobBaseSimple::GrowRawSize | ( | bsize_t | num_bytes | ) | [inline] |
Increase RawSize() by num_bytes.
Definition at line 240 of file blob.hpp.
References MakeRawFreeSpace(), and RawSizeRef().
Referenced by AppendRaw().
FORCEINLINE void CBlobBaseSimple::ReduceRawSize | ( | bsize_t | num_bytes | ) | [inline] |
Decrease RawSize() by num_bytes.
Definition at line 248 of file blob.hpp.
References MaxRawSize(), RawSize(), and RawSizeRef().