RAVE
rave_object.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2009 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
26#ifndef RAVE_OBJECT_H
27#define RAVE_OBJECT_H
28#include <stdlib.h>
29
33#define RAVE_OBJECT_HEAD \
34 int roh_refCnt; \
35 struct _raveobjecttype* roh_type; \
36 void* roh_bindingData;
37
45
59
66#define RAVE_OBJECT_NEW(type) \
67 (void*)RaveCoreObject_new(type, __FILE__, __LINE__);
68
76#define RAVE_OBJECT_RELEASE(obj) \
77 RaveCoreObject_release((RaveCoreObject*)(obj), __FILE__, __LINE__); \
78 (obj) = NULL;
79
87#define RAVE_OBJECT_COPY(src) \
88 (void*)RaveCoreObject_copy((RaveCoreObject*)(src), __FILE__, __LINE__)
89
105#define RAVE_OBJECT_CLONE(src) \
106 (void*)RaveCoreObject_clone((RaveCoreObject*)(src), __FILE__, __LINE__)
107
112#define RAVE_OBJECT_ISCLONEABLE(src) \
113 RaveCoreObject_isCloneable((RaveCoreObject*)(src))
114
118#define RAVE_OBJECT_REFCNT(src) \
119 RaveCoreObject_getRefCount((RaveCoreObject*)src)
120
124#define RAVE_OBJECT_BIND(this, bound) \
125 RaveCoreObject_bind((RaveCoreObject*)this, bound)
126
130#define RAVE_OBJECT_UNBIND(this, bound) \
131 RaveCoreObject_unbind((RaveCoreObject*)this, bound)
132
136#define RAVE_OBJECT_ISBOUND(this) \
137 (RaveCoreObject_getBindingData((RaveCoreObject*)this) != NULL)
138
142#define RAVE_OBJECT_GETBINDING(this) \
143 RaveCoreObject_getBindingData((RaveCoreObject*)this)
144
152#define RAVE_OBJECT_CHECK_TYPE(this, type) \
153 (((RaveCoreObject*)this)->roh_type == type)
154
155
163RaveCoreObject* RaveCoreObject_new(RaveCoreObjectType* type, const char* filename, int lineno);
164
173void RaveCoreObject_release(RaveCoreObject* obj, const char* filename, int lineno);
174
182RaveCoreObject* RaveCoreObject_copy(RaveCoreObject* src, const char* filename, int lineno);
183
191RaveCoreObject* RaveCoreObject_clone(RaveCoreObject* src, const char* filename, int lineno);
192
199
208void RaveCoreObject_bind(RaveCoreObject* src, void* bindingData);
209
216void RaveCoreObject_unbind(RaveCoreObject* src, void* bindingData);
217
225
232
237void RaveCoreObject_setTrackObjects(int track);
238
243
248
253
254#endif /* RAVE_OBJECT_H */
int RaveCoreObject_getTrackObjects()
Definition rave_object.c:280
void RaveCoreObject_printStatistics(void)
Prints the rave object statistics.
Definition rave_object.c:244
struct _raveobject RaveCoreObject
The basic raveobject that contains the header information for all rave objects.
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
RaveCoreObject * RaveCoreObject_new(RaveCoreObjectType *type, const char *filename, int lineno)
Creates a new instance of the provided type.
Definition rave_object.c:123
struct _raveobjecttype RaveCoreObjectType
The rave object type definition.
int RaveCoreObject_isCloneable(RaveCoreObject *src)
Returns if this object is possible to clone or not.
Definition rave_object.c:228
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
int RaveCoreObject_getRefCount(RaveCoreObject *src)
Returns the current reference count.
Definition rave_object.c:195
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
void RaveCoreObject_setTrackObjects(int track)
Will track object creation and destruction.
Definition rave_object.c:271
void RaveCoreObject_printCurrentObjectStatus(void)
Print current status of object creation.
Definition rave_object.c:239
#define RAVE_OBJECT_HEAD
Always should be at top of a struct that implements a RaveObject.
Definition rave_object.h:33
void * RaveCoreObject_getBindingData(RaveCoreObject *src)
Returns the extra data.
Definition rave_object.c:222
void RaveCoreObject_unbind(RaveCoreObject *src, void *bindingData)
Removes the binding from the rave object.
Definition rave_object.c:214
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
The basic raveobject that contains the header information for all rave objects.
Definition rave_object.h:42
The rave object type definition.
Definition rave_object.h:52
size_t type_size
the size of the object, sizeof(type)
Definition rave_object.h:54
void(* destructor)(RaveCoreObject *obj)
function to be called for release of members in the object
Definition rave_object.h:56
int(* constructor)(RaveCoreObject *obj)
function to be called for initialization of the object
Definition rave_object.h:55
int(* copyconstructor)(RaveCoreObject *obj, RaveCoreObject *source)
Function when creating an clone.
Definition rave_object.h:57
const char * name
the name, for printout
Definition rave_object.h:53