Some new function templates.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 5 Jan 2003 17:41:44 +0000 (17:41 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 5 Jan 2003 17:41:44 +0000 (17:41 +0000)
gom/func_template.h

index df5c9442086d35f53b86b27d933f356737705c3f..24e1ea69a3711b71816d30e6b16ab2e2f950eda1 100644 (file)
 #define __FUNC_TEMPLATE_H
 
 #define MAKEFUNC(STRUCTTYPE)     make_ ## STRUCTTYPE ## _record
+#define SUB_MAKEFUNC(STRUCTTYPE) make_ ## STRUCTTYPE
 #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 DELETEFUNC(STRUCTTYPE)   gom_delete_ ## STRUCTTYPE
+#define SUB_DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE
+#define MAKELINKFUNC(STRUCTTYPE) gom_make_ ## STRUCTTYPE ## _link
 #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)
@@ -39,6 +43,9 @@
 #define DECLARE_MAKEFUNC(STRUCTTYPE)                                          \
   struct STRUCTTYPE* MAKEFUNC(STRUCTTYPE)(const char* xref)
 
+#define DECLARE_SUB_MAKEFUNC(STRUCTTYPE)                                      \
+  struct STRUCTTYPE* SUB_MAKEFUNC(STRUCTTYPE)()
+
 #define DECLARE_CLEANFUNC(STRUCTTYPE)                                         \
   void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj)
 
     return obj;                                                               \
   }
 
+#define DEFINE_SUB_MAKEFUNC(STRUCTTYPE)                                       \
+  struct STRUCTTYPE* SUB_MAKEFUNC(STRUCTTYPE)() {                             \
+    struct STRUCTTYPE* obj = NULL;                                            \
+    obj = (struct STRUCTTYPE*) malloc(sizeof(struct STRUCTTYPE));             \
+    if (!obj)                                                                 \
+      MEMORY_ERROR;                                                           \
+    else                                                                      \
+      memset(obj, 0, sizeof(struct STRUCTTYPE));                              \
+    return obj;                                                               \
+  }
+
 #define DEFINE_DESTROYFUNC(STRUCTTYPE,FIRSTVAL)                               \
   void CLEANFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj);                         \
   void DESTROYFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj) {                      \
     return obj;                                                               \
   }
 
+#define DEFINE_SUB_ADDFUNC(STRUCTTYPE)                                        \
+  struct STRUCTTYPE *SUB_ADDFUNC(STRUCTTYPE)(struct STRUCTTYPE** addto)       \
+  {                                                                           \
+    struct STRUCTTYPE *obj = NULL;                                            \
+    if (addto && ! *addto) {                                                  \
+      obj = SUB_MAKEFUNC(STRUCTTYPE)();                                       \
+      if (obj) *addto = obj;                                                  \
+    }                                                                         \
+    return obj;                                                               \
+  }
+
 #define DEFINE_DELETEFUNC(STRUCTTYPE)                                         \
   int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj)                          \
   {                                                                           \
     return result;                                                            \
   }
 
+#define DEFINE_SUB_DELETEFUNC(STRUCTTYPE)                                     \
+  int SUB_DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE** obj)                     \
+  {                                                                           \
+    int result = 1;                                                           \
+    if (obj && *obj) {                                                        \
+      CLEANFUNC(STRUCTTYPE)(*obj);                                            \
+      free(*obj);                                                             \
+      *obj = NULL;                                                            \
+      result = 0;                                                             \
+    }                                                                         \
+    return result;                                                            \
+  }
+
+#define DEFINE_MAKELINKFUNC(STRUCTTYPE,XREF_TYPE)                             \
+  struct xref_value* MAKELINKFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj)         \
+  {                                                                           \
+    struct xref_value* xr = NULL;                                             \
+    if (obj && obj->xrefstr) {                                                \
+      xr = gedcom_get_by_xref(obj->xrefstr);                                  \
+    }                                                                         \
+    return xr;                                                                \
+  }
+
 #define DEFINE_ADDFUNC2(STRUCTTYPE,T2,FIELD)                                  \
   void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* addobj)              \
   {                                                                           \