Defines | |
#define | OBJECT_OK 0 |
OK (No Error). | |
#define | OBJECT_ERR_OUT_OF_MEMORY 1 |
Out of memory. | |
#define | OBJECT_ERR_CLASS_REGISTERED 2 |
Class already registered. | |
#define | OBJECT_ERR_CLASS_NOT_FOUND 3 |
Class could not be found. | |
#define | ObjectRegisterType(_type) ObjectRegisterClass(TOSTRING(_type), sizeof(_type), NULL) |
Helper macro to register a type as an object class. | |
#define | ObjectRegisterTypeDestructor(_type, _destructor) ObjectRegisterClass(TOSTRING(_type), sizeof(_type), _destructor) |
Helper macro to register a type as an object class. | |
#define | ObjectCreate(_classname) ObjectCreateImpl(_classname, __FILE__, __LINE__) |
Create a new object of class <classname>. | |
#define | ObjectCreateType(_type) ObjectCreate(TOSTRING(_type)) |
Helper macro to create a new object of the specfied type. | |
#define | ObjectRefInc(_ptr) ObjectRefIncImpl(_ptr, __FILE__, __LINE__) |
Increment the reference count for the specified object. | |
#define | ObjectRefDec(_ptr) ObjectRefDecImpl(_ptr, __FILE__, __LINE__) |
Decrement the reference count for the specified object. | |
#define | ObjectAlloc(_size) ObjectAllocImpl(_size, __FILE__, __LINE__) |
Replacement for malloc, with the addition that it also clears the memory to zero. | |
#define | ObjectFree(_ptr) ObjectFreeImpl(_ptr, __FILE__, __LINE__) |
Replacement for free. | |
Typedefs | |
typedef void(* | ObjectDestructor_t )(void *ptr) |
Type for a function to call when free'ing an object. | |
Functions | |
int | ObjectInit (void) |
Initialise object memory system. | |
int | ObjectDeinit (void) |
Deinitialise object memory system. | |
int | ObjectRegisterClass (char *classname, unsigned int size, ObjectDestructor_t destructor) |
Register a class of object to use with the ObjectCreate function. | |
void * | ObjectCreateImpl (char *classname, char *file, int line) |
Create a new object of class <classname>. | |
void | ObjectRefIncImpl (void *ptr, char *file, int line) |
Increment the reference count for the specified object. | |
bool | ObjectRefDecImpl (void *ptr, char *file, int line) |
Decrement the reference count for the specified object. | |
int | ObjectRefCount (void *ptr) |
Retrieve the current reference count of the specific object. | |
bool | ObjectIsObject (void *ptr) |
Queries the supplied pointer to determine if it is an object instance. | |
char * | ObjectGetObjectClass (void *ptr) |
Queries the supplied object pointer to determine the class of the object. | |
void * | ObjectAllocImpl (int size, char *file, int line) |
Replacement for malloc with the addition that it also clears the memory to zero. | |
void | ObjectFreeImpl (void *ptr, char *file, int line) |
Replacement for free. | |
void | ObjectDump (void *ptr) |
Print out debugging information about the object. |
#define OBJECT_ERR_CLASS_NOT_FOUND 3 |
Class could not be found.
#define OBJECT_ERR_CLASS_REGISTERED 2 |
Class already registered.
#define OBJECT_ERR_OUT_OF_MEMORY 1 |
Out of memory.
#define OBJECT_OK 0 |
OK (No Error).
#define ObjectAlloc | ( | _size | ) | ObjectAllocImpl(_size, __FILE__, __LINE__) |
Replacement for malloc, with the addition that it also clears the memory to zero.
_size | Size of the block to allocated. |
#define ObjectCreate | ( | _classname | ) | ObjectCreateImpl(_classname, __FILE__, __LINE__) |
Create a new object of class <classname>.
The initial reference count for the returned object will be 1.
_classname | Class of object to create. |
#define ObjectCreateType | ( | _type | ) | ObjectCreate(TOSTRING(_type)) |
Helper macro to create a new object of the specfied type.
_type | The new type of the object to create. |
#define ObjectFree | ( | _ptr | ) | ObjectFreeImpl(_ptr, __FILE__, __LINE__) |
Replacement for free.
Releases memory previously allocated by ObjectAlloc.
_ptr | The memory block to free. |
#define ObjectRefDec | ( | _ptr | ) | ObjectRefDecImpl(_ptr, __FILE__, __LINE__) |
Decrement the reference count for the specified object.
If the reference count reaches zero the object's class's destructor will be called and the memory freed.
_ptr | Pointer to the object to decrement the ref. count of. |
#define ObjectRefInc | ( | _ptr | ) | ObjectRefIncImpl(_ptr, __FILE__, __LINE__) |
Increment the reference count for the specified object.
_ptr | Pointer to the object to increment the ref. count of. |
#define ObjectRegisterType | ( | _type | ) | ObjectRegisterClass(TOSTRING(_type), sizeof(_type), NULL) |
Helper macro to register a type as an object class.
_type | The type to register with the object system. |
#define ObjectRegisterTypeDestructor | ( | _type, | |||
_destructor | ) | ObjectRegisterClass(TOSTRING(_type), sizeof(_type), _destructor) |
Helper macro to register a type as an object class.
_type | The type to register with the object system. | |
_destructor | Function to call when free'ing an object of the type being registered. |
typedef void(* ObjectDestructor_t)(void *ptr) |
Type for a function to call when free'ing an object.
ptr is the pointer to the object being freed.
void* ObjectAllocImpl | ( | int | size, | |
char * | file, | |||
int | line | |||
) |
Replacement for malloc with the addition that it also clears the memory to zero.
size | Size of the block to allocated. | |
file | The file this function is being called from. | |
line | The line this function is being called from. |
void* ObjectCreateImpl | ( | char * | classname, | |
char * | file, | |||
int | line | |||
) |
Create a new object of class <classname>.
The initial reference count for the returned object will be 1.
classname | Class of object to create. | |
file | The file this function is being called from. | |
line | The line this function is being called from. |
int ObjectDeinit | ( | void | ) |
Deinitialise object memory system.
void ObjectDump | ( | void * | ptr | ) |
Print out debugging information about the object.
ptr | Pointer to the object to dump information on. |
void ObjectFreeImpl | ( | void * | ptr, | |
char * | file, | |||
int | line | |||
) |
Replacement for free.
Releases memory previously allocated by ObjectAlloc.
_ptr | The memory block to free. | |
file | The file this function is being called from. | |
line | The line this function is being called from. |
char* ObjectGetObjectClass | ( | void * | ptr | ) |
Queries the supplied object pointer to determine the class of the object.
ptr | Pointer to check. |
int ObjectInit | ( | void | ) |
Initialise object memory system.
bool ObjectIsObject | ( | void * | ptr | ) |
Queries the supplied pointer to determine if it is an object instance.
ptr | Pointer to check to see if it is an object pointer. |
int ObjectRefCount | ( | void * | ptr | ) |
Retrieve the current reference count of the specific object.
ptr | Pointer to the object to get the reference count of. |
bool ObjectRefDecImpl | ( | void * | ptr, | |
char * | file, | |||
int | line | |||
) |
Decrement the reference count for the specified object.
If the reference count
ptr | Pointer to the object to decrement the ref. count of. | |
file | The file this function is being called from. | |
line | The line this function is being called from. |
void ObjectRefIncImpl | ( | void * | ptr, | |
char * | file, | |||
int | line | |||
) |
Increment the reference count for the specified object.
ptr | Pointer to the object to increment the ref. count of. | |
file | The file this function is being called from. | |
line | The line this function is being called from. |
int ObjectRegisterClass | ( | char * | classname, | |
unsigned int | size, | |||
ObjectDestructor_t | destructor | |||
) |
Register a class of object to use with the ObjectCreate function.
classname | Name of the class being registered. | |
size | Size of the memory need for the object. | |
destructor | Function to call when the reference count reach zero for an object. This is only required if the object includes references to other object/malloc memory that needs to be freed. |