Use def_elt_end instead of destroying the context directly.
[gedcom-parse.git] / gom / gom_internal.h
1 /* General header for the Gedcom object model.
2    Copyright (C) 2002 The Genes Development Team
3    This file is part of the Gedcom parser library.
4    Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2002.
5
6    The Gedcom parser library is free software; you can redistribute it
7    and/or modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The Gedcom parser library is distributed in the hope that it will be
12    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the Gedcom parser library; if not, write to the
18    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
20
21 /* $Id$ */
22 /* $Name$ */
23
24 #ifndef __GOM_INTERNAL_H
25 #define __GOM_INTERNAL_H
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <libintl.h>
30 #include <time.h>
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 #include "gom.h"
35 #include "gedcom.h"
36       
37 #define _(string) dgettext(PACKAGE, string)
38 #define N_(string) (string)
39
40 #ifdef __GNUC__
41 #define UNUSED __attribute__((unused))
42 #else
43 #define UNUSED
44 #endif
45
46 typedef enum {
47   T_NULL,
48   
49   T_header, T_submission, T_submitter, T_family, T_individual,
50   T_multimedia, T_note, T_repository, T_source, T_user_rec,
51   
52   T_address, T_event, T_place, T_source_citation, T_text,
53   T_note_sub, T_multimedia_link, T_lds_event, T_user_ref_number,
54   T_change_date, T_personal_name, T_family_link, T_pedigree,
55   T_association, T_source_event, T_source_description,
56
57   T_LAST
58 } OBJ_TYPE;
59
60 /* Assumptions for context:
61     - In case of error, NULL is passed as context
62     - If not NULL, the ctxt_ptr of the context is not NULL also
63     - UNEXPECTED_CONTEXT is not treated as an error, but as a warning
64 */
65
66 struct Gom_ctxt_struct {
67   int ctxt_type;
68   OBJ_TYPE obj_type;
69   void* ctxt_ptr;
70 };
71
72 typedef struct Gom_ctxt_struct *Gom_ctxt;
73
74 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr);
75 void destroy_gom_ctxt(Gom_ctxt ctxt);
76 void gom_cast_error(const char* file, int line,
77                     OBJ_TYPE expected, OBJ_TYPE found);
78 void gom_no_context(const char* file, int line);
79 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found);
80 void gom_xref_already_in_use(const char *xrefstr);
81 void gom_move_error(const char* type);
82 void gom_find_error(const char* type);
83 void unref_xref_value(struct xref_value *xref);
84
85 int gom_write_xref_list(Gedcom_write_hndl hndl,
86                         Gedcom_elt elt, int tag, int parent_rec_or_elt,
87                         struct xref_list* val);
88
89 #define MAKE_GOM_CTXT(CTXT_TYPE, STRUCTTYPE, CTXT_PTR)                        \
90   make_gom_ctxt(CTXT_TYPE, T_ ## STRUCTTYPE, CTXT_PTR)
91
92 #define SAFE_CTXT_CAST(STRUCTTYPE, VAL)                                       \
93   (((VAL)->obj_type == T_ ## STRUCTTYPE) ?                                    \
94    (VAL)->ctxt_ptr :                                                          \
95    (gom_cast_error(__FILE__, __LINE__, T_ ## STRUCTTYPE, (VAL)->obj_type),    \
96     (VAL)->ctxt_ptr))
97
98 #define SAFE_FREE(PTR)                                                        \
99   if (PTR) {                                                                  \
100     free(PTR);                                                                \
101     PTR = NULL;                                                               \
102   }
103
104 #define UNEXPECTED_CONTEXT(CTXT_TYPE)                                         \
105   gom_unexpected_context(__FILE__, __LINE__, CTXT_TYPE)
106
107 #define NO_CONTEXT                                                            \
108   gom_no_context(__FILE__, __LINE__)
109
110 void gom_mem_error(const char *filename, int line);
111
112 #define MEMORY_ERROR gom_mem_error(__FILE__, __LINE__)
113
114 void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
115 void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent,
116                  Gedcom_ctxt self, Gedcom_val parsed_value);
117 void set_xref_type(struct xref_value *xr, const char* str);
118
119 int  update_date(struct date_value** dv, struct tm* tm_ptr);
120 int  update_time(char** tv, struct tm* tm_ptr);
121
122 void NULL_DESTROY(void* anything);
123
124 #include "func_template.h"
125
126 DECLARE_UNREFALLFUNC(xref_list);
127 DECLARE_CLEANFUNC(xref_list);
128   
129 #endif /* __GOM_INTERNAL_H */