inherit.h
Go to the documentation of this file.
/***************************************************************************
$RCSfile$
-------------------
cvs : $Id$
begin : Sun Dec 05 2003
copyright : (C) 2003 by Martin Preuss
email : martin@libchipcard.de
***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
* MA 02111-1307 USA *
* *
***************************************************************************/
#ifndef GWENHYWFAR_INHERIT_H
#define GWENHYWFAR_INHERIT_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct GWEN_INHERITDATA GWEN_INHERITDATA;
#ifdef __cplusplus
}
#endif
#include <gwenhywfar/misc.h>
#include <gwenhywfar/gwenhywfarapi.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void GWENHYWFAR_CB(*GWEN_INHERIT_FREEDATAFN)(void *baseData,
void *data);
GWEN_LIST_FUNCTION_LIB_DEFS(GWEN_INHERITDATA, GWEN_InheritData, GWENHYWFAR_API)
/* No trailing semicolon because this is a macro call */
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_free(GWEN_INHERITDATA *d);
GWENHYWFAR_API
void GWEN_InheritData_freeData(GWEN_INHERITDATA *d);
GWENHYWFAR_API
void GWEN_InheritData_freeAllData(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
uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d);
GWENHYWFAR_API
void *GWEN_InheritData_GetData(const GWEN_INHERITDATA *d);
GWENHYWFAR_API
GWEN_INHERIT_FREEDATAFN
GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d);
GWENHYWFAR_API
uint32_t GWEN_Inherit_MakeId(const char *typeName);
GWENHYWFAR_API
void *GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l,
uint32_t id,
int wantCreate);
GWENHYWFAR_API
GWEN_INHERITDATA *GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l,
uint32_t id,
int wantCreate);
#define GWEN_INHERIT_ELEMENT(t) \
GWEN_INHERITDATA_LIST *INHERIT__list;
#define GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl) \
decl void t##__INHERIT_SETDATA(t *element, \
const char *typeName,\
uint32_t id,\
void *data,\
GWEN_INHERIT_FREEDATAFN f);\
decl int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id);\
decl GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element);\
decl void t##__INHERIT_UNLINK(t *element, \
const char *typeName,\
uint32_t id);
#define GWEN_INHERIT_FUNCTION_DEFS(t) \
GWEN_INHERIT_FUNCTION_LIB_DEFS(t, GWEN_DUMMY_EMPTY_ARG)
#define GWEN_INHERIT_FUNCTIONS(t) \
GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element) {\
assert(element);\
return element->INHERIT__list;\
}\
\
void t##__INHERIT_SETDATA(t *element, \
const char *typeName,\
uint32_t id,\
void *data,\
GWEN_INHERIT_FREEDATAFN f) {\
GWEN_INHERITDATA *d;\
void *p;\
\
assert(element);\
assert(element->INHERIT__list);\
\
p=GWEN_Inherit_FindData(element->INHERIT__list, id, 1);\
if (p) {\
fprintf(stderr,\
"ERROR: Type \"%s\" already inherits base type\n",\
typeName);\
abort();\
}\
d=GWEN_InheritData_new(typeName, id, data, (void*)element, f);\
GWEN_InheritData_List_Insert(d, element->INHERIT__list);\
}\
\
int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id) {\
assert(element);\
assert(element->INHERIT__list);\
\
return (GWEN_Inherit_FindData(element->INHERIT__list, id, 1)!=0);\
}\
\
void t##__INHERIT_UNLINK(t *element, \
const char *typeName,\
uint32_t id) {\
GWEN_INHERITDATA *d;\
\
assert(element);\
assert(element->INHERIT__list);\
\
d=GWEN_Inherit_FindEntry(element->INHERIT__list, id, 1);\
if (!d) {\
fprintf(stderr, \
"ERROR: Type \"%s\" does not inherit base type\n",\
typeName);\
abort();\
}\
GWEN_InheritData_clear(d);\
GWEN_InheritData_List_Del(d);\
GWEN_InheritData_free(d);\
}
#define GWEN_INHERIT_INIT(t, element) {\
assert(element);\
element->INHERIT__list=GWEN_InheritData_List_new();\
}
#define GWEN_INHERIT_FINI(t, element) {\
GWEN_INHERITDATA *inherit__data;\
\
assert(element);\
assert(element->INHERIT__list);\
\
while( (inherit__data=GWEN_InheritData_List_First(element->INHERIT__list)) ) {\
GWEN_InheritData_freeData(inherit__data); \
GWEN_InheritData_List_Del(inherit__data); \
GWEN_InheritData_free(inherit__data); \
} \
GWEN_InheritData_List_free(element->INHERIT__list);\
}
#define GWEN_INHERIT(bt, t) \
uint32_t t##__INHERIT_ID=0;
#define GWEN_INHERIT_REF(bt, t) \
extern uint32_t t##__INHERIT_ID;
#define GWEN_INHERIT_GETDATA(bt, t, element) \
((t*)GWEN_Inherit_FindData(bt##__INHERIT_GETLIST(element),t##__INHERIT_ID,0))
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn) {\
if (!t##__INHERIT_ID)\
t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
bt##__INHERIT_SETDATA(element, __STRING(t), t##__INHERIT_ID, data, fn);\
}
#define GWEN_INHERIT_ISOFTYPE(bt, t, element) \
((bt##__INHERIT_ISOFTYPE(element,\
((t##__INHERIT_ID==0)?\
((t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t)))):\
t##__INHERIT_ID)))?1:0)
#define GWEN_INHERIT_UNLINK(bt, t, element) {\
if (!t##__INHERIT_ID)\
t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
bt##__INHERIT_UNLINK(element, __STRING(t), t##__INHERIT_ID);\
}
/* defgroup */
#ifdef __cplusplus
}
#endif
#endif /* GWENHYWFAR_INHERIT_P_H */
gwenhywfarapi.h
GWENHYWFAR_API
#define GWENHYWFAR_API
Definition gwenhywfarapi.h:67
GWENHYWFAR_CB
#define GWENHYWFAR_CB
Definition gwenhywfarapi.h:89
GWEN_Inherit_FindData
GWENHYWFAR_API void * GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
GWEN_InheritData_new
GWENHYWFAR_API GWEN_INHERITDATA * GWEN_InheritData_new(const char *t, uint32_t id, void *data, void *baseData, GWEN_INHERIT_FREEDATAFN fn)
GWEN_InheritData_GetData
GWENHYWFAR_API void * GWEN_InheritData_GetData(const GWEN_INHERITDATA *d)
GWEN_Inherit_MakeId
GWENHYWFAR_API uint32_t GWEN_Inherit_MakeId(const char *typeName)
GWEN_InheritData_GetId
GWENHYWFAR_API uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d)
GWEN_InheritData_clear
GWENHYWFAR_API void GWEN_InheritData_clear(GWEN_INHERITDATA *d)
GWEN_InheritData_GetTypeName
GWENHYWFAR_API const char * GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d)
GWEN_InheritData_freeAllData
GWENHYWFAR_API void GWEN_InheritData_freeAllData(GWEN_INHERITDATA *d)
GWEN_InheritData_free
GWENHYWFAR_API void GWEN_InheritData_free(GWEN_INHERITDATA *d)
GWEN_INHERITDATA
struct GWEN_INHERITDATA GWEN_INHERITDATA
Definition inherit.h:34
GWEN_InheritData_freeData
GWENHYWFAR_API void GWEN_InheritData_freeData(GWEN_INHERITDATA *d)
GWEN_InheritData_GetFreeDataFn
GWENHYWFAR_API GWEN_INHERIT_FREEDATAFN GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d)
GWEN_INHERIT_FREEDATAFN
void GWENHYWFAR_CB(* GWEN_INHERIT_FREEDATAFN)(void *baseData, void *data)
Definition inherit.h:53
GWEN_Inherit_FindEntry
GWENHYWFAR_API GWEN_INHERITDATA * GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
GWEN_LIST_FUNCTION_LIB_DEFS
#define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl)
Definition list1.h:349
misc.h
GWEN_INHERITDATA_LIST
Definition listdoc.h:4437