RAVE
|
Generic implementation of an object that is used within rave. More...
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | _raveobject |
The basic raveobject that contains the header information for all rave objects. More... | |
struct | _raveobjecttype |
The rave object type definition. More... | |
Macros | |
#define | RAVE_OBJECT_HEAD |
Always should be at top of a struct that implements a RaveObject. | |
#define | RAVE_OBJECT_NEW(type) |
Creates a new instance of a specified object type, should be implemented within the object itself until we have a generic way to create instances by type. | |
#define | RAVE_OBJECT_RELEASE(obj) |
Releases the provided object once (i.e. | |
#define | RAVE_OBJECT_COPY(src) |
Increments the reference counter once for the specified object and returns the pointer. | |
#define | RAVE_OBJECT_CLONE(src) |
Creates a clone of a object. | |
#define | RAVE_OBJECT_ISCLONEABLE(src) |
Returns if this object is cloneable or not. | |
#define | RAVE_OBJECT_REFCNT(src) |
Returns the provided objects reference count. | |
#define | RAVE_OBJECT_BIND(this, bound) |
Binds the rave object to some sort of pointer value. | |
#define | RAVE_OBJECT_UNBIND(this, bound) |
Unbinds the rave object from a pointer value. | |
#define | RAVE_OBJECT_ISBOUND(this) |
Returns if this object currently is bound to a pointer or not. | |
#define | RAVE_OBJECT_GETBINDING(this) |
Returns the current binding or NULL if there is none. | |
#define | RAVE_OBJECT_CHECK_TYPE(this, type) |
Checks if this object is of the specified type. | |
Typedefs | |
typedef struct _raveobject | RaveCoreObject |
The basic raveobject that contains the header information for all rave objects. | |
typedef struct _raveobjecttype | RaveCoreObjectType |
The rave object type definition. | |
Functions | |
RaveCoreObject * | RaveCoreObject_new (RaveCoreObjectType *type, const char *filename, int lineno) |
Creates a new instance of the provided type. | |
void | RaveCoreObject_release (RaveCoreObject *obj, const char *filename, int lineno) |
Decrements the reference counter and if reference counts gets to 0, the destructor that was provided when creating the instance will be called. | |
RaveCoreObject * | RaveCoreObject_copy (RaveCoreObject *src, const char *filename, int lineno) |
Increments the reference counter and returns a pointer to the provided object. | |
RaveCoreObject * | RaveCoreObject_clone (RaveCoreObject *src, const char *filename, int lineno) |
Creates a clone of the provided object by using the types copyconstructor (if there is any). | |
int | RaveCoreObject_getRefCount (RaveCoreObject *src) |
Returns the current reference count. | |
void | RaveCoreObject_bind (RaveCoreObject *src, void *bindingData) |
Sets the binding data field, useful when for example associating this object with another object in order to manage objects from python or other languages. | |
void | RaveCoreObject_unbind (RaveCoreObject *src, void *bindingData) |
Removes the binding from the rave object. | |
void * | RaveCoreObject_getBindingData (RaveCoreObject *src) |
Returns the extra data. | |
int | RaveCoreObject_isCloneable (RaveCoreObject *src) |
Returns if this object is possible to clone or not. | |
void | RaveCoreObject_setTrackObjects (int track) |
Will track object creation and destruction. | |
int | RaveCoreObject_getTrackObjects (void) |
void | RaveCoreObject_printCurrentObjectStatus (void) |
Print current status of object creation. | |
void | RaveCoreObject_printStatistics (void) |
Prints the rave object statistics. | |
Generic implementation of an object that is used within rave.
All objects should use this as template for their structure.
#define RAVE_OBJECT_BIND | ( | this, | |
bound ) |
Binds the rave object to some sort of pointer value.
E.g. a python object pointer.
#define RAVE_OBJECT_CHECK_TYPE | ( | this, | |
type ) |
Checks if this object is of the specified type.
For example RAVE_OBJECT_CHECK_TYPE(obj, &PolarScan_TYPE).
[in] | this | - the object |
[in] | type | - the type to be checked against. |
#define RAVE_OBJECT_CLONE | ( | src | ) |
Creates a clone of a object.
Not to be confused with COPY. I.e. basically the same as doing a NEW followed by a copy of all essential members. Be aware that not all objects supports this function and in that case, NULL will be returned. If it is interesting to ensure that everything is successful, you can always do this:
* if (RAVE_OBJECT_ISCLONEABLE(src)) { * clone = RAVE_OBJECT_CLONE(src); * if (clone == NULL) { * // memory allocation error or something * } * } *
#define RAVE_OBJECT_COPY | ( | src | ) |
Increments the reference counter once for the specified object and returns the pointer.
Typically used as: x = RAVE_OBJECT_COPY(obj); .... RAVE_OBJECT_RELEASE(x);
#define RAVE_OBJECT_GETBINDING | ( | this | ) |
Returns the current binding or NULL if there is none.
#define RAVE_OBJECT_HEAD |
Always should be at top of a struct that implements a RaveObject.
#define RAVE_OBJECT_ISBOUND | ( | this | ) |
Returns if this object currently is bound to a pointer or not.
#define RAVE_OBJECT_ISCLONEABLE | ( | src | ) |
Returns if this object is cloneable or not.
Is determined by verifying if the type contains a copy constructor or not.
#define RAVE_OBJECT_NEW | ( | type | ) |
Creates a new instance of a specified object type, should be implemented within the object itself until we have a generic way to create instances by type.
Typically: SomeObject_t* obj = RAVE_OBJECT_NEW(&SomeObject_Type);
#define RAVE_OBJECT_REFCNT | ( | src | ) |
Returns the provided objects reference count.
#define RAVE_OBJECT_RELEASE | ( | obj | ) |
Releases the provided object once (i.e.
decrements the reference counter and sets the invalue to NULL. Ie. Do not do something funny like: RAVE_OBJECT_RELEASE(x[index++]) since that will mess up the memory, instead write RAVE_OBJECT_RELEASE(x[index]); index++
#define RAVE_OBJECT_UNBIND | ( | this, | |
bound ) |
Unbinds the rave object from a pointer value.
E.g. a python object pointer.
typedef struct _raveobject RaveCoreObject |
The basic raveobject that contains the header information for all rave objects.
typedef struct _raveobjecttype RaveCoreObjectType |
The rave object type definition.
If you are implementing support for the copy constructor, you must ensure that all members of the object are clones as well so that there are no references to other objects.
void RaveCoreObject_bind | ( | RaveCoreObject * | src, |
void * | bindingData ) |
Sets the binding data field, useful when for example associating this object with another object in order to manage objects from python or other languages.
Do not use this function directly but use the macros for binding instead.
[in] | src | - this object |
[in] | bindingData | - the associated object (or similar) |
RaveCoreObject * RaveCoreObject_clone | ( | RaveCoreObject * | src, |
const char * | filename, | ||
int | lineno ) |
Creates a clone of the provided object by using the types copyconstructor (if there is any).
[in] | src | - the object to be cloned |
[in] | filename | - the filename that this operation was performed in |
[in] | lineno | - the linenumber that this operation was performed in |
RaveCoreObject * RaveCoreObject_copy | ( | RaveCoreObject * | src, |
const char * | filename, | ||
int | lineno ) |
Increments the reference counter and returns a pointer to the provided object.
[in] | src | - the object to be copied |
[in] | filename | - the filename that this operation was performed in |
[in] | lineno | - the linenumber that this operation was performed in |
void * RaveCoreObject_getBindingData | ( | RaveCoreObject * | src | ) |
Returns the extra data.
Do not use this function directly but use the macros for binding objects instead.
[in] | src | - this object |
int RaveCoreObject_getRefCount | ( | RaveCoreObject * | src | ) |
Returns the current reference count.
[in] | src | - the the object that should be queried for reference count |
int RaveCoreObject_getTrackObjects | ( | void | ) |
int RaveCoreObject_isCloneable | ( | RaveCoreObject * | src | ) |
Returns if this object is possible to clone or not.
[in] | src | - the rave core object |
RaveCoreObject * RaveCoreObject_new | ( | RaveCoreObjectType * | type, |
const char * | filename, | ||
int | lineno ) |
Creates a new instance of the provided type.
[in] | type | - the object type |
[in] | filename | - the filename that this allocation was performed in |
[in] | lineno | - the linenumber that this allocation was performed in |
void RaveCoreObject_printCurrentObjectStatus | ( | void | ) |
Print current status of object creation.
void RaveCoreObject_printStatistics | ( | void | ) |
Prints the rave object statistics.
void RaveCoreObject_release | ( | RaveCoreObject * | obj, |
const char * | filename, | ||
int | lineno ) |
Decrements the reference counter and if reference counts gets to 0, the destructor that was provided when creating the instance will be called.
Note, regardless on if and how the destructor has been implemented, the object will be freed.
[in] | obj | - the object to release (including the object itself) |
[in] | filename | - the filename that this operation was performed in |
[in] | lineno | - the linenumber that this operation was performed in |
void RaveCoreObject_setTrackObjects | ( | int | track | ) |
Will track object creation and destruction.
[in] | track | - if object creation / destruction should be tracked |
void RaveCoreObject_unbind | ( | RaveCoreObject * | src, |
void * | bindingData ) |
Removes the binding from the rave object.
Do not use this function directly but use the macros for binding instead. If bindingData != the stored binding data nothing will happen.
[in] | src | - this object |
[in] | bindingData | - the binding to remove |