| Linderdaum Engine: clBlob Class Reference | ![]() |
A chunk of raw memory with hashing capabilities. More...
#include <LBlob.h>
Public Member Functions | |
| clBlob () | |
| virtual | ~clBlob () |
| virtual void | AfterConstruction () |
| void | SetExternalData (void *Ptr, size_t Sz) |
| Set the blob data pointer to some external memory block. | |
| void * | GetDataConst () const |
| Constant access to the blob's data. | |
| void * | GetData () |
| Direct access to blob's data. | |
| void | SetSize (size_t NewSize) |
| Alias (setter method) for the reallocator. | |
| size_t | GetSize () const |
| Get current blob size. | |
| bool | OwnsData () const |
| Check if this blob manages its own contents. | |
| void | SetOwnership (bool Ownership) |
| Change ownership of the memory block. | |
| bool | CopyBlob (const clBlob *Other) |
| Make a local copy of the other blob. Can change memory ownership of this blob on reallocation. | |
| bool | HasData () const |
| Check if this blob refers to some data. | |
| int | CompareContents (const clBlob *Other) const |
| Binary comparison with other blob (strcmp() analogue) Error codes: 0 if equal, -1/+1 if other is longer/shorter than this 0xFF - one of the blobs contains null data. | |
| bool | CopyMemoryBlock (const void *FromData, size_t FromSize) |
| Copy blob contents from external source. | |
| template<class T > | |
| void | SetPOD (size_t Offset, T TheValue) |
| Template Set method to avoid inclusion of custom type headers (vec3/mtx etc) | |
| template<class T > | |
| T | GetPOD (size_t Offset) |
| Template Get method to avoid inclusion of custom type headers (vec3/mtx etc) | |
| void | SetByte (size_t Offset, Lubyte TheByte) |
| Item access. | |
| Lubyte | GetByte (size_t Offset) const |
| Quick access to the specififed byte. No range checking. | |
| void | SetBytes (size_t Offset, size_t Num, const Lubyte *Src) |
| void | GetBytes (size_t Offset, size_t Num, Lubyte *Out) const |
| void | CopyFrom (const clBlob *Other, size_t SrcOffset, size_t DestOffset, size_t Count) |
| Copy Count bytes from another blob. | |
| bool | SafeResize (size_t NewSize) |
| Resize and do not spoil the contents. | |
Public Attributes | |
| LEndianness | FByteEndianness |
| Endianness is not yet supported. | |
Private Member Functions | |
| void | Allocate (size_t NewSize) |
| Allocate new block and change ownership type. | |
| void | Delete () |
| Try to delete the memory block. Not exposed as a public method, because direct access here can cause troubles. | |
| void | Reallocate (size_t NewSize) |
| Reallocate the data block if it is required. | |
Private Attributes | |
| void * | FData |
| Pointer to the blob data. | |
| size_t | FSize |
| Effective size of the blob. | |
| size_t | FAllocatedSize |
| Actually allocated size (used for faster resize and copy operations) | |
| bool | FOwnsData |
| True if this Blob manages and deallocates the memory block. | |
A chunk of raw memory with hashing capabilities.
typedef unsigned int uint32;
/ Bob Jenkins' on_at_a_time hash function (http://burtleburtle.net/bob/hash/doobs.html) uint32 JenkinsHash(const char *key, size_t len, uint32 mask) { uint32 hash, i;
const char* val_ptr = key; for (uint32 hash = 0, i = 0 ; i < len ; ++i) { hash += *val_ptr; hash += (hash << 10); hash ^= (hash >> 6); val_ptr++; }
hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15);
return (hash & mask); } I. Uses:
a) Used for native-to-managed (script, jni, .net, lua) array marshalling
E.g., if a user wants a direct access to some array, he/she might use the Set/GetByte() methods
b) Bitmaps/Heightmaps can be converted to this blob. Memory/File streams can also be converted to blob
c) Selected items from the blob (a.k.a. array elements) can be bound to some console variables.
d) This class can, in theory, replace the Packet class in network lib
II. Creation and memory management
Blobs are created using Linker or ResourceManager.
Memory for the blob is allocated internaly on demand (SetSize/alloc methods) or the blob can refer to the preallocated memory chunk (FOwnsData flag).
III. Strong typing
Items of the blob (accessed with Get<Type>Item(int idx) methods) can have many types (scalars, strings and vec/mtx)
IV. Serialization
Blob can act as a storage analogous to the mlNode: autogenerated save/load procedures can use the Read/Write methods and support endian-independent structure layout
| clBlob::clBlob | ( | ) | [inline] |
| virtual clBlob::~clBlob | ( | ) | [inline, virtual] |
| virtual void clBlob::AfterConstruction | ( | ) | [inline, virtual] |
Reimplemented from iObject.
| void clBlob::Allocate | ( | size_t | NewSize | ) | [inline, private] |
Allocate new block and change ownership type.
Binary comparison with other blob (strcmp() analogue) Error codes: 0 if equal, -1/+1 if other is longer/shorter than this 0xFF - one of the blobs contains null data.
| bool clBlob::CopyBlob | ( | const clBlob * | Other | ) | [inline] |
Make a local copy of the other blob. Can change memory ownership of this blob on reallocation.
| void clBlob::CopyFrom | ( | const clBlob * | Other, |
| size_t | SrcOffset, | ||
| size_t | DestOffset, | ||
| size_t | Count | ||
| ) | [inline] |
Copy Count bytes from another blob.
| bool clBlob::CopyMemoryBlock | ( | const void * | FromData, |
| size_t | FromSize | ||
| ) | [inline] |
Copy blob contents from external source.
| void clBlob::Delete | ( | ) | [inline, private] |
Try to delete the memory block. Not exposed as a public method, because direct access here can cause troubles.
| Lubyte clBlob::GetByte | ( | size_t | Offset | ) | const [inline] |
Quick access to the specififed byte. No range checking.
| void clBlob::GetBytes | ( | size_t | Offset, |
| size_t | Num, | ||
| Lubyte * | Out | ||
| ) | const [inline] |
| void* clBlob::GetData | ( | ) | [inline] |
Direct access to blob's data.
| void* clBlob::GetDataConst | ( | ) | const [inline] |
Constant access to the blob's data.
| T clBlob::GetPOD | ( | size_t | Offset | ) | [inline] |
Template Get method to avoid inclusion of custom type headers (vec3/mtx etc)
| size_t clBlob::GetSize | ( | ) | const [inline] |
Get current blob size.
| bool clBlob::HasData | ( | ) | const [inline] |
Check if this blob refers to some data.
| bool clBlob::OwnsData | ( | ) | const [inline] |
Check if this blob manages its own contents.
| void clBlob::Reallocate | ( | size_t | NewSize | ) | [inline, private] |
Reallocate the data block if it is required.
| bool clBlob::SafeResize | ( | size_t | NewSize | ) | [inline] |
Resize and do not spoil the contents.
| void clBlob::SetByte | ( | size_t | Offset, |
| Lubyte | TheByte | ||
| ) | [inline] |
Item access.
| void clBlob::SetBytes | ( | size_t | Offset, |
| size_t | Num, | ||
| const Lubyte * | Src | ||
| ) | [inline] |
| void clBlob::SetExternalData | ( | void * | Ptr, |
| size_t | Sz | ||
| ) | [inline] |
Set the blob data pointer to some external memory block.
| void clBlob::SetOwnership | ( | bool | Ownership | ) | [inline] |
Change ownership of the memory block.
| void clBlob::SetPOD | ( | size_t | Offset, |
| T | TheValue | ||
| ) | [inline] |
Template Set method to avoid inclusion of custom type headers (vec3/mtx etc)
| void clBlob::SetSize | ( | size_t | NewSize | ) | [inline] |
Alias (setter method) for the reallocator.
size_t clBlob::FAllocatedSize [private] |
Actually allocated size (used for faster resize and copy operations)
Endianness is not yet supported.
void* clBlob::FData [private] |
Pointer to the blob data.
bool clBlob::FOwnsData [private] |
True if this Blob manages and deallocates the memory block.
size_t clBlob::FSize [private] |
Effective size of the blob.