inherit.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  $RCSfile: inherit.h,v $
00003                              -------------------
00004     cvs         : $Id: inherit.h,v 1.15 2004/08/18 11:04:50 cstim Exp $
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 (*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                                          GWEN_TYPE_UINT32 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_clear(GWEN_INHERITDATA *d);
00070 
00071   GWENHYWFAR_API 
00072   const char *GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d);
00073 
00074   GWENHYWFAR_API 
00075   GWEN_TYPE_UINT32 GWEN_InheritData_GetId(const GWEN_INHERITDATA *d);
00076 
00077   GWENHYWFAR_API 
00078   void *GWEN_InheritData_GetData(const GWEN_INHERITDATA *d);
00079 
00080   GWENHYWFAR_API 
00081     GWEN_INHERIT_FREEDATAFN
00082     GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d);
00083 
00084   GWENHYWFAR_API 
00085   GWEN_TYPE_UINT32 GWEN_Inherit_MakeId(const char *typeName);
00086 
00087   GWENHYWFAR_API 
00088   void* GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l,
00089                               GWEN_TYPE_UINT32 id,
00090                               int wantCreate);
00091 
00092   GWENHYWFAR_API
00093     GWEN_INHERITDATA *GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l,
00094                                              GWEN_TYPE_UINT32 id,
00095                                              int wantCreate);
00096 
00106 #define GWEN_INHERIT_ELEMENT(t) \
00107   GWEN_INHERITDATA_LIST *INHERIT__list;
00108 
00119 #define GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl) \
00120   decl void t##__INHERIT_SETDATA(t *element, \
00121                                  const char *typeName,\
00122                                  GWEN_TYPE_UINT32 id,\
00123                                  void *data,\
00124                                  GWEN_INHERIT_FREEDATAFN f);\
00125   decl int t##__INHERIT_ISOFTYPE(t *element, GWEN_TYPE_UINT32 id);\
00126   decl GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element);\
00127   decl void t##__INHERIT_UNLINK(t *element, \
00128                                 const char *typeName,\
00129                                 GWEN_TYPE_UINT32 id);
00130 
00141 #define GWEN_INHERIT_FUNCTION_DEFS(t) \
00142   GWEN_INHERIT_FUNCTION_LIB_DEFS(t, GWEN_DUMMY_EMPTY_ARG)
00143 
00157 #define GWEN_INHERIT_FUNCTIONS(t) \
00158   GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element) {\
00159   assert(element);\
00160   return element->INHERIT__list;\
00161   }\
00162   \
00163   void t##__INHERIT_SETDATA(t *element, \
00164                             const char *typeName,\
00165                             GWEN_TYPE_UINT32 id,\
00166                             void *data,\
00167                             GWEN_INHERIT_FREEDATAFN f) {\
00168   GWEN_INHERITDATA *d;\
00169   void *p;\
00170     \
00171     assert(element);\
00172     assert(element->INHERIT__list);\
00173     \
00174     p=GWEN_Inherit_FindData(element->INHERIT__list, id, 1);\
00175     if (p) {\
00176       fprintf(stderr,\
00177               "ERROR: Type \"%s\" already inherits base type\n",\
00178               typeName);\
00179       abort();\
00180     }\
00181     d=GWEN_InheritData_new(typeName, id, data, (void*)element, f);\
00182     GWEN_InheritData_List_Insert(d, element->INHERIT__list);\
00183   }\
00184   \
00185   int t##__INHERIT_ISOFTYPE(t *element, GWEN_TYPE_UINT32 id) {\
00186     assert(element);\
00187     assert(element->INHERIT__list);\
00188   \
00189     return (GWEN_Inherit_FindData(element->INHERIT__list, id, 1)!=0);\
00190   }\
00191   \
00192   void t##__INHERIT_UNLINK(t *element, \
00193                            const char *typeName,\
00194                            GWEN_TYPE_UINT32 id) {\
00195     GWEN_INHERITDATA *d;\
00196     \
00197     assert(element);\
00198     assert(element->INHERIT__list);\
00199     \
00200     d=GWEN_Inherit_FindEntry(element->INHERIT__list, id, 1);\
00201     if (!d) {\
00202       fprintf(stderr, \
00203               "ERROR: Type \"%s\" does not inherit base type\n",\
00204               typeName);\
00205       abort();\
00206     }\
00207     GWEN_InheritData_clear(d);\
00208     GWEN_InheritData_List_Del(d);\
00209     GWEN_InheritData_free(d);\
00210   }
00211 
00217 #define GWEN_INHERIT_INIT(t, element) {\
00218     assert(element);\
00219     element->INHERIT__list=GWEN_InheritData_List_new();\
00220   }
00221 
00222 
00232 #define GWEN_INHERIT_FINI(t, element) {\
00233     assert(element);\
00234     GWEN_InheritData_List_free(element->INHERIT__list);\
00235   }
00236 
00249 #define GWEN_INHERIT(bt, t) \
00250   GWEN_TYPE_UINT32 t##__INHERIT_ID=0;
00251 
00256 #define GWEN_INHERIT_GETDATA(bt, t, element) \
00257   ((t*)GWEN_Inherit_FindData(bt##__INHERIT_GETLIST(element),t##__INHERIT_ID,0))
00258 
00277 #define GWEN_INHERIT_SETDATA(bt, t, element, data, fn) {\
00278     if (!t##__INHERIT_ID)\
00279       t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
00280     bt##__INHERIT_SETDATA(element, __STRING(t), t##__INHERIT_ID, data, fn);\
00281   }
00282 
00290 #define GWEN_INHERIT_ISOFTYPE(bt, t, element) \
00291   ((bt##__INHERIT_ISOFTYPE(element,\
00292                            ((t##__INHERIT_ID==0)?\
00293                             ((t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t)))):\
00294                             t##__INHERIT_ID)))?1:0)
00295 
00303 #define GWEN_INHERIT_UNLINK(bt, t, element) {\
00304     if (!t##__INHERIT_ID)\
00305       t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
00306     bt##__INHERIT_UNLINK(element, __STRING(t), t##__INHERIT_ID);\
00307   }
00308 
00311  /* defgroup */
00312 
00313 
00314 #ifdef __cplusplus
00315 }
00316 #endif
00317 
00318 
00319 
00320 #endif /* GWENHYWFAR_INHERIT_P_H */
00321 
00322 
00323 

Generated on Wed Mar 8 22:38:26 2006 for gwenhywfar by  doxygen 1.4.6