1 /* User record 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 "submission.h"
28 #include "submitter.h"
30 #include "individual.h"
31 #include "multimedia.h"
33 #include "repository.h"
38 #include "source_citation.h"
40 #include "multimedia_link.h"
41 #include "lds_event.h"
43 #include "change_date.h"
44 #include "personal_name.h"
45 #include "family_link.h"
46 #include "association.h"
47 #include "source_event.h"
48 #include "source_description.h"
52 #include "gom_internal.h"
54 struct user_rec* gom_first_user_rec = NULL;
56 Gedcom_ctxt user_rec_start(_REC_PARAMS_)
58 struct user_rec* user = NULL;
59 struct xref_value* xr = NULL;
60 Gedcom_ctxt ctxt = NULL;
61 if (GEDCOM_IS_XREF_PTR(xref))
62 xr = GEDCOM_XREF_PTR(xref);
65 user = make_user_record(xr->string);
66 xr->object = (Gedcom_ctxt) user;
70 user = (struct user_rec*) ctxt;
74 user = make_user_record(NULL);
75 ctxt = (Gedcom_ctxt) user;
78 user->tag = strdup(tag);
79 if (GEDCOM_IS_STRING(parsed_value))
80 user->str_value = strdup(GEDCOM_STRING(parsed_value));
81 else if (GEDCOM_IS_XREF_PTR(parsed_value))
82 user->xref_value = GEDCOM_XREF_PTR(parsed_value);
84 return (Gedcom_ctxt) MAKE_GOM_CTXT(rec, user_rec, ctxt);
87 GET_REC_BY_XREF(user_rec, XREF_USER, gom_get_user_rec_by_xref)
89 Gedcom_ctxt user_elt_start(_ELT_PARAMS_)
91 Gom_ctxt ctxt = (Gom_ctxt)parent;
92 struct user_data *data = (struct user_data *)malloc(sizeof(struct user_data));
93 memset (data, 0, sizeof(struct user_data));
96 data->tag = strdup(tag);
97 if (GEDCOM_IS_STRING(parsed_value))
98 data->str_value = strdup(GEDCOM_STRING(parsed_value));
99 else if (GEDCOM_IS_XREF_PTR(parsed_value))
100 data->xref_value = GEDCOM_XREF_PTR(parsed_value);
103 switch (ctxt->obj_type) {
105 header_add_user_data(ctxt, data); break;
107 submission_add_user_data(ctxt, data); break;
109 submitter_add_user_data(ctxt, data); break;
111 family_add_user_data(ctxt, data); break;
113 individual_add_user_data(ctxt, data); break;
115 multimedia_add_user_data(ctxt, data); break;
117 note_add_user_data(ctxt, data); break;
119 repository_add_user_data(ctxt, data); break;
121 source_add_user_data(ctxt, data); break;
123 user_rec_add_user_data(ctxt, data); break;
125 address_add_user_data(ctxt, data); break;
127 event_add_user_data(ctxt, data); break;
129 place_add_user_data(ctxt, data); break;
130 case T_source_citation:
131 citation_add_user_data(ctxt, data); break;
133 note_sub_add_user_data(ctxt, data); break;
134 case T_multimedia_link:
135 multimedia_link_add_user_data(ctxt, data); break;
137 lds_event_add_user_data(ctxt, data); break;
138 case T_user_ref_number:
139 user_ref_add_user_data(ctxt, data); break;
141 change_date_add_user_data(ctxt, data); break;
142 case T_personal_name:
143 name_add_user_data(ctxt, data); break;
145 family_link_add_user_data(ctxt, data); break;
147 association_add_user_data(ctxt, data); break;
149 source_event_add_user_data(ctxt, data); break;
150 case T_source_description:
151 source_description_add_user_data(ctxt, data); break;
153 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
157 return (Gedcom_ctxt) make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr);
160 void user_rec_subscribe()
162 gedcom_subscribe_to_record(REC_USER, user_rec_start, def_rec_end);
163 gedcom_subscribe_to_element(ELT_USER, user_elt_start, def_elt_end);
166 void user_rec_add_user_data(Gom_ctxt ctxt, struct user_data* data)
168 struct user_rec *obj = SAFE_CTXT_CAST(user_rec, ctxt);
169 LINK_CHAIN_ELT(user_data, obj->extra, data)
172 void user_data_cleanup(struct user_data* data)
174 SAFE_FREE(data->tag);
175 SAFE_FREE(data->str_value);
178 void user_rec_cleanup(struct user_rec* rec)
180 SAFE_FREE(rec->xrefstr);
182 SAFE_FREE(rec->str_value);
183 DESTROY_CHAIN_ELTS(user_data, rec->extra, user_data_cleanup);
186 void user_recs_cleanup()
188 DESTROY_CHAIN_ELTS(user_rec, gom_first_user_rec, user_rec_cleanup);
191 struct user_rec* gom_get_first_user_rec()
193 return gom_first_user_rec;
196 struct user_rec* make_user_record(char* xrefstr)
198 struct user_rec* rec;
199 MAKE_CHAIN_ELT(user_rec, gom_first_user_rec, rec);
201 rec->xrefstr = strdup(xrefstr);