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 REC_CB(family, fam_start, make_family_record)
44 GET_REC_BY_XREF(family, XREF_FAM, gom_get_family_by_xref)
45 XREF_CB(family, fam_husb_start, husband, make_individual_record)
46 XREF_CB(family, fam_wife_start, wife, make_individual_record)
47 STRING_CB(family, fam_nchi_start, nr_of_children)
48 XREF_LIST_CB(family, fam_chil_start, children, make_individual_record)
49 XREF_LIST_CB(family, fam_subm_start, submitters, make_submitter_record)
51 void family_subscribe()
53 gedcom_subscribe_to_record(REC_FAM, fam_start, def_rec_end);
54 gedcom_subscribe_to_element(ELT_FAM_HUSB, fam_husb_start, def_elt_end);
55 gedcom_subscribe_to_element(ELT_FAM_WIFE, fam_wife_start, def_elt_end);
56 gedcom_subscribe_to_element(ELT_FAM_CHIL, fam_chil_start, def_elt_end);
57 gedcom_subscribe_to_element(ELT_FAM_NCHI, fam_nchi_start, def_elt_end);
58 gedcom_subscribe_to_element(ELT_FAM_SUBM, fam_subm_start, def_elt_end);
61 void family_add_event(Gom_ctxt ctxt, struct event* evt)
63 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
65 LINK_CHAIN_ELT(event, fam->event, evt);
68 void family_add_lss(Gom_ctxt ctxt, struct lds_event* lss)
70 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
72 LINK_CHAIN_ELT(lds_event, fam->lds_spouse_sealing, lss);
75 void family_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
77 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
79 LINK_CHAIN_ELT(source_citation, fam->citation, cit);
82 void family_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
84 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
86 LINK_CHAIN_ELT(multimedia_link, fam->mm_link, link);
89 void family_add_note(Gom_ctxt ctxt, struct note_sub* note)
91 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
93 LINK_CHAIN_ELT(note_sub, fam->note, note);
96 void family_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
98 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
100 LINK_CHAIN_ELT(user_ref_number, fam->ref, ref);
103 void family_set_record_id(Gom_ctxt ctxt, char *rin)
105 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
107 fam->record_id = strdup(rin);
108 if (! fam->record_id) MEMORY_ERROR;
112 void family_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
114 struct family *fam = SAFE_CTXT_CAST(family, ctxt);
116 fam->change_date = chan;
119 void family_add_user_data(Gom_ctxt ctxt, struct user_data* data)
121 struct family *obj = SAFE_CTXT_CAST(family, ctxt);
123 LINK_CHAIN_ELT(user_data, obj->extra, data);
126 void family_cleanup(struct family* fam)
129 SAFE_FREE(fam->xrefstr);
130 DESTROY_CHAIN_ELTS(event, fam->event, event_cleanup);
131 DESTROY_CHAIN_ELTS(xref_list, fam->children, NULL_DESTROY);
132 SAFE_FREE(fam->nr_of_children);
133 DESTROY_CHAIN_ELTS(xref_list, fam->submitters, NULL_DESTROY);
134 DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing, lds_event_cleanup);
135 DESTROY_CHAIN_ELTS(source_citation, fam->citation, citation_cleanup);
136 DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link, multimedia_link_cleanup);
137 DESTROY_CHAIN_ELTS(note_sub, fam->note, note_sub_cleanup);
138 DESTROY_CHAIN_ELTS(user_ref_number, fam->ref, user_ref_cleanup);
139 SAFE_FREE(fam->record_id);
140 change_date_cleanup(fam->change_date);
141 DESTROY_CHAIN_ELTS(user_data, fam->extra, user_data_cleanup);
145 void families_cleanup()
147 DESTROY_CHAIN_ELTS(family, gom_first_family, family_cleanup);
150 struct family* gom_get_first_family()
152 return gom_first_family;
155 struct family* make_family_record(char* xrefstr)
157 struct family* fam = NULL;
158 MAKE_CHAIN_ELT(family, gom_first_family, fam);
160 fam->xrefstr = strdup(xrefstr);
161 if (! fam->xrefstr) MEMORY_ERROR;