gwenhywfar 5.12.0
inherit.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Sun Dec 05 2003
3 copyright : (C) 2003-2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 * *
23 ***************************************************************************/
24
25
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30#define DISABLE_DEBUGLOG
31
32#include "inherit_p.h"
33#include <gwenhywfar/misc.h>
34#include <gwenhywfar/debug.h>
35#include <gwenhywfar/gwenhywfarapi.h>
36
37#include <string.h>
38
39
40
42
43
44
46 uint32_t id,
47 void *data,
48 void *baseData,
49 GWEN_INHERIT_FREEDATAFN freeDataFn)
50{
52
53 assert(t);
56 d->typeName=strdup(t);
57 d->id=id;
58 d->data=data;
59 d->baseData=baseData;
60 d->freeDataFn=freeDataFn;
61
63 "Created inheritance for type \"%s\" (%08x)", t, id);
64 return d;
65}
66
67
68
70{
71 if (d) {
72 if (d->freeDataFn)
73 d->freeDataFn(d->baseData, d->data);
74 free(d->typeName);
77 }
78}
79
80
81
83{
84 if (d) {
86 "Freeing data for type \"%s\"",
87 d->typeName);
88 if (d->freeDataFn)
89 d->freeDataFn(d->baseData, d->data);
90 d->freeDataFn=NULL;
91 d->data=NULL;
92 }
93}
94
95
96
98{
99 assert(d);
100 d->freeDataFn=0;
101 d->data=0;
102}
103
104
105
107{
108 assert(d);
109 return d->typeName;
110}
111
112
113
115{
116 assert(d);
117 return d->id;
118}
119
120
121
123{
124 assert(d);
125 return d->data;
126}
127
128
129
131{
132 assert(d);
133 return d->freeDataFn;
134}
135
136
137
138
139
140uint32_t GWEN_Inherit_MakeId(const char *typeName)
141{
142 unsigned int i, j;
143 uint32_t result;
144
145 result=0;
146 j=strlen(typeName);
147 for (i=0; i<j; i++) {
148 uint32_t tmpResult;
149 unsigned char c;
150
151 tmpResult=result<<8;
152 c=((result>>24)&0xff);
153 result=tmpResult|c;
154 result^=(unsigned char)(typeName[i]);
155 }
156
158 "Id for type \"%s\" is \"%08x\"",
159 typeName, result);
160 return result;
161}
162
163
164
166 uint32_t id,
167 int wantCreate)
168{
170
171 assert(l);
172
174 "Searching for inheritance id \"%08x\"", id);
176 while (ih) {
178 "Checking type \"%s\" (%08x) against %08x",
179 ih->typeName, ih->id, id);
180 if (ih->id==id)
181 return ih->data;
183 } /* while */
184 if (!wantCreate) {
186 "Type \"%08x\" not derived from this base type", id);
187 }
188 return 0;
189}
190
191
192
194 uint32_t id,
195 int wantCreate)
196{
198
199 assert(l);
200
201 DBG_VERBOUS(GWEN_LOGDOMAIN, "Searching for inheritance id \"%08x\"", id);
203 while (ih) {
204 DBG_VERBOUS(GWEN_LOGDOMAIN, "Checking type \"%s\" (%08x) against %08x",
205 ih->typeName, ih->id, id);
206 if (ih->id==id)
207 return ih;
209 } /* while */
210 if (!wantCreate) {
212 "Type \"%08x\" not derived from this base type", id);
213 }
214 return 0;
215}
216
217
218
219
220
#define NULL
Definition binreloc.c:300
#define DBG_VERBOUS(dbg_logger, format,...)
Definition debug.h:224
#define DBG_WARN(dbg_logger, format,...)
Definition debug.h:125
const char * GWEN_InheritData_GetTypeName(const GWEN_INHERITDATA *d)
Definition inherit.c:106
GWEN_INHERIT_FREEDATAFN GWEN_InheritData_GetFreeDataFn(const GWEN_INHERITDATA *d)
Definition inherit.c:130
GWEN_INHERITDATA * GWEN_InheritData_new(const char *t, uint32_t id, void *data, void *baseData, GWEN_INHERIT_FREEDATAFN freeDataFn)
Definition inherit.c:45
void * GWEN_InheritData_GetData(const GWEN_INHERITDATA *d)
Definition inherit.c:122
void GWEN_InheritData_freeData(GWEN_INHERITDATA *d)
Definition inherit.c:82
GWEN_INHERITDATA * GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
Definition inherit.c:193
uint32_t GWEN_InheritData_GetId(const GWEN_INHERITDATA *d)
Definition inherit.c:114
void GWEN_InheritData_clear(GWEN_INHERITDATA *d)
Definition inherit.c:97
void GWEN_InheritData_free(GWEN_INHERITDATA *d)
Definition inherit.c:69
uint32_t GWEN_Inherit_MakeId(const char *typeName)
Definition inherit.c:140
void * GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
Definition inherit.c:165
struct GWEN_INHERITDATA GWEN_INHERITDATA
Definition inherit.h:34
void GWENHYWFAR_CB(* GWEN_INHERIT_FREEDATAFN)(void *baseData, void *data)
Definition inherit.h:53
#define GWEN_LIST_FINI(t, element)
Definition list1.h:475
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition list1.h:367
#define GWEN_LIST_INIT(t, element)
Definition list1.h:466
GWEN_INHERITDATA * GWEN_InheritData_List_Next(const GWEN_INHERITDATA *element)
GWEN_INHERITDATA * GWEN_InheritData_List_First(const GWEN_INHERITDATA_LIST *l)
#define GWEN_LOGDOMAIN
Definition logger.h:35
#define GWEN_FREE_OBJECT(varname)
Definition memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55