RAVE
rave_object.h File Reference

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

RaveCoreObjectRaveCoreObject_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.
 
RaveCoreObjectRaveCoreObject_copy (RaveCoreObject *src, const char *filename, int lineno)
 Increments the reference counter and returns a pointer to the provided object.
 
RaveCoreObjectRaveCoreObject_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.
 

Detailed Description

Generic implementation of an object that is used within rave.

All objects should use this as template for their structure.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2009-11-25

Macro Definition Documentation

◆ RAVE_OBJECT_BIND

#define RAVE_OBJECT_BIND ( this,
bound )
Value:
void RaveCoreObject_bind(RaveCoreObject *src, void *bindingData)
Sets the binding data field, useful when for example associating this object with another object in o...
Definition rave_object.c:203
The basic raveobject that contains the header information for all rave objects.
Definition rave_object.h:42

Binds the rave object to some sort of pointer value.

E.g. a python object pointer.

◆ RAVE_OBJECT_CHECK_TYPE

#define RAVE_OBJECT_CHECK_TYPE ( this,
type )
Value:
(((RaveCoreObject*)this)->roh_type == type)

Checks if this object is of the specified type.

For example RAVE_OBJECT_CHECK_TYPE(obj, &PolarScan_TYPE).

Parameters
[in]this- the object
[in]type- the type to be checked against.
Returns
true if matching, otherwise false.

◆ RAVE_OBJECT_CLONE

#define RAVE_OBJECT_CLONE ( src)
Value:
(void*)RaveCoreObject_clone((RaveCoreObject*)(src), __FILE__, __LINE__)
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).
Definition rave_object.c:172

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
*   }
* }
* 

◆ RAVE_OBJECT_COPY

#define RAVE_OBJECT_COPY ( src)
Value:
(void*)RaveCoreObject_copy((RaveCoreObject*)(src), __FILE__, __LINE__)
RaveCoreObject * RaveCoreObject_copy(RaveCoreObject *src, const char *filename, int lineno)
Increments the reference counter and returns a pointer to the provided object.
Definition rave_object.c:164

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);

◆ RAVE_OBJECT_GETBINDING

#define RAVE_OBJECT_GETBINDING ( this)
Value:
void * RaveCoreObject_getBindingData(RaveCoreObject *src)
Returns the extra data.
Definition rave_object.c:222

Returns the current binding or NULL if there is none.

◆ RAVE_OBJECT_HEAD

#define RAVE_OBJECT_HEAD
Value:
int roh_refCnt; \
struct _raveobjecttype* roh_type; \
void* roh_bindingData;
The rave object type definition.
Definition rave_object.h:52

Always should be at top of a struct that implements a RaveObject.

◆ RAVE_OBJECT_ISBOUND

#define RAVE_OBJECT_ISBOUND ( this)
Value:

Returns if this object currently is bound to a pointer or not.

◆ RAVE_OBJECT_ISCLONEABLE

#define RAVE_OBJECT_ISCLONEABLE ( src)
Value:
int RaveCoreObject_isCloneable(RaveCoreObject *src)
Returns if this object is possible to clone or not.
Definition rave_object.c:228

Returns if this object is cloneable or not.

Is determined by verifying if the type contains a copy constructor or not.

◆ RAVE_OBJECT_NEW

#define RAVE_OBJECT_NEW ( type)
Value:
(void*)RaveCoreObject_new(type, __FILE__, __LINE__);
RaveCoreObject * RaveCoreObject_new(RaveCoreObjectType *type, const char *filename, int lineno)
Creates a new instance of the provided type.
Definition rave_object.c:123

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);

◆ RAVE_OBJECT_REFCNT

#define RAVE_OBJECT_REFCNT ( src)
Value:
int RaveCoreObject_getRefCount(RaveCoreObject *src)
Returns the current reference count.
Definition rave_object.c:195

Returns the provided objects reference count.

◆ RAVE_OBJECT_RELEASE

#define RAVE_OBJECT_RELEASE ( obj)
Value:
RaveCoreObject_release((RaveCoreObject*)(obj), __FILE__, __LINE__); \
(obj) = NULL;
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 ...
Definition rave_object.c:145

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++

◆ RAVE_OBJECT_UNBIND

#define RAVE_OBJECT_UNBIND ( this,
bound )
Value:
void RaveCoreObject_unbind(RaveCoreObject *src, void *bindingData)
Removes the binding from the rave object.
Definition rave_object.c:214

Unbinds the rave object from a pointer value.

E.g. a python object pointer.

Typedef Documentation

◆ RaveCoreObject

typedef struct _raveobject RaveCoreObject

The basic raveobject that contains the header information for all rave objects.

◆ 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.

Function Documentation

◆ RaveCoreObject_bind()

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.

Parameters
[in]src- this object
[in]bindingData- the associated object (or similar)

◆ RaveCoreObject_clone()

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).

Parameters
[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
Returns
a pointer to the cloned object

◆ RaveCoreObject_copy()

RaveCoreObject * RaveCoreObject_copy ( RaveCoreObject * src,
const char * filename,
int lineno )

Increments the reference counter and returns a pointer to the provided object.

Parameters
[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
Returns
a pointer to the copied object

◆ RaveCoreObject_getBindingData()

void * RaveCoreObject_getBindingData ( RaveCoreObject * src)

Returns the extra data.

Do not use this function directly but use the macros for binding objects instead.

Parameters
[in]src- this object
Returns
the binding data or NULL if none.

◆ RaveCoreObject_getRefCount()

int RaveCoreObject_getRefCount ( RaveCoreObject * src)

Returns the current reference count.

Parameters
[in]src- the the object that should be queried for reference count
Returns
the reference count.

◆ RaveCoreObject_getTrackObjects()

int RaveCoreObject_getTrackObjects ( void )
Returns
if object creation / destruction is tracked.

◆ RaveCoreObject_isCloneable()

int RaveCoreObject_isCloneable ( RaveCoreObject * src)

Returns if this object is possible to clone or not.

Parameters
[in]src- the rave core object
Returns
1 if the object is possible to clone.

◆ RaveCoreObject_new()

RaveCoreObject * RaveCoreObject_new ( RaveCoreObjectType * type,
const char * filename,
int lineno )

Creates a new instance of the provided type.

Parameters
[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
Returns
a new instance

◆ RaveCoreObject_printCurrentObjectStatus()

void RaveCoreObject_printCurrentObjectStatus ( void )

Print current status of object creation.

◆ RaveCoreObject_printStatistics()

void RaveCoreObject_printStatistics ( void )

Prints the rave object statistics.

◆ RaveCoreObject_release()

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.

Parameters
[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

◆ RaveCoreObject_setTrackObjects()

void RaveCoreObject_setTrackObjects ( int track)

Will track object creation and destruction.

Parameters
[in]track- if object creation / destruction should be tracked

◆ RaveCoreObject_unbind()

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.

Parameters
[in]src- this object
[in]bindingData- the binding to remove