1 /* Family link 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 "family_link.h"
27 #include "individual.h"
32 #include "gom_internal.h"
34 Gedcom_ctxt sub_fam_link_start(_ELT_PARAMS_)
36 Gom_ctxt ctxt = (Gom_ctxt)parent;
37 Gom_ctxt result = NULL;
42 struct family_link *link = SUB_MAKEFUNC(family_link)();
44 link->family = GEDCOM_XREF_PTR(parsed_value);
46 switch (ctxt->ctxt_type) {
48 ADDFUNC2(individual,family_link)(ctxt, elt, link); break;
50 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
52 result = MAKE_GOM_CTXT(elt, family_link, link);
56 return (Gedcom_ctxt)result;
59 Gedcom_ctxt sub_fam_link_pedi_start(_ELT_PARAMS_)
61 Gom_ctxt ctxt = (Gom_ctxt)parent;
62 Gom_ctxt result = NULL;
67 struct family_link *link = SAFE_CTXT_CAST(family_link, ctxt);
70 struct pedigree *ped = NULL;
71 MAKE_CHAIN_ELT(pedigree, link->pedigree, ped);
73 ped->pedigree = strdup(GEDCOM_STRING(parsed_value));
74 if (! ped->pedigree) {
80 result = MAKE_GOM_CTXT(elt, pedigree, ped);
83 return (Gedcom_ctxt)result;
86 DEFINE_SUB_MAKEFUNC(family_link)
87 DEFINE_SUB_ADDFUNC(family_link)
88 DEFINE_SUB_FINDFUNC(family_link)
89 DEFINE_SUB_REMOVEFUNC(family_link)
90 DEFINE_SUB_MOVEFUNC(family_link)
92 DEFINE_ADDFUNC2(family_link, note_sub, note)
93 DEFINE_ADDFUNC2(family_link, user_data, extra)
95 void family_link_subscribe()
97 gedcom_subscribe_to_element(ELT_SUB_FAMC, sub_fam_link_start,
99 gedcom_subscribe_to_element(ELT_SUB_FAMS, sub_fam_link_start,
101 gedcom_subscribe_to_element(ELT_SUB_FAMC_PEDI, sub_fam_link_pedi_start,
105 void UNREFALLFUNC(pedigree)(struct pedigree* obj)
108 struct pedigree* runner;
109 for (runner = obj; runner; runner = runner->next) {
110 UNREFALLFUNC(user_data)(runner->extra);
115 void CLEANFUNC(pedigree)(struct pedigree* ped)
118 SAFE_FREE(ped->pedigree);
122 DEFINE_SUB_MAKEFUNC(pedigree)
123 DEFINE_SUB_ADDFUNC(pedigree)
124 DEFINE_SUB_FINDFUNC(pedigree)
125 DEFINE_SUB_REMOVEFUNC(pedigree)
126 DEFINE_SUB_MOVEFUNC(pedigree)
128 void UNREFALLFUNC(family_link)(struct family_link* obj)
131 struct family_link* runner;
132 for (runner = obj; runner; runner = runner->next) {
133 unref_xref_value(runner->family);
134 UNREFALLFUNC(pedigree)(runner->pedigree);
135 UNREFALLFUNC(note_sub)(runner->note);
136 UNREFALLFUNC(user_data)(runner->extra);
141 void CLEANFUNC(family_link)(struct family_link *link)
144 DESTROY_CHAIN_ELTS(pedigree, link->pedigree);
145 DESTROY_CHAIN_ELTS(note_sub, link->note);
146 DESTROY_CHAIN_ELTS(user_data, link->extra);
150 int write_pedigrees(Gedcom_write_hndl hndl, int parent, struct pedigree* ped)
153 struct pedigree* obj;
157 for (obj = ped; obj; obj = obj->next) {
158 result |= gedcom_write_element_str(hndl, ELT_SUB_FAMC_PEDI, 0, parent,
161 result |= write_user_data(hndl, obj->extra);
167 int write_family_links(Gedcom_write_hndl hndl, int parent, LinkType type,
168 struct family_link *link)
171 struct family_link* obj;
172 int elt = (type == LINK_TYPE_CHILD ? ELT_SUB_FAMC : ELT_SUB_FAMS);
176 for (obj = link; obj; obj = obj->next) {
177 result |= gedcom_write_element_xref(hndl, elt, 0, parent,
180 result |= write_pedigrees(hndl, elt, obj->pedigree);
182 result |= write_note_subs(hndl, elt, obj->note);
184 result |= write_user_data(hndl, obj->extra);