X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Ffunc_template.h;h=769debb2a96e84c350da8c118a6e0067885bd7dc;hb=abda83ad355fff5c6878a3dd6ad600de0d68d416;hp=a21424d1b425b1847d3f2123b556da5a0758671d;hpb=28297bd9b57fa7d8c3600d040cc08e5e73a62c27;p=gedcom-parse.git diff --git a/gom/func_template.h b/gom/func_template.h index a21424d..769debb 100644 --- a/gom/func_template.h +++ b/gom/func_template.h @@ -29,8 +29,9 @@ #define DESTROYFUNC(STRUCTTYPE) destroy_ ## STRUCTTYPE ## _record #define GETXREFFUNC(STRUCTTYPE) gom_get_ ## STRUCTTYPE ## _by_xref #define CLEANFUNC(STRUCTTYPE) STRUCTTYPE ## _cleanup -#define ADDFUNC(STRUCTTYPE) gom_add_ ## STRUCTTYPE -#define SUB_ADDFUNC(STRUCTTYPE) gom_add_ ## STRUCTTYPE +#define ADDFUNC(STRUCTTYPE) gom_new_ ## STRUCTTYPE +#define SUB_SETFUNC(STRUCTTYPE) gom_set_new_ ## STRUCTTYPE +#define UNREFALLFUNC(STRUCTTYPE) STRUCTTYPE ## _unref_all #define DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE #define SUB_DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE #define ADDFUNC2(T1,T2) T1 ## _add_ ## T2 @@ -48,6 +49,9 @@ #define DECLARE_CLEANFUNC(STRUCTTYPE) \ void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) +#define DECLARE_UNREFALLFUNC(STRUCTTYPE) \ + void UNREFALLFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) + #define DECLARE_ADDFUNC2(STRUCTTYPE,T2) \ void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* obj) @@ -93,6 +97,39 @@ (FIRSTVAL)->previous = VAL->previous; \ } +#define MOVE_CHAIN_ELT(STRUCTTYPE, DIR, FIRSTVAL, VAL) \ + { \ + struct STRUCTTYPE *first, *second; \ + if (DIR == MOVE_UP) { \ + first = VAL->previous; \ + second = VAL; \ + } \ + else { \ + first = VAL; \ + second = VAL->next; \ + } \ + if (second && (second != FIRSTVAL)) { \ + if (first != FIRSTVAL) \ + first->previous->next = second; \ + else \ + FIRSTVAL = second; \ + \ + if (second->next) \ + second->next->previous = first; \ + else \ + (FIRSTVAL)->previous = first; \ + \ + first->next = second->next; \ + second->next = first; \ + \ + second->previous = first->previous; \ + first->previous = second; \ + } \ + else { \ + gom_move_error(#STRUCTTYPE); \ + } \ + } + #define MAKE_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL) \ { \ VAL = (struct STRUCTTYPE*) malloc(sizeof(struct STRUCTTYPE)); \ @@ -145,7 +182,7 @@ } #define DEFINE_DESTROYFUNC(STRUCTTYPE,FIRSTVAL) \ - void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj); \ + DECLARE_CLEANFUNC(STRUCTTYPE); \ void DESTROYFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) { \ if (obj) { \ CLEANFUNC(STRUCTTYPE)(obj); \ @@ -184,8 +221,8 @@ return obj; \ } -#define DEFINE_SUB_ADDFUNC(STRUCTTYPE) \ - struct STRUCTTYPE *SUB_ADDFUNC(STRUCTTYPE)(struct STRUCTTYPE** addto) \ +#define DEFINE_SUB_SETFUNC(STRUCTTYPE) \ + struct STRUCTTYPE *SUB_SETFUNC(STRUCTTYPE)(struct STRUCTTYPE** addto) \ { \ struct STRUCTTYPE *obj = NULL; \ if (addto && ! *addto) { \ @@ -195,15 +232,17 @@ return obj; \ } -/* TODO: Check whether there are still xrefs linked in */ #define DEFINE_DELETEFUNC(STRUCTTYPE) \ + DECLARE_UNREFALLFUNC(STRUCTTYPE); \ int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) \ { \ int result = 1; \ if (obj) { \ result = gedcom_delete_xref(obj->xrefstr); \ - if (result == 0) \ + if (result == 0) { \ + UNREFALLFUNC(STRUCTTYPE)(obj); \ DESTROYFUNC(STRUCTTYPE)(obj); \ + } \ } \ return result; \ } @@ -213,6 +252,7 @@ { \ int result = 1; \ if (obj && *obj) { \ + UNREFALLFUNC(STRUCTTYPE)(*obj); \ CLEANFUNC(STRUCTTYPE)(*obj); \ SAFE_FREE(*obj); \ result = 0; \