X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=gom%2Ffunc_template.h;h=d5b22c5e21032d177283f20259362807b59b8020;hb=1b7536d78e236978e83fbf8acc9f90e2141e13b0;hp=769debb2a96e84c350da8c118a6e0067885bd7dc;hpb=3155d964e15a3c49121c01d2808e5a846779b812;p=gedcom-parse.git diff --git a/gom/func_template.h b/gom/func_template.h index 769debb..d5b22c5 100644 --- a/gom/func_template.h +++ b/gom/func_template.h @@ -31,9 +31,13 @@ #define CLEANFUNC(STRUCTTYPE) STRUCTTYPE ## _cleanup #define ADDFUNC(STRUCTTYPE) gom_new_ ## STRUCTTYPE #define SUB_SETFUNC(STRUCTTYPE) gom_set_new_ ## STRUCTTYPE +#define SUB_ADDFUNC(STRUCTTYPE) gom_add_new_ ## STRUCTTYPE #define UNREFALLFUNC(STRUCTTYPE) STRUCTTYPE ## _unref_all #define DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE #define SUB_DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE +#define SUB_FINDFUNC(STRUCTTYPE) find_ ## STRUCTTYPE +#define SUB_REMOVEFUNC(STRUCTTYPE) gom_remove_ ## STRUCTTYPE +#define SUB_MOVEFUNC(STRUCTTYPE) gom_move_ ## STRUCTTYPE #define ADDFUNC2(T1,T2) T1 ## _add_ ## T2 #define ADDFUNC2_TOVAR(T1,T2,F) T1 ## _add_ ## T2 ## _to_ ## F #define ADDFUNC2_NOLIST(T1,T2) ADDFUNC2(T1,T2) @@ -232,6 +236,16 @@ return obj; \ } +#define DEFINE_SUB_ADDFUNC(STRUCTTYPE) \ + struct STRUCTTYPE *SUB_ADDFUNC(STRUCTTYPE)(struct STRUCTTYPE** addto) \ + { \ + struct STRUCTTYPE *obj = NULL; \ + if (addto) { \ + MAKE_CHAIN_ELT(STRUCTTYPE, *addto, obj); \ + } \ + return obj; \ + } + #define DEFINE_DELETEFUNC(STRUCTTYPE) \ DECLARE_UNREFALLFUNC(STRUCTTYPE); \ int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) \ @@ -260,6 +274,55 @@ return result; \ } +#define DEFINE_SUB_FINDFUNC(STRUCTTYPE) \ + struct STRUCTTYPE* SUB_FINDFUNC(STRUCTTYPE)(struct STRUCTTYPE** data, \ + struct STRUCTTYPE* obj) \ + { \ + struct STRUCTTYPE* result = NULL; \ + struct STRUCTTYPE* runner; \ + for (runner = *data ; runner ; runner = runner->next) { \ + if (runner == obj) { \ + result = runner; \ + break; \ + } \ + } \ + if (! result) \ + gom_find_error(#STRUCTTYPE); \ + return result; \ + } + +#define DEFINE_SUB_REMOVEFUNC(STRUCTTYPE) \ + int SUB_REMOVEFUNC(STRUCTTYPE) (struct STRUCTTYPE** data, \ + struct STRUCTTYPE* obj) \ + { \ + int result = 1; \ + if (data && obj) { \ + struct STRUCTTYPE* toremove = SUB_FINDFUNC(STRUCTTYPE)(data, obj); \ + if (toremove) { \ + UNLINK_CHAIN_ELT(STRUCTTYPE, *data, toremove); \ + CLEANFUNC(STRUCTTYPE)(toremove); \ + SAFE_FREE(toremove); \ + result = 0; \ + } \ + } \ + return result; \ + } + +#define DEFINE_SUB_MOVEFUNC(STRUCTTYPE) \ + int SUB_MOVEFUNC(STRUCTTYPE)(Gom_direction dir, struct STRUCTTYPE** data, \ + struct STRUCTTYPE* obj) \ + { \ + int result = 1; \ + if (data && obj) { \ + struct STRUCTTYPE* tomove = SUB_FINDFUNC(STRUCTTYPE)(data, obj); \ + if (tomove) { \ + MOVE_CHAIN_ELT(STRUCTTYPE, dir, *data, tomove); \ + result = 0; \ + } \ + } \ + return result; \ + } + #define DEFINE_ADDFUNC2(STRUCTTYPE,T2,FIELD) \ void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* addobj) \ { \