Forgotten internal header file.
[gedcom-parse.git] / gom / change_date.c
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.
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 "change_date.h"
27 #include "family.h"
28 #include "individual.h"
29 #include "note_sub.h"
30 #include "multimedia.h"
31 #include "note.h"
32 #include "repository.h"
33 #include "source.h"
34 #include "submitter.h"
35 #include "user_rec.h"
36 #include "gom_internal.h"
37 #include "gom.h"
38 #include "gedcom.h"
39
40 Gedcom_ctxt sub_chan_start(_ELT_PARAMS_)
41 {
42   Gom_ctxt ctxt = (Gom_ctxt)parent;
43   struct change_date *chan
44     = (struct change_date *)malloc(sizeof(struct change_date));
45   memset (chan, 0, sizeof(struct change_date));
46
47   if (ctxt) {
48     switch (ctxt->ctxt_type) {
49       case REC_FAM:
50         family_set_change_date(ctxt, chan); break;
51       case REC_INDI:
52         individual_set_change_date(ctxt, chan); break;
53       case REC_OBJE:
54         multimedia_set_change_date(ctxt, chan); break;
55       case REC_NOTE:
56         note_set_change_date(ctxt, chan); break;
57       case REC_REPO:
58         repository_set_change_date(ctxt, chan); break;
59       case REC_SOUR:
60         source_set_change_date(ctxt, chan); break;
61       case REC_SUBM:
62         submitter_set_change_date(ctxt, chan); break;
63       default:
64         UNEXPECTED_CONTEXT(ctxt->ctxt_type);
65     }
66   }
67   
68   return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, change_date, chan);
69 }
70
71 DATE_CB(change_date, sub_chan_date_start, date)
72 STRING_CB(change_date, sub_chan_time_start, time)
73
74 void change_date_subscribe()
75 {
76   gedcom_subscribe_to_element(ELT_SUB_CHAN, sub_chan_start, def_elt_end);
77   gedcom_subscribe_to_element(ELT_SUB_CHAN_DATE, sub_chan_date_start,
78                               def_elt_end);
79   gedcom_subscribe_to_element(ELT_SUB_CHAN_TIME, sub_chan_time_start,
80                               def_elt_end);
81 }
82
83 void change_date_add_note(Gom_ctxt ctxt, struct note_sub* note)
84 {
85   struct change_date *chan = SAFE_CTXT_CAST(change_date, ctxt);
86   LINK_CHAIN_ELT(note_sub, chan->note, note)
87 }
88
89 void change_date_add_user_data(Gom_ctxt ctxt, struct user_data* data)
90 {
91   struct change_date *obj = SAFE_CTXT_CAST(change_date, ctxt);
92   LINK_CHAIN_ELT(user_data, obj->extra, data)
93 }
94
95 void change_date_cleanup(struct change_date *chan)
96 {
97   if (chan) {
98     SAFE_FREE(chan->date);
99     SAFE_FREE(chan->time);
100     DESTROY_CHAIN_ELTS(note_sub, chan->note, note_sub_cleanup)
101     DESTROY_CHAIN_ELTS(user_data, chan->extra, user_data_cleanup)
102   }
103   SAFE_FREE(chan);
104 }