Forgotten internal header file.
[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 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)
50
51 void family_subscribe()
52 {
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);
59 }
60
61 void family_add_event(Gom_ctxt ctxt, struct event* evt)
62 {
63   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
64   LINK_CHAIN_ELT(event, fam->event, evt)
65 }
66
67 void family_add_lss(Gom_ctxt ctxt, struct lds_event* lss)
68 {
69   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
70   LINK_CHAIN_ELT(lds_event, fam->lds_spouse_sealing, lss)
71 }
72
73 void family_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
74 {
75   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
76   LINK_CHAIN_ELT(source_citation, fam->citation, cit)
77 }
78
79 void family_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
80 {
81   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
82   LINK_CHAIN_ELT(multimedia_link, fam->mm_link, link)
83 }
84
85 void family_add_note(Gom_ctxt ctxt, struct note_sub* note)
86 {
87   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
88   LINK_CHAIN_ELT(note_sub, fam->note, note)
89 }
90
91 void family_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
92 {
93   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
94   LINK_CHAIN_ELT(user_ref_number, fam->ref, ref)
95 }
96
97 void family_set_record_id(Gom_ctxt ctxt, char *rin)
98 {
99   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
100   fam->record_id = strdup(rin);
101 }
102
103 void family_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
104 {
105   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
106   fam->change_date = chan;
107 }
108
109 void family_add_user_data(Gom_ctxt ctxt, struct user_data* data)
110 {
111   struct family *obj = SAFE_CTXT_CAST(family, ctxt);
112   LINK_CHAIN_ELT(user_data, obj->extra, data)
113 }
114
115 void family_cleanup(struct family* fam)
116 {
117   SAFE_FREE(fam->xrefstr);
118   DESTROY_CHAIN_ELTS(event, fam->event, event_cleanup)  
119   DESTROY_CHAIN_ELTS(xref_list, fam->children, NULL_DESTROY)
120   SAFE_FREE(fam->nr_of_children);
121   DESTROY_CHAIN_ELTS(xref_list, fam->submitters, NULL_DESTROY)
122   DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing, lds_event_cleanup)
123   DESTROY_CHAIN_ELTS(source_citation, fam->citation, citation_cleanup)
124   DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link, multimedia_link_cleanup)
125   DESTROY_CHAIN_ELTS(note_sub, fam->note, note_sub_cleanup)
126   DESTROY_CHAIN_ELTS(user_ref_number, fam->ref, user_ref_cleanup)
127   SAFE_FREE(fam->record_id);
128   change_date_cleanup(fam->change_date);
129   DESTROY_CHAIN_ELTS(user_data, fam->extra, user_data_cleanup)
130 }
131
132 void families_cleanup()
133 {
134   DESTROY_CHAIN_ELTS(family, gom_first_family, family_cleanup);
135 }
136
137 struct family* gom_get_first_family()
138 {
139   return gom_first_family;
140 }
141
142 struct family* make_family_record(char* xrefstr)
143 {
144   struct family* fam;
145   MAKE_CHAIN_ELT(family, gom_first_family, fam);
146   fam->xrefstr = strdup(xrefstr);
147   return fam;
148 }