Allow elements out of context in GOM.
[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 struct Gom_ctxt_struct;
61 typedef struct Gom_ctxt_struct *Gom_ctxt;
62
63 Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr);
64 Gom_ctxt dup_gom_ctxt(Gom_ctxt ctxt, int ctxt_type);
65 void* safe_ctxt_cast(Gom_ctxt ctxt, OBJ_TYPE type, const char* file, int line);
66 int ctxt_type(Gom_ctxt ctxt);
67 OBJ_TYPE ctxt_obj_type(Gom_ctxt ctxt);
68
69 void gom_cast_error(const char* file, int line,
70                     OBJ_TYPE expected, OBJ_TYPE found);
71 void gom_no_context(const char* file, int line);
72 void gom_unexpected_context(const char* file, int line, OBJ_TYPE found);
73 void gom_xref_already_in_use(const char *xrefstr);
74 void gom_move_error(const char* type);
75 void gom_find_error(const char* type);
76 void unref_xref_value(struct xref_value *xref);
77
78 int gom_write_xref_list(Gedcom_write_hndl hndl,
79                         Gedcom_elt elt, int tag, int parent_rec_or_elt,
80                         struct xref_list* val);
81
82 #define MAKE_GOM_CTXT(CTXT_TYPE, STRUCTTYPE, CTXT_PTR)                        \
83   make_gom_ctxt(CTXT_TYPE, T_ ## STRUCTTYPE, CTXT_PTR)
84
85 #define SAFE_CTXT_CAST(STRUCTTYPE, VAL)                                       \
86   safe_ctxt_cast(VAL, T_ ## STRUCTTYPE, __FILE__, __LINE__)
87
88 #define SAFE_FREE(PTR)                                                        \
89   if (PTR) {                                                                  \
90     free(PTR);                                                                \
91     PTR = NULL;                                                               \
92   }
93
94 #define UNEXPECTED_CONTEXT(CTXT_TYPE)                                         \
95   gom_unexpected_context(__FILE__, __LINE__, CTXT_TYPE)
96
97 #define NO_CONTEXT                                                            \
98   gom_no_context(__FILE__, __LINE__)
99
100 void gom_mem_error(const char *filename, int line);
101
102 #define MEMORY_ERROR gom_mem_error(__FILE__, __LINE__)
103
104 void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
105 void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent,
106                  Gedcom_ctxt self, Gedcom_val parsed_value);
107 void set_xref_type(struct xref_value *xr, const char* str);
108
109 int  update_date(struct date_value** dv, struct tm* tm_ptr);
110 int  update_time(char** tv, struct tm* tm_ptr);
111
112 void NULL_DESTROY(void* anything);
113
114 #include "func_template.h"
115
116 DECLARE_UNREFALLFUNC(xref_list);
117 DECLARE_CLEANFUNC(xref_list);
118   
119 #endif /* __GOM_INTERNAL_H */