gwenhywfar 5.12.0
inherit.h
Go to the documentation of this file.
1/***************************************************************************
2 $RCSfile$
3 -------------------
4 cvs : $Id$
5 begin : Sun Dec 05 2003
6 copyright : (C) 2003 by Martin Preuss
7 email : martin@libchipcard.de
8
9 ***************************************************************************
10 * *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2.1 of the License, or (at your option) any later version. *
15 * *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19 * Lesser General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU Lesser General Public *
22 * License along with this library; if not, write to the Free Software *
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24 * MA 02111-1307 USA *
25 * *
26 ***************************************************************************/
27
28#ifndef GWENHYWFAR_INHERIT_H
29#define GWENHYWFAR_INHERIT_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
35#ifdef __cplusplus
36}
37#endif
38
39
40#include <gwenhywfar/misc.h>
42
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48
53typedef void GWENHYWFAR_CB(*GWEN_INHERIT_FREEDATAFN)(void *baseData,
54 void *data);
55
57/* No trailing semicolon because this is a macro call */
58
61 uint32_t id,
62 void *data,
63 void *baseData,
67
70
73
76
79
82
85
89
91uint32_t GWEN_Inherit_MakeId(const char *typeName);
92
95 uint32_t id,
96 int wantCreate);
97
100 uint32_t id,
101 int wantCreate);
102
112#define GWEN_INHERIT_ELEMENT(t) \
113 GWEN_INHERITDATA_LIST *INHERIT__list;
114
125#define GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl) \
126 decl void t##__INHERIT_SETDATA(t *element, \
127 const char *typeName,\
128 uint32_t id,\
129 void *data,\
130 GWEN_INHERIT_FREEDATAFN f);\
131 decl int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id);\
132 decl GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element);\
133 decl void t##__INHERIT_UNLINK(t *element, \
134 const char *typeName,\
135 uint32_t id);
136
147#define GWEN_INHERIT_FUNCTION_DEFS(t) \
148 GWEN_INHERIT_FUNCTION_LIB_DEFS(t, GWEN_DUMMY_EMPTY_ARG)
149
163#define GWEN_INHERIT_FUNCTIONS(t) \
164 GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element) {\
165 assert(element);\
166 return element->INHERIT__list;\
167 }\
168 \
169 void t##__INHERIT_SETDATA(t *element, \
170 const char *typeName,\
171 uint32_t id,\
172 void *data,\
173 GWEN_INHERIT_FREEDATAFN f) {\
174 GWEN_INHERITDATA *d;\
175 void *p;\
176 \
177 assert(element);\
178 assert(element->INHERIT__list);\
179 \
180 p=GWEN_Inherit_FindData(element->INHERIT__list, id, 1);\
181 if (p) {\
182 fprintf(stderr,\
183 "ERROR: Type \"%s\" already inherits base type\n",\
184 typeName);\
185 abort();\
186 }\
187 d=GWEN_InheritData_new(typeName, id, data, (void*)element, f);\
188 GWEN_InheritData_List_Insert(d, element->INHERIT__list);\
189 }\
190 \
191 int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id) {\
192 assert(element);\
193 assert(element->INHERIT__list);\
194 \
195 return (GWEN_Inherit_FindData(element->INHERIT__list, id, 1)!=0);\
196 }\
197 \
198 void t##__INHERIT_UNLINK(t *element, \
199 const char *typeName,\
200 uint32_t id) {\
201 GWEN_INHERITDATA *d;\
202 \
203 assert(element);\
204 assert(element->INHERIT__list);\
205 \
206 d=GWEN_Inherit_FindEntry(element->INHERIT__list, id, 1);\
207 if (!d) {\
208 fprintf(stderr, \
209 "ERROR: Type \"%s\" does not inherit base type\n",\
210 typeName);\
211 abort();\
212 }\
213 GWEN_InheritData_clear(d);\
214 GWEN_InheritData_List_Del(d);\
215 GWEN_InheritData_free(d);\
216 }
217
223#define GWEN_INHERIT_INIT(t, element) {\
224 assert(element);\
225 element->INHERIT__list=GWEN_InheritData_List_new();\
226 }
227
228
238#define GWEN_INHERIT_FINI(t, element) {\
239 GWEN_INHERITDATA *inherit__data;\
240 \
241 assert(element);\
242 assert(element->INHERIT__list);\
243 \
244 while( (inherit__data=GWEN_InheritData_List_First(element->INHERIT__list)) ) {\
245 GWEN_InheritData_freeData(inherit__data); \
246 GWEN_InheritData_List_Del(inherit__data); \
247 GWEN_InheritData_free(inherit__data); \
248 } \
249 GWEN_InheritData_List_free(element->INHERIT__list);\
250 }
251
264#define GWEN_INHERIT(bt, t) \
265 uint32_t t##__INHERIT_ID=0;
266
271#define GWEN_INHERIT_REF(bt, t) \
272 extern uint32_t t##__INHERIT_ID;
273
274
279#define GWEN_INHERIT_GETDATA(bt, t, element) \
280 ((t*)GWEN_Inherit_FindData(bt##__INHERIT_GETLIST(element),t##__INHERIT_ID,0))
281
300#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn) {\
301 if (!t##__INHERIT_ID)\
302 t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
303 bt##__INHERIT_SETDATA(element, __STRING(t), t##__INHERIT_ID, data, fn);\
304 }
305
313#define GWEN_INHERIT_ISOFTYPE(bt, t, element) \
314 ((bt##__INHERIT_ISOFTYPE(element,\
315 ((t##__INHERIT_ID==0)?\
316 ((t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t)))):\
317 t##__INHERIT_ID)))?1:0)
318
326#define GWEN_INHERIT_UNLINK(bt, t, element) {\
327 if (!t##__INHERIT_ID)\
328 t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
329 bt##__INHERIT_UNLINK(element, __STRING(t), t##__INHERIT_ID);\
330 }
331 /* defgroup */
335
336
337#ifdef __cplusplus
338}
339#endif
340
341
342
343#endif /* GWENHYWFAR_INHERIT_P_H */
344
345
346
#define GWENHYWFAR_API
Definition: gwenhywfarapi.h:67
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
GWENHYWFAR_API void * GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
GWENHYWFAR_API GWEN_INHERITDATA * GWEN_InheritData_new(const char *t, uint32_t id, void *data, void *baseData, GWEN_INHERIT_FREEDATAFN fn)
GWENHYWFAR_API void * GWEN_InheritData_GetData(const GWEN_INHERITDATA *d)
GWENHYWFAR_API uint32_t GWEN_Inherit_MakeId(const char *typeName)
GWENHYWFAR_API uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d)
GWENHYWFAR_API void GWEN_InheritData_clear(GWEN_INHERITDATA *d)
GWENHYWFAR_API const char * GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d)
GWENHYWFAR_API void GWEN_InheritData_freeAllData(GWEN_INHERITDATA *d)
GWENHYWFAR_API void GWEN_InheritData_free(GWEN_INHERITDATA *d)
struct GWEN_INHERITDATA GWEN_INHERITDATA
Definition: inherit.h:34
GWENHYWFAR_API void GWEN_InheritData_freeData(GWEN_INHERITDATA *d)
GWENHYWFAR_API GWEN_INHERIT_FREEDATAFN GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d)
void GWENHYWFAR_CB(* GWEN_INHERIT_FREEDATAFN)(void *baseData, void *data)
Definition: inherit.h:53
GWENHYWFAR_API GWEN_INHERITDATA * GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
#define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl)
Definition: list1.h:349