1 /**********************************************************
2 * This file has been automatically created by "typemaker2"
3 * from the file "balance.xml".
4 * Please do not edit this file, all changes will be lost.
5 * Better edit the mentioned source file instead.
6 **********************************************************/
7
8 #ifdef HAVE_CONFIG_H
9 # include <config.h>
10 #endif
11
12 #include "./balance_p.h"
13
14 #include <gwenhywfar/misc.h>
15 #include <gwenhywfar/debug.h>
16
17 /* code headers */
18
19 /* macro functions */
GWEN_LIST_FUNCTIONS(AB_BALANCE,AB_Balance)20 GWEN_LIST_FUNCTIONS(AB_BALANCE, AB_Balance)
21
22
23 AB_BALANCE_TYPE AB_Balance_Type_fromString(const char *p_s)
24 {
25 if (p_s && *p_s) {
26 if (strcasecmp(p_s, "none")==0)
27 return AB_Balance_TypeNone;
28 else if (strcasecmp(p_s, "noted")==0)
29 return AB_Balance_TypeNoted;
30 else if (strcasecmp(p_s, "booked")==0)
31 return AB_Balance_TypeBooked;
32 else if (strcasecmp(p_s, "bankLine")==0)
33 return AB_Balance_TypeBankLine;
34 else if (strcasecmp(p_s, "disposable")==0)
35 return AB_Balance_TypeDisposable;
36 else if (strcasecmp(p_s, "temporary")==0)
37 return AB_Balance_TypeTemporary;
38 else if (strcasecmp(p_s, "dayStart")==0)
39 return AB_Balance_TypeDayStart;
40 else if (strcasecmp(p_s, "dayEnd")==0)
41 return AB_Balance_TypeDayEnd;
42 }
43 return AB_Balance_TypeUnknown;
44 }
45
AB_Balance_Type_toString(AB_BALANCE_TYPE p_i)46 const char *AB_Balance_Type_toString(AB_BALANCE_TYPE p_i)
47 {
48 switch (p_i) {
49 case AB_Balance_TypeNone:
50 return "none";
51 case AB_Balance_TypeNoted:
52 return "noted";
53 case AB_Balance_TypeBooked:
54 return "booked";
55 case AB_Balance_TypeBankLine:
56 return "bankLine";
57 case AB_Balance_TypeDisposable:
58 return "disposable";
59 case AB_Balance_TypeTemporary:
60 return "temporary";
61 case AB_Balance_TypeDayStart:
62 return "dayStart";
63 case AB_Balance_TypeDayEnd:
64 return "dayEnd";
65 case AB_Balance_TypeUnknown:
66 default:
67 return "unknown";
68 }
69 }
70
AB_Balance_new(void)71 AB_BALANCE *AB_Balance_new(void)
72 {
73 AB_BALANCE *p_struct;
74
75 GWEN_NEW_OBJECT(AB_BALANCE, p_struct)
76 p_struct->_refCount=1;
77 GWEN_LIST_INIT(AB_BALANCE, p_struct)
78 /* members */
79 p_struct->date=NULL;
80 p_struct->value=AB_Value_new();
81 p_struct->type=AB_Balance_TypeUnknown;
82 /* virtual functions */
83
84 return p_struct;
85 }
86
AB_Balance_free(AB_BALANCE * p_struct)87 void AB_Balance_free(AB_BALANCE *p_struct)
88 {
89 if (p_struct) {
90 assert(p_struct->_refCount);
91 if (p_struct->_refCount==1) {
92 GWEN_LIST_FINI(AB_BALANCE, p_struct)
93 /* members */
94 GWEN_Date_free(p_struct->date);
95 p_struct->date=NULL;
96 AB_Value_free(p_struct->value);
97 p_struct->_refCount=0;
98 GWEN_FREE_OBJECT(p_struct);
99 }
100 else
101 p_struct->_refCount--;
102 }
103 }
104
AB_Balance_Attach(AB_BALANCE * p_struct)105 void AB_Balance_Attach(AB_BALANCE *p_struct)
106 {
107 assert(p_struct);
108 assert(p_struct->_refCount);
109 p_struct->_refCount++;
110 }
111
AB_Balance_dup(const AB_BALANCE * p_src)112 AB_BALANCE *AB_Balance_dup(const AB_BALANCE *p_src)
113 {
114 AB_BALANCE *p_struct;
115
116 assert(p_src);
117 p_struct=AB_Balance_new();
118 /* member "date" */
119 if (p_struct->date) {
120 GWEN_Date_free(p_struct->date);
121 p_struct->date=NULL;
122 p_struct->date=NULL;
123 }
124 if (p_src->date) {
125 p_struct->date=GWEN_Date_dup(p_src->date);
126 }
127
128 /* member "value" */
129 if (p_struct->value) {
130 AB_Value_free(p_struct->value);
131 p_struct->value=NULL;
132 }
133 if (p_src->value) {
134 p_struct->value=AB_Value_dup(p_src->value);
135 }
136
137 /* member "type" */
138 p_struct->type=p_src->type;
139
140 return p_struct;
141 }
142
AB_Balance_copy(AB_BALANCE * p_struct,const AB_BALANCE * p_src)143 AB_BALANCE *AB_Balance_copy(AB_BALANCE *p_struct, const AB_BALANCE *p_src)
144 {
145 assert(p_struct);
146 assert(p_src);
147 /* member "date" */
148 if (p_struct->date) {
149 GWEN_Date_free(p_struct->date);
150 p_struct->date=NULL;
151 p_struct->date=NULL;
152 }
153 if (p_src->date) {
154 p_struct->date=GWEN_Date_dup(p_src->date);
155 }
156
157 /* member "value" */
158 if (p_struct->value) {
159 AB_Value_free(p_struct->value);
160 p_struct->value=NULL;
161 }
162 if (p_src->value) {
163 p_struct->value=AB_Value_dup(p_src->value);
164 }
165
166 /* member "type" */
167 p_struct->type=p_src->type;
168
169 return p_struct;
170 }
171
AB_Balance_GetDate(const AB_BALANCE * p_struct)172 const GWEN_DATE *AB_Balance_GetDate(const AB_BALANCE *p_struct)
173 {
174 assert(p_struct);
175 return p_struct->date;
176 }
177
AB_Balance_GetValue(const AB_BALANCE * p_struct)178 const AB_VALUE *AB_Balance_GetValue(const AB_BALANCE *p_struct)
179 {
180 assert(p_struct);
181 return p_struct->value;
182 }
183
AB_Balance_GetType(const AB_BALANCE * p_struct)184 AB_BALANCE_TYPE AB_Balance_GetType(const AB_BALANCE *p_struct)
185 {
186 assert(p_struct);
187 return p_struct->type;
188 }
189
AB_Balance_SetDate(AB_BALANCE * p_struct,const GWEN_DATE * p_src)190 void AB_Balance_SetDate(AB_BALANCE *p_struct, const GWEN_DATE *p_src)
191 {
192 assert(p_struct);
193 if (p_struct->date) {
194 GWEN_Date_free(p_struct->date);
195 p_struct->date=NULL;
196 }
197 if (p_src) {
198 p_struct->date=GWEN_Date_dup(p_src);
199 }
200 else {
201 p_struct->date=NULL;
202 }
203 }
204
AB_Balance_SetValue(AB_BALANCE * p_struct,const AB_VALUE * p_src)205 void AB_Balance_SetValue(AB_BALANCE *p_struct, const AB_VALUE *p_src)
206 {
207 assert(p_struct);
208 if (p_struct->value) {
209 AB_Value_free(p_struct->value);
210 }
211 if (p_src) {
212 p_struct->value=AB_Value_dup(p_src);
213 }
214 else {
215 p_struct->value=AB_Value_new();
216 }
217 }
218
AB_Balance_SetType(AB_BALANCE * p_struct,AB_BALANCE_TYPE p_src)219 void AB_Balance_SetType(AB_BALANCE *p_struct, AB_BALANCE_TYPE p_src)
220 {
221 assert(p_struct);
222 p_struct->type=p_src;
223 }
224
225 /* list1 functions */
AB_Balance_List_dup(const AB_BALANCE_LIST * p_src)226 AB_BALANCE_LIST *AB_Balance_List_dup(const AB_BALANCE_LIST *p_src)
227 {
228 AB_BALANCE_LIST *p_dest;
229 AB_BALANCE *p_elem;
230
231 assert(p_src);
232 p_dest=AB_Balance_List_new();
233 p_elem=AB_Balance_List_First(p_src);
234 while (p_elem) {
235 AB_BALANCE *p_cpy;
236
237 p_cpy=AB_Balance_dup(p_elem);
238 AB_Balance_List_Add(p_cpy, p_dest);
239 p_elem=AB_Balance_List_Next(p_elem);
240 }
241
242 return p_dest;
243 }
244
AB_Balance_ReadDb(AB_BALANCE * p_struct,GWEN_DB_NODE * p_db)245 void AB_Balance_ReadDb(AB_BALANCE *p_struct, GWEN_DB_NODE *p_db)
246 {
247 assert(p_struct);
248 /* member "date" */
249 if (p_struct->date) {
250 GWEN_Date_free(p_struct->date);
251 p_struct->date=NULL;
252 }
253 {
254 const char *s;
255 s=GWEN_DB_GetCharValue(p_db, "date", 0, NULL);
256 if (s && *s)
257 p_struct->date=GWEN_Date_fromString(s);
258 }
259 if (p_struct->date==NULL) {
260 p_struct->date=NULL;
261 }
262
263 /* member "value" */
264 if (p_struct->value) {
265 AB_Value_free(p_struct->value);
266 }
267 {
268 const char *s;
269 s=GWEN_DB_GetCharValue(p_db, "value", 0, NULL);
270 if (s)
271 p_struct->value=AB_Value_fromString(s);
272 else
273 p_struct->value=NULL;
274 }
275 if (p_struct->value==NULL) {
276 p_struct->value=AB_Value_new();
277 }
278
279 /* member "type" */
280 {
281 const char *s;
282 s=GWEN_DB_GetCharValue(p_db, "type", 0, NULL);
283 if (s)
284 p_struct->type=AB_Balance_Type_fromString(s);
285 else
286 p_struct->type=AB_Balance_TypeUnknown;
287 }
288
289 }
290
AB_Balance_WriteDb(const AB_BALANCE * p_struct,GWEN_DB_NODE * p_db)291 int AB_Balance_WriteDb(const AB_BALANCE *p_struct, GWEN_DB_NODE *p_db)
292 {
293 int p_rv;
294
295 assert(p_struct);
296 /* member "date" */
297 if (p_struct->date) {
298 const char *s=GWEN_Date_GetString(p_struct->date);
299 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "date", s);
300 }
301 else {
302 GWEN_DB_DeleteVar(p_db, "date");
303 p_rv=0;
304 }
305 if (p_rv<0) {
306 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
307 return p_rv;
308 }
309
310 /* member "value" */
311 if (p_struct->value) {
312 GWEN_BUFFER *tbuf=GWEN_Buffer_new(0, 64, 0, 1);
313 AB_Value_toString(p_struct->value, tbuf);
314 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "value", GWEN_Buffer_GetStart(tbuf));
315 GWEN_Buffer_free(tbuf);
316 }
317 else {
318 GWEN_DB_DeleteVar(p_db, "value");
319 p_rv=0;
320 }
321 if (p_rv<0) {
322 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
323 return p_rv;
324 }
325
326 /* member "type" */
327 p_rv=GWEN_DB_SetCharValue(p_db, GWEN_DB_FLAGS_OVERWRITE_VARS, "type", AB_Balance_Type_toString(p_struct->type));
328 if (p_rv<0) {
329 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)\n", p_rv);
330 return p_rv;
331 }
332
333 return 0;
334 }
335
AB_Balance_fromDb(GWEN_DB_NODE * p_db)336 AB_BALANCE *AB_Balance_fromDb(GWEN_DB_NODE *p_db)
337 {
338 AB_BALANCE *p_struct;
339 p_struct=AB_Balance_new();
340 AB_Balance_ReadDb(p_struct, p_db);
341 return p_struct;
342 }
343
AB_Balance_toDb(const AB_BALANCE * p_struct,GWEN_DB_NODE * p_db)344 int AB_Balance_toDb(const AB_BALANCE *p_struct, GWEN_DB_NODE *p_db)
345 {
346 return AB_Balance_WriteDb(p_struct, p_db);
347 }
348
AB_Balance_ReadXml(AB_BALANCE * p_struct,GWEN_XMLNODE * p_db)349 void AB_Balance_ReadXml(AB_BALANCE *p_struct, GWEN_XMLNODE *p_db)
350 {
351 assert(p_struct);
352 /* member "date" */
353 if (p_struct->date) {
354 GWEN_Date_free(p_struct->date);
355 p_struct->date=NULL;
356 }
357 {
358 const char *s;
359 s=GWEN_XMLNode_GetCharValue(p_db, "date", NULL);
360 if (s && *s)
361 p_struct->date=GWEN_Date_fromString(s);
362 }
363 if (p_struct->date==NULL) { /* preset member "date" if empty */
364 p_struct->date=NULL;
365 }
366
367 /* member "value" */
368 if (p_struct->value) {
369 AB_Value_free(p_struct->value);
370 }
371 {
372 const char *s;
373 s=GWEN_XMLNode_GetCharValue(p_db, "value", NULL);
374 if (s)
375 p_struct->value=AB_Value_fromString(s);
376 else
377 p_struct->value=NULL;
378 }
379 if (p_struct->value==NULL) { /* preset member "value" if empty */
380 p_struct->value=AB_Value_new();
381 }
382
383 /* member "type" */
384 {
385 const char *s;
386 s=GWEN_XMLNode_GetCharValue(p_db, "type", NULL);
387 if (s)
388 p_struct->type=AB_Balance_Type_fromString(s);
389 else
390 p_struct->type=AB_Balance_TypeUnknown;
391 }
392
393 }
394
AB_Balance_WriteXml(const AB_BALANCE * p_struct,GWEN_XMLNODE * p_db)395 void AB_Balance_WriteXml(const AB_BALANCE *p_struct, GWEN_XMLNODE *p_db)
396 {
397 assert(p_struct);
398 /* member "date" */
399 if (p_struct->date) {
400 const char *s=GWEN_Date_GetString(p_struct->date);
401 GWEN_XMLNode_SetCharValue(p_db, "date", s);
402 }
403
404 /* member "value" */
405 if (p_struct->value) {
406 GWEN_BUFFER *tbuf=GWEN_Buffer_new(0, 64, 0, 1);
407 AB_Value_toString(p_struct->value, tbuf);
408 GWEN_XMLNode_SetCharValue(p_db, "value", GWEN_Buffer_GetStart(tbuf));
409 GWEN_Buffer_free(tbuf);
410 }
411
412 /* member "type" */
413 GWEN_XMLNode_SetCharValue(p_db, "type", AB_Balance_Type_toString(p_struct->type));
414
415 }
416
AB_Balance_toXml(const AB_BALANCE * p_struct,GWEN_XMLNODE * p_db)417 void AB_Balance_toXml(const AB_BALANCE *p_struct, GWEN_XMLNODE *p_db)
418 {
419 AB_Balance_WriteXml(p_struct, p_db);
420 }
421
AB_Balance_fromXml(GWEN_XMLNODE * p_db)422 AB_BALANCE *AB_Balance_fromXml(GWEN_XMLNODE *p_db)
423 {
424 AB_BALANCE *p_struct;
425 p_struct=AB_Balance_new();
426 AB_Balance_ReadXml(p_struct, p_db);
427 return p_struct;
428 }
429
AB_Balance_List_GetByType(const AB_BALANCE_LIST * p_list,int p_cmp)430 AB_BALANCE *AB_Balance_List_GetByType(const AB_BALANCE_LIST *p_list, int p_cmp)
431 {
432 AB_BALANCE *p_struct;
433
434 assert(p_list);
435 p_struct = AB_Balance_List_First(p_list);
436 while (p_struct) {
437 int p_rv;
438
439 if (p_struct->type==p_cmp)
440 p_rv=0;
441 else if (p_cmp<p_struct->type)
442 p_rv=-1;
443 else
444 p_rv=1;
445 if (p_rv == 0)
446 return p_struct;
447 p_struct = AB_Balance_List_Next(p_struct);
448 }
449 return NULL;
450 }
451
AB_Balance_List_FindFirstByType(const AB_BALANCE_LIST * bl,int ty)452 AB_BALANCE *AB_Balance_List_FindFirstByType(const AB_BALANCE_LIST *bl, int ty)
453 {
454 AB_BALANCE *bal;
455 assert(bl);
456 bal=AB_Balance_List_First(bl);
457 while (bal) {
458 if (ty==AB_Balance_TypeNone || ty==bal->type)
459 return bal;
460 bal=AB_Balance_List_Next(bal);
461 }
462 return NULL;
463 }
AB_Balance_List_FindNextByType(AB_BALANCE * bal,int ty)464 AB_BALANCE *AB_Balance_List_FindNextByType(AB_BALANCE *bal, int ty)
465 {
466 assert(bal);
467 bal=AB_Balance_List_Next(bal);
468 while (bal) {
469 if (ty==AB_Balance_TypeNone || ty==bal->type)
470 return bal;
471 bal=AB_Balance_List_Next(bal);
472 }
473 return NULL;
474 }
AB_Balance_List_GetLatestByType(const AB_BALANCE_LIST * bl,int ty)475 AB_BALANCE *AB_Balance_List_GetLatestByType(const AB_BALANCE_LIST *bl, int ty)
476 {
477 AB_BALANCE *lastBal=NULL;
478 const GWEN_DATE *lastDt=NULL;
479 AB_BALANCE *bal=NULL;
480 bal=AB_Balance_List_First(bl);
481 while (bal) {
482 if (ty==0 || (AB_Balance_GetType(bal)==ty)) {
483 const GWEN_DATE *dt;
484 if (lastBal && lastDt && (dt=AB_Balance_GetDate(bal))) {
485 if (GWEN_Date_Compare(dt, lastDt)>0) {
486 lastBal=bal;
487 lastDt=dt;
488 }
489 }
490 else {
491 lastBal=bal;
492 lastDt=AB_Balance_GetDate(bal);
493 }
494 }
495 bal=AB_Balance_List_Next(bal);
496 }
497 return lastBal;
498 }
499
500 /* code headers */
501
502