Definition of SUB_MAKEFUNC.
[gedcom-parse.git] / gom / family.c
1 /* Family object in 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 #include <stdlib.h>
25 #include <string.h>
26 #include "family.h"
27 #include "individual.h"
28 #include "submitter.h"
29 #include "event.h"
30 #include "lds_event.h"
31 #include "source_citation.h"
32 #include "multimedia_link.h"
33 #include "note_sub.h"
34 #include "user_ref.h"
35 #include "change_date.h"
36 #include "user_rec.h"
37 #include "gom.h"
38 #include "gedcom.h"
39 #include "gom_internal.h"
40
41 struct family* gom_first_family = NULL;
42
43 DEFINE_MAKEFUNC(family, gom_first_family)
44 DEFINE_DESTROYFUNC(family, gom_first_family)
45 DEFINE_ADDFUNC(family, XREF_FAM)
46 DEFINE_DELETEFUNC(family)
47 DEFINE_GETXREFFUNC(family, XREF_FAM)
48      
49 DEFINE_REC_CB(family, fam_start)
50 DEFINE_XREF_CB(family, fam_husb_start, husband, individual)
51 DEFINE_XREF_CB(family, fam_wife_start, wife, individual)
52 DEFINE_STRING_CB(family, fam_nchi_start, nr_of_children)
53 DEFINE_XREF_LIST_CB(family, fam_chil_start, children, individual)
54 DEFINE_XREF_LIST_CB(family, fam_subm_start, submitters, submitter)
55
56 DEFINE_ADDFUNC2(family, event, event)
57 DEFINE_ADDFUNC2(family, lds_event, lds_spouse_sealing)
58 DEFINE_ADDFUNC2(family, source_citation, citation)
59 DEFINE_ADDFUNC2(family, multimedia_link, mm_link)
60 DEFINE_ADDFUNC2(family, note_sub, note)
61 DEFINE_ADDFUNC2(family, user_ref_number, ref)
62 DEFINE_ADDFUNC2(family, user_data, extra)
63 DEFINE_ADDFUNC2_NOLIST(family, change_date, change_date)
64 DEFINE_ADDFUNC2_STR(family, record_id)
65
66 void family_subscribe()
67 {
68   gedcom_subscribe_to_record(REC_FAM, fam_start, def_rec_end);
69   gedcom_subscribe_to_element(ELT_FAM_HUSB, fam_husb_start, def_elt_end);
70   gedcom_subscribe_to_element(ELT_FAM_WIFE, fam_wife_start, def_elt_end);
71   gedcom_subscribe_to_element(ELT_FAM_CHIL, fam_chil_start, def_elt_end);
72   gedcom_subscribe_to_element(ELT_FAM_NCHI, fam_nchi_start, def_elt_end);
73   gedcom_subscribe_to_element(ELT_FAM_SUBM, fam_subm_start, def_elt_end);
74 }
75
76 void CLEANFUNC(family)(struct family* fam)
77 {
78   if (fam) {
79     SAFE_FREE(fam->xrefstr);
80     DESTROY_CHAIN_ELTS(event, fam->event); 
81     DESTROY_CHAIN_ELTS(xref_list, fam->children);
82     SAFE_FREE(fam->nr_of_children);
83     DESTROY_CHAIN_ELTS(xref_list, fam->submitters);
84     DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing);
85     DESTROY_CHAIN_ELTS(source_citation, fam->citation);
86     DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link);
87     DESTROY_CHAIN_ELTS(note_sub, fam->note);
88     DESTROY_CHAIN_ELTS(user_ref_number, fam->ref);
89     SAFE_FREE(fam->record_id);
90     CLEANFUNC(change_date)(fam->change_date);
91     DESTROY_CHAIN_ELTS(user_data, fam->extra);
92   }
93 }
94
95 void families_cleanup()
96 {
97   DESTROY_CHAIN_ELTS(family, gom_first_family);
98 }
99
100 struct family* gom_get_first_family()
101 {
102   return gom_first_family;
103 }
104
105 int write_families(Gedcom_write_hndl hndl)
106 {
107   int result = 0;
108   struct family* obj;
109
110   for (obj = gom_first_family; obj; obj = obj->next) {
111     result |= gedcom_write_record_str(hndl, REC_FAM, obj->xrefstr, NULL);
112     if (obj->event)
113       result |= write_events(hndl, REC_FAM, EVT_TYPE_FAMILY, obj->event);
114     if (obj->husband)
115       result |= gedcom_write_element_xref(hndl, ELT_FAM_HUSB, 0,
116                                           REC_FAM, obj->husband);
117     if (obj->wife)
118       result |= gedcom_write_element_xref(hndl, ELT_FAM_WIFE, 0,
119                                           REC_FAM, obj->wife);
120     result |= gom_write_xref_list(hndl, ELT_FAM_CHIL, 0,
121                                   REC_FAM, obj->children);
122     if (obj->nr_of_children)
123       result |= gedcom_write_element_str(hndl, ELT_FAM_NCHI, 0,
124                                          REC_FAM, obj->nr_of_children);
125     result |= gom_write_xref_list(hndl, ELT_FAM_SUBM, 0,
126                                   REC_FAM, obj->submitters);
127     if (obj->lds_spouse_sealing)
128       result |= write_lds_events(hndl, REC_FAM, obj->lds_spouse_sealing);
129     if (obj->citation)
130       result |= write_citations(hndl, REC_FAM, obj->citation);
131     if (obj->mm_link)
132       result |= write_multimedia_links(hndl, REC_FAM, obj->mm_link);
133     if (obj->note)
134       result |= write_note_subs(hndl, REC_FAM, obj->note);
135     if (obj->ref)
136       result |= write_user_refs(hndl, REC_FAM, obj->ref);
137     if (obj->record_id)
138       result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0,
139                                          REC_FAM, obj->record_id);
140     if (obj->change_date)
141       result |= write_change_date(hndl, REC_FAM, obj->change_date);
142     if (obj->extra)
143       result |= write_user_data(hndl, obj->extra);
144   }
145   
146   return result;
147 }
148