First check-in of gedcom object model.
[gedcom-parse.git] / gom / multimedia_link.c
1 /* Multimedia 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.
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 "multimedia_link.h"
27 #include "event.h"
28 #include "source_citation.h"
29 #include "note_sub.h"
30 #include "family.h"
31 #include "individual.h"
32 #include "source.h"
33 #include "submitter.h"
34 #include "user_rec.h"
35 #include "gom.h"
36 #include "gedcom.h"
37 #include "gom_internal.h"
38
39 Gedcom_ctxt sub_obje_start(_ELT_PARAMS_)
40 {
41   Gom_ctxt ctxt = (Gom_ctxt)parent;
42   struct multimedia_link *mm = NULL;
43
44   if (ctxt) {
45     mm = (struct multimedia_link *)malloc(sizeof(struct multimedia_link));
46     memset (mm, 0, sizeof(struct multimedia_link));
47     if (GEDCOM_IS_XREF_PTR(parsed_value))
48       mm->reference = GEDCOM_XREF_PTR(parsed_value);
49
50     switch (ctxt->ctxt_type) {
51       case ELT_SUB_FAM_EVT:
52       case ELT_SUB_FAM_EVT_EVEN:
53       case ELT_SUB_INDIV_ATTR:
54       case ELT_SUB_INDIV_RESI:
55       case ELT_SUB_INDIV_BIRT:
56       case ELT_SUB_INDIV_GEN:
57       case ELT_SUB_INDIV_ADOP:
58       case ELT_SUB_INDIV_EVEN:
59         event_add_mm_link(ctxt, mm); break;
60       case ELT_SUB_SOUR:
61         citation_add_mm_link(ctxt, mm); break;
62       case REC_FAM:
63         family_add_mm_link(ctxt, mm); break;
64       case REC_INDI:
65         individual_add_mm_link(ctxt, mm); break;
66       case REC_SOUR:
67         source_add_mm_link(ctxt, mm); break;
68       case REC_SUBM:
69         submitter_add_mm_link(ctxt, mm); break;
70       default:
71         UNEXPECTED_CONTEXT(ctxt->ctxt_type);
72     }
73   }
74
75   return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, multimedia_link, mm);
76 }
77
78 STRING_CB(multimedia_link, sub_obje_form_start, form)
79 STRING_CB(multimedia_link, sub_obje_titl_start, title)
80 STRING_CB(multimedia_link, sub_obje_file_start, file)
81      
82 void multimedia_link_subscribe()
83 {
84   gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE,
85                               sub_obje_start, def_elt_end);
86   gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_FORM,
87                               sub_obje_form_start, def_elt_end);
88   gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_TITL,
89                               sub_obje_titl_start, def_elt_end);
90   gedcom_subscribe_to_element(ELT_SUB_MULTIM_OBJE_FILE,
91                               sub_obje_file_start, def_elt_end);
92 }
93
94 void multimedia_link_add_note(Gom_ctxt ctxt, struct note_sub* note)
95 {
96   struct multimedia_link *mm = SAFE_CTXT_CAST(multimedia_link, ctxt);
97   LINK_CHAIN_ELT(note_sub, mm->note, note)    
98 }
99
100 void multimedia_link_add_user_data(Gom_ctxt ctxt, struct user_data* data)
101 {
102   struct multimedia_link *obj = SAFE_CTXT_CAST(multimedia_link, ctxt);
103   LINK_CHAIN_ELT(user_data, obj->extra, data)
104 }
105
106 void multimedia_link_cleanup(struct multimedia_link* mm)
107 {
108   if (mm) {
109     SAFE_FREE(mm->form);
110     SAFE_FREE(mm->title);
111     SAFE_FREE(mm->file);
112     DESTROY_CHAIN_ELTS(note_sub, mm->note, note_sub_cleanup)
113     DESTROY_CHAIN_ELTS(user_data, mm->extra, user_data_cleanup)
114   }
115 }