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.
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.
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.
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
27 #include "individual.h"
28 #include "submitter.h"
30 #include "lds_event.h"
31 #include "source_citation.h"
32 #include "multimedia_link.h"
35 #include "change_date.h"
39 #include "gom_internal.h"
41 struct family* gom_first_family = NULL;
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)
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)
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)
67 void family_subscribe()
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);
77 void CLEANFUNC(family)(struct family* 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);
96 void families_cleanup()
98 DESTROY_CHAIN_ELTS(family, gom_first_family);
101 struct family* gom_get_first_family()
103 return gom_first_family;
106 int write_families(Gedcom_write_hndl hndl)
111 for (obj = gom_first_family; obj; obj = obj->next) {
112 result |= gedcom_write_record_str(hndl, REC_FAM, obj->xrefstr, NULL);
114 result |= write_events(hndl, REC_FAM, EVT_TYPE_FAMILY, obj->event);
116 result |= gedcom_write_element_xref(hndl, ELT_FAM_HUSB, 0,
117 REC_FAM, obj->husband);
119 result |= gedcom_write_element_xref(hndl, ELT_FAM_WIFE, 0,
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);
131 result |= write_citations(hndl, REC_FAM, obj->citation);
133 result |= write_multimedia_links(hndl, REC_FAM, obj->mm_link);
135 result |= write_note_subs(hndl, REC_FAM, obj->note);
137 result |= write_user_refs(hndl, REC_FAM, obj->ref);
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);
144 result |= write_user_data(hndl, obj->extra);