1 /* Change date 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 "change_date.h"
28 #include "individual.h"
30 #include "multimedia.h"
32 #include "repository.h"
34 #include "submitter.h"
36 #include "gom_internal.h"
40 Gedcom_ctxt sub_chan_start(_ELT_PARAMS_)
42 Gom_ctxt ctxt = (Gom_ctxt)parent;
43 Gom_ctxt result = NULL;
48 struct change_date *chan
49 = (struct change_date *)malloc(sizeof(struct change_date));
53 memset (chan, 0, sizeof(struct change_date));
55 switch (ctxt->ctxt_type) {
57 family_set_change_date(ctxt, chan); break;
59 individual_set_change_date(ctxt, chan); break;
61 multimedia_set_change_date(ctxt, chan); break;
63 note_set_change_date(ctxt, chan); break;
65 repository_set_change_date(ctxt, chan); break;
67 source_set_change_date(ctxt, chan); break;
69 submitter_set_change_date(ctxt, chan); break;
71 UNEXPECTED_CONTEXT(ctxt->ctxt_type);
73 result = MAKE_GOM_CTXT(elt, change_date, chan);
77 return (Gedcom_ctxt)result;
80 DATE_CB(change_date, sub_chan_date_start, date)
81 STRING_CB(change_date, sub_chan_time_start, time)
83 void change_date_subscribe()
85 gedcom_subscribe_to_element(ELT_SUB_CHAN, sub_chan_start, def_elt_end);
86 gedcom_subscribe_to_element(ELT_SUB_CHAN_DATE, sub_chan_date_start,
88 gedcom_subscribe_to_element(ELT_SUB_CHAN_TIME, sub_chan_time_start,
92 void change_date_add_note(Gom_ctxt ctxt, struct note_sub* note)
94 struct change_date *chan = SAFE_CTXT_CAST(change_date, ctxt);
96 LINK_CHAIN_ELT(note_sub, chan->note, note);
99 void change_date_add_user_data(Gom_ctxt ctxt, struct user_data* data)
101 struct change_date *obj = SAFE_CTXT_CAST(change_date, ctxt);
103 LINK_CHAIN_ELT(user_data, obj->extra, data);
106 void change_date_cleanup(struct change_date *chan)
109 SAFE_FREE(chan->date);
110 SAFE_FREE(chan->time);
111 DESTROY_CHAIN_ELTS(note_sub, chan->note, note_sub_cleanup);
112 DESTROY_CHAIN_ELTS(user_data, chan->extra, user_data_cleanup);
117 int write_change_date(Gedcom_write_hndl hndl, int parent,
118 struct change_date *chan)
124 result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN, 0, parent, NULL);
126 result |= gedcom_write_element_date(hndl, ELT_SUB_CHAN_DATE, 0,
127 ELT_SUB_CHAN, chan->date);
129 result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN_TIME, 0,
130 ELT_SUB_CHAN_DATE, chan->time);
132 result |= write_note_subs(hndl, ELT_SUB_CHAN, chan->note);
134 result |= write_user_data(hndl, chan->extra);