Definition of MAKELINKFUNC.
[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 DEFINE_MAKELINKFUNC(family, XREF_FAM)
49      
50 DEFINE_REC_CB(family, fam_start)
51 DEFINE_XREF_CB(family, fam_husb_start, husband, individual)
52 DEFINE_XREF_CB(family, fam_wife_start, wife, individual)
53 DEFINE_STRING_CB(family, fam_nchi_start, nr_of_children)
54 DEFINE_XREF_LIST_CB(family, fam_chil_start, children, individual)
55 DEFINE_XREF_LIST_CB(family, fam_subm_start, submitters, submitter)
56
57 DEFINE_ADDFUNC2(family, event, event)
58 DEFINE_ADDFUNC2(family, lds_event, lds_spouse_sealing)
59 DEFINE_ADDFUNC2(family, source_citation, citation)
60 DEFINE_ADDFUNC2(family, multimedia_link, mm_link)
61 DEFINE_ADDFUNC2(family, note_sub, note)
62 DEFINE_ADDFUNC2(family, user_ref_number, ref)
63 DEFINE_ADDFUNC2(family, user_data, extra)
64 DEFINE_ADDFUNC2_NOLIST(family, change_date, change_date)
65 DEFINE_ADDFUNC2_STR(family, record_id)
66
67 void family_subscribe()
68 {
69   gedcom_subscribe_to_record(REC_FAM, fam_start, def_rec_end);
70   gedcom_subscribe_to_element(ELT_FAM_HUSB, fam_husb_start, def_elt_end);
71   gedcom_subscribe_to_element(ELT_FAM_WIFE, fam_wife_start, def_elt_end);
72   gedcom_subscribe_to_element(ELT_FAM_CHIL, fam_chil_start, def_elt_end);
73   gedcom_subscribe_to_element(ELT_FAM_NCHI, fam_nchi_start, def_elt_end);
74   gedcom_subscribe_to_element(ELT_FAM_SUBM, fam_subm_start, def_elt_end);
75 }
76
77 void CLEANFUNC(family)(struct family* fam)
78 {
79   if (fam) {
80     SAFE_FREE(fam->xrefstr);
81     DESTROY_CHAIN_ELTS(event, fam->event); 
82     DESTROY_CHAIN_ELTS(xref_list, fam->children);
83     SAFE_FREE(fam->nr_of_children);
84     DESTROY_CHAIN_ELTS(xref_list, fam->submitters);
85     DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing);
86     DESTROY_CHAIN_ELTS(source_citation, fam->citation);
87     DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link);
88     DESTROY_CHAIN_ELTS(note_sub, fam->note);
89     DESTROY_CHAIN_ELTS(user_ref_number, fam->ref);
90     SAFE_FREE(fam->record_id);
91     CLEANFUNC(change_date)(fam->change_date);
92     DESTROY_CHAIN_ELTS(user_data, fam->extra);
93   }
94 }
95
96 void families_cleanup()
97 {
98   DESTROY_CHAIN_ELTS(family, gom_first_family);
99 }
100
101 struct family* gom_get_first_family()
102 {
103   return gom_first_family;
104 }
105
106 int write_families(Gedcom_write_hndl hndl)
107 {
108   int result = 0;
109   struct family* obj;
110
111   for (obj = gom_first_family; obj; obj = obj->next) {
112     result |= gedcom_write_record_str(hndl, REC_FAM, obj->xrefstr, NULL);
113     if (obj->event)
114       result |= write_events(hndl, REC_FAM, EVT_TYPE_FAMILY, obj->event);
115     if (obj->husband)
116       result |= gedcom_write_element_xref(hndl, ELT_FAM_HUSB, 0,
117                                           REC_FAM, obj->husband);
118     if (obj->wife)
119       result |= gedcom_write_element_xref(hndl, ELT_FAM_WIFE, 0,
120                                           REC_FAM, obj->wife);
121     result |= gom_write_xref_list(hndl, ELT_FAM_CHIL, 0,
122                                   REC_FAM, obj->children);
123     if (obj->nr_of_children)
124       result |= gedcom_write_element_str(hndl, ELT_FAM_NCHI, 0,
125                                          REC_FAM, obj->nr_of_children);
126     result |= gom_write_xref_list(hndl, ELT_FAM_SUBM, 0,
127                                   REC_FAM, obj->submitters);
128     if (obj->lds_spouse_sealing)
129       result |= write_lds_events(hndl, REC_FAM, obj->lds_spouse_sealing);
130     if (obj->citation)
131       result |= write_citations(hndl, REC_FAM, obj->citation);
132     if (obj->mm_link)
133       result |= write_multimedia_links(hndl, REC_FAM, obj->mm_link);
134     if (obj->note)
135       result |= write_note_subs(hndl, REC_FAM, obj->note);
136     if (obj->ref)
137       result |= write_user_refs(hndl, REC_FAM, obj->ref);
138     if (obj->record_id)
139       result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0,
140                                          REC_FAM, obj->record_id);
141     if (obj->change_date)
142       result |= write_change_date(hndl, REC_FAM, obj->change_date);
143     if (obj->extra)
144       result |= write_user_data(hndl, obj->extra);
145   }
146   
147   return result;
148 }
149