Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #define DISABLE_DEBUGLOG
00031
00032 #include "inherit_p.h"
00033 #include <gwenhywfar/misc.h>
00034 #include <gwenhywfar/debug.h>
00035 #include <gwenhywfar/gwenhywfarapi.h>
00036
00037 #include <string.h>
00038
00039
00040
00041 GWEN_LIST_FUNCTIONS(GWEN_INHERITDATA, GWEN_InheritData)
00042
00043
00044
00045 GWEN_INHERITDATA *GWEN_InheritData_new(const char *t,
00046 uint32_t id,
00047 void *data,
00048 void *baseData,
00049 GWEN_INHERIT_FREEDATAFN freeDataFn){
00050 GWEN_INHERITDATA *d;
00051
00052 assert(t);
00053 GWEN_NEW_OBJECT(GWEN_INHERITDATA, d);
00054 GWEN_LIST_INIT(GWEN_INHERITDATA, d);
00055 d->typeName=strdup(t);
00056 d->id=id;
00057 d->data=data;
00058 d->baseData=baseData;
00059 d->freeDataFn=freeDataFn;
00060
00061 DBG_VERBOUS(GWEN_LOGDOMAIN,
00062 "Created inheritance for type \"%s\" (%08x)", t, id);
00063 return d;
00064 }
00065
00066
00067
00068 void GWEN_InheritData_free(GWEN_INHERITDATA *d) {
00069 if (d) {
00070 if (d->freeDataFn)
00071 d->freeDataFn(d->baseData, d->data);
00072 free(d->typeName);
00073 GWEN_LIST_FINI(GWEN_INHERITDATA, d);
00074 GWEN_FREE_OBJECT(d);
00075 }
00076 }
00077
00078
00079
00080 void GWEN_InheritData_freeData(GWEN_INHERITDATA *d) {
00081 if (d) {
00082 DBG_VERBOUS(GWEN_LOGDOMAIN,
00083 "Freeing data for type \"%s\"",
00084 d->typeName);
00085 if (d->freeDataFn)
00086 d->freeDataFn(d->baseData, d->data);
00087 d->freeDataFn=NULL;
00088 d->data=NULL;
00089 }
00090 }
00091
00092
00093
00094 void GWEN_InheritData_clear(GWEN_INHERITDATA *d){
00095 assert(d);
00096 d->freeDataFn=0;
00097 d->data=0;
00098 }
00099
00100
00101
00102 const char *GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d){
00103 assert(d);
00104 return d->typeName;
00105 }
00106
00107
00108
00109 uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d){
00110 assert(d);
00111 return d->id;
00112 }
00113
00114
00115
00116 void *GWEN_InheritData_GetData(const GWEN_INHERITDATA *d){
00117 assert(d);
00118 return d->data;
00119 }
00120
00121
00122
00123 GWEN_INHERIT_FREEDATAFN
00124 GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d){
00125 assert(d);
00126 return d->freeDataFn;
00127 }
00128
00129
00130
00131
00132
00133 uint32_t GWEN_Inherit_MakeId(const char *typeName){
00134 unsigned int i, j;
00135 uint32_t result;
00136
00137 result=0;
00138 j=strlen(typeName);
00139 for (i=0; i<j; i++) {
00140 uint32_t tmpResult;
00141 unsigned char c;
00142
00143 tmpResult=result<<8;
00144 c=((result>>24)&0xff);
00145 result=tmpResult|c;
00146 result^=(unsigned char)(typeName[i]);
00147 }
00148
00149 DBG_VERBOUS(GWEN_LOGDOMAIN,
00150 "Id for type \"%s\" is \"%08x\"",
00151 typeName, result);
00152 return result;
00153 }
00154
00155
00156
00157 void *GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l,
00158 uint32_t id,
00159 int wantCreate){
00160 GWEN_INHERITDATA *ih;
00161
00162 assert(l);
00163
00164 DBG_VERBOUS(GWEN_LOGDOMAIN,
00165 "Searching for inheritance id \"%08x\"", id);
00166 ih=GWEN_InheritData_List_First(l);
00167 while(ih) {
00168 DBG_VERBOUS(GWEN_LOGDOMAIN,
00169 "Checking type \"%s\" (%08x) against %08x",
00170 ih->typeName, ih->id, id);
00171 if (ih->id==id)
00172 return ih->data;
00173 ih=GWEN_InheritData_List_Next(ih);
00174 }
00175 if (!wantCreate) {
00176 DBG_WARN(GWEN_LOGDOMAIN,
00177 "Type \"%08x\" not derived from this base type", id);
00178 }
00179 return 0;
00180 }
00181
00182
00183
00184 GWEN_INHERITDATA *GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l,
00185 uint32_t id,
00186 int wantCreate){
00187 GWEN_INHERITDATA *ih;
00188
00189 assert(l);
00190
00191 DBG_VERBOUS(GWEN_LOGDOMAIN, "Searching for inheritance id \"%08x\"", id);
00192 ih=GWEN_InheritData_List_First(l);
00193 while(ih) {
00194 DBG_VERBOUS(GWEN_LOGDOMAIN, "Checking type \"%s\" (%08x) against %08x",
00195 ih->typeName, ih->id, id);
00196 if (ih->id==id)
00197 return ih;
00198 ih=GWEN_InheritData_List_Next(ih);
00199 }
00200 if (!wantCreate) {
00201 DBG_WARN(GWEN_LOGDOMAIN,
00202 "Type \"%08x\" not derived from this base type", id);
00203 }
00204 return 0;
00205 }
00206
00207
00208
00209
00210