gwenhywfar
4.3.3
|
00001 /*************************************************************************** 00002 $RCSfile$ 00003 ------------------- 00004 cvs : $Id$ 00005 begin : Sun Dec 05 2003 00006 copyright : (C) 2003 by Martin Preuss 00007 email : martin@libchipcard.de 00008 00009 *************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00024 * MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 #ifndef GWENHYWFAR_INHERIT_H 00029 #define GWENHYWFAR_INHERIT_H 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 typedef struct GWEN_INHERITDATA GWEN_INHERITDATA; 00035 #ifdef __cplusplus 00036 } 00037 #endif 00038 00039 00040 #include <gwenhywfar/misc.h> 00041 #include <gwenhywfar/gwenhywfarapi.h> 00042 00043 00044 #ifdef __cplusplus 00045 extern "C" { 00046 #endif 00047 00048 00053 typedef void GWENHYWFAR_CB (*GWEN_INHERIT_FREEDATAFN)(void *baseData, 00054 void *data); 00055 00056 GWEN_LIST_FUNCTION_LIB_DEFS(GWEN_INHERITDATA, GWEN_InheritData, GWENHYWFAR_API) 00057 /* No trailing semicolon because this is a macro call */ 00058 00059 GWENHYWFAR_API 00060 GWEN_INHERITDATA *GWEN_InheritData_new(const char *t, 00061 uint32_t id, 00062 void *data, 00063 void *baseData, 00064 GWEN_INHERIT_FREEDATAFN fn); 00065 GWENHYWFAR_API 00066 void GWEN_InheritData_free(GWEN_INHERITDATA *d); 00067 00068 GWENHYWFAR_API 00069 void GWEN_InheritData_freeData(GWEN_INHERITDATA *d); 00070 00071 GWENHYWFAR_API 00072 void GWEN_InheritData_freeAllData(GWEN_INHERITDATA *d); 00073 00074 GWENHYWFAR_API 00075 void GWEN_InheritData_clear(GWEN_INHERITDATA *d); 00076 00077 GWENHYWFAR_API 00078 const char *GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d); 00079 00080 GWENHYWFAR_API 00081 uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d); 00082 00083 GWENHYWFAR_API 00084 void *GWEN_InheritData_GetData(const GWEN_INHERITDATA *d); 00085 00086 GWENHYWFAR_API 00087 GWEN_INHERIT_FREEDATAFN 00088 GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d); 00089 00090 GWENHYWFAR_API 00091 uint32_t GWEN_Inherit_MakeId(const char *typeName); 00092 00093 GWENHYWFAR_API 00094 void* GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l, 00095 uint32_t id, 00096 int wantCreate); 00097 00098 GWENHYWFAR_API 00099 GWEN_INHERITDATA *GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l, 00100 uint32_t id, 00101 int wantCreate); 00102 00112 #define GWEN_INHERIT_ELEMENT(t) \ 00113 GWEN_INHERITDATA_LIST *INHERIT__list; 00114 00125 #define GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl) \ 00126 decl void t##__INHERIT_SETDATA(t *element, \ 00127 const char *typeName,\ 00128 uint32_t id,\ 00129 void *data,\ 00130 GWEN_INHERIT_FREEDATAFN f);\ 00131 decl int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id);\ 00132 decl GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element);\ 00133 decl void t##__INHERIT_UNLINK(t *element, \ 00134 const char *typeName,\ 00135 uint32_t id); 00136 00147 #define GWEN_INHERIT_FUNCTION_DEFS(t) \ 00148 GWEN_INHERIT_FUNCTION_LIB_DEFS(t, GWEN_DUMMY_EMPTY_ARG) 00149 00163 #define GWEN_INHERIT_FUNCTIONS(t) \ 00164 GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element) {\ 00165 assert(element);\ 00166 return element->INHERIT__list;\ 00167 }\ 00168 \ 00169 void t##__INHERIT_SETDATA(t *element, \ 00170 const char *typeName,\ 00171 uint32_t id,\ 00172 void *data,\ 00173 GWEN_INHERIT_FREEDATAFN f) {\ 00174 GWEN_INHERITDATA *d;\ 00175 void *p;\ 00176 \ 00177 assert(element);\ 00178 assert(element->INHERIT__list);\ 00179 \ 00180 p=GWEN_Inherit_FindData(element->INHERIT__list, id, 1);\ 00181 if (p) {\ 00182 fprintf(stderr,\ 00183 "ERROR: Type \"%s\" already inherits base type\n",\ 00184 typeName);\ 00185 abort();\ 00186 }\ 00187 d=GWEN_InheritData_new(typeName, id, data, (void*)element, f);\ 00188 GWEN_InheritData_List_Insert(d, element->INHERIT__list);\ 00189 }\ 00190 \ 00191 int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id) {\ 00192 assert(element);\ 00193 assert(element->INHERIT__list);\ 00194 \ 00195 return (GWEN_Inherit_FindData(element->INHERIT__list, id, 1)!=0);\ 00196 }\ 00197 \ 00198 void t##__INHERIT_UNLINK(t *element, \ 00199 const char *typeName,\ 00200 uint32_t id) {\ 00201 GWEN_INHERITDATA *d;\ 00202 \ 00203 assert(element);\ 00204 assert(element->INHERIT__list);\ 00205 \ 00206 d=GWEN_Inherit_FindEntry(element->INHERIT__list, id, 1);\ 00207 if (!d) {\ 00208 fprintf(stderr, \ 00209 "ERROR: Type \"%s\" does not inherit base type\n",\ 00210 typeName);\ 00211 abort();\ 00212 }\ 00213 GWEN_InheritData_clear(d);\ 00214 GWEN_InheritData_List_Del(d);\ 00215 GWEN_InheritData_free(d);\ 00216 } 00217 00223 #define GWEN_INHERIT_INIT(t, element) {\ 00224 assert(element);\ 00225 element->INHERIT__list=GWEN_InheritData_List_new();\ 00226 } 00227 00228 00238 #define GWEN_INHERIT_FINI(t, element) {\ 00239 GWEN_INHERITDATA *inherit__data;\ 00240 \ 00241 assert(element);\ 00242 assert(element->INHERIT__list);\ 00243 \ 00244 while( (inherit__data=GWEN_InheritData_List_First(element->INHERIT__list)) ) {\ 00245 GWEN_InheritData_freeData(inherit__data); \ 00246 GWEN_InheritData_List_Del(inherit__data); \ 00247 GWEN_InheritData_free(inherit__data); \ 00248 } \ 00249 GWEN_InheritData_List_free(element->INHERIT__list);\ 00250 } 00251 00264 #define GWEN_INHERIT(bt, t) \ 00265 uint32_t t##__INHERIT_ID=0; 00266 00271 #define GWEN_INHERIT_GETDATA(bt, t, element) \ 00272 ((t*)GWEN_Inherit_FindData(bt##__INHERIT_GETLIST(element),t##__INHERIT_ID,0)) 00273 00292 #define GWEN_INHERIT_SETDATA(bt, t, element, data, fn) {\ 00293 if (!t##__INHERIT_ID)\ 00294 t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\ 00295 bt##__INHERIT_SETDATA(element, __STRING(t), t##__INHERIT_ID, data, fn);\ 00296 } 00297 00305 #define GWEN_INHERIT_ISOFTYPE(bt, t, element) \ 00306 ((bt##__INHERIT_ISOFTYPE(element,\ 00307 ((t##__INHERIT_ID==0)?\ 00308 ((t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t)))):\ 00309 t##__INHERIT_ID)))?1:0) 00310 00318 #define GWEN_INHERIT_UNLINK(bt, t, element) {\ 00319 if (!t##__INHERIT_ID)\ 00320 t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\ 00321 bt##__INHERIT_UNLINK(element, __STRING(t), t##__INHERIT_ID);\ 00322 } 00323 00326 /* defgroup */ 00327 00328 00329 #ifdef __cplusplus 00330 } 00331 #endif 00332 00333 00334 00335 #endif /* GWENHYWFAR_INHERIT_P_H */ 00336 00337 00338