1 /* Association sub-structure 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
26 #include "association.h"
27 #include "individual.h"
29 #include "source_citation.h"
33 #include "gom_internal.h"
35 Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_)
37 Gom_ctxt ctxt = (Gom_ctxt)parent;
38 Gom_ctxt result = NULL;
43 struct association *assoc;
44 assoc = (struct association *)malloc(sizeof(struct association));
48 memset (assoc, 0, sizeof(struct association));
49 assoc->to = GEDCOM_XREF_PTR(parsed_value);
51 switch (ctxt->ctxt_type) {
53 individual_add_association(ctxt, assoc);
55 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
57 result = MAKE_GOM_CTXT(elt, association, assoc);
61 return (Gedcom_ctxt)result;
64 STRING_CB(association, sub_assoc_rela_start, relation)
66 Gedcom_ctxt sub_assoc_type_start(_ELT_PARAMS_)
68 Gom_ctxt ctxt = (Gom_ctxt)parent;
69 Gom_ctxt result = NULL;
74 struct association *obj = SAFE_CTXT_CAST(association, ctxt);
75 char *str = GEDCOM_STRING(parsed_value);
77 obj->type = strdup(str);
81 set_xref_type(obj->to, str);
82 result = MAKE_GOM_CTXT(elt, association, obj);
86 return (Gedcom_ctxt)result;
89 void association_subscribe()
91 gedcom_subscribe_to_element(ELT_SUB_ASSO, sub_assoc_start, def_elt_end);
92 gedcom_subscribe_to_element(ELT_SUB_ASSO_TYPE, sub_assoc_type_start,
94 gedcom_subscribe_to_element(ELT_SUB_ASSO_RELA, sub_assoc_rela_start,
98 void association_add_note(Gom_ctxt ctxt, struct note_sub* note)
100 struct association *assoc = SAFE_CTXT_CAST(association, ctxt);
102 LINK_CHAIN_ELT(note_sub, assoc->note, note);
105 void association_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
107 struct association *assoc = SAFE_CTXT_CAST(association, ctxt);
109 LINK_CHAIN_ELT(source_citation, assoc->citation, cit);
112 void association_add_user_data(Gom_ctxt ctxt, struct user_data* data)
114 struct association *obj = SAFE_CTXT_CAST(association, ctxt);
116 LINK_CHAIN_ELT(user_data, obj->extra, data);
119 void association_cleanup(struct association* assoc)
122 SAFE_FREE(assoc->type);
123 SAFE_FREE(assoc->relation);
124 DESTROY_CHAIN_ELTS(note_sub, assoc->note, note_sub_cleanup);
125 DESTROY_CHAIN_ELTS(source_citation, assoc->citation, citation_cleanup);
126 DESTROY_CHAIN_ELTS(user_data, assoc->extra, user_data_cleanup);
130 int write_associations(Gedcom_write_hndl hndl, int parent,
131 struct association *assoc)
134 struct association* obj;
136 if (!assoc) return 1;
138 for (obj = assoc; obj; obj = obj->next) {
139 result |= gedcom_write_element_xref(hndl, ELT_SUB_ASSO, 0, parent,
142 result |= gedcom_write_element_str(hndl, ELT_SUB_ASSO_TYPE, 0, parent,
145 result |= gedcom_write_element_str(hndl, ELT_SUB_ASSO_RELA, 0, parent,
148 result |= write_citations(hndl, ELT_SUB_ASSO, obj->citation);
150 result |= write_note_subs(hndl, ELT_SUB_ASSO, obj->note);
152 result |= write_user_data(hndl, obj->extra);