Forgotten internal header file.
[gedcom-parse.git] / gom / repository.c
1 /* Repository object 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 "repository.h"
27 #include "address.h"
28 #include "note_sub.h"
29 #include "user_ref.h"
30 #include "change_date.h"
31 #include "user_rec.h"
32 #include "gom.h"
33 #include "gedcom.h"
34 #include "gom_internal.h"
35
36 struct repository* gom_first_repository = NULL;
37
38 REC_CB(repository, repo_start, make_repository_record)
39 GET_REC_BY_XREF(repository, XREF_REPO, gom_get_repository_by_xref)
40 STRING_CB(repository, repo_name_start, name)
41
42 void repository_subscribe()
43 {
44   gedcom_subscribe_to_record(REC_REPO, repo_start, def_rec_end);
45   gedcom_subscribe_to_element(ELT_REPO_NAME, repo_name_start, def_elt_end);
46 }
47
48 void repository_add_address(Gom_ctxt ctxt, struct address* address)
49 {
50   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
51   repo->address = address;
52 }
53
54 void repository_add_phone(Gom_ctxt ctxt, char *phone)
55 {
56   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
57   if (! repo->phone[0])
58     repo->phone[0] = strdup(phone);
59   else if (! repo->phone[1])
60     repo->phone[1] = strdup(phone);
61   else if (! repo->phone[2])
62     repo->phone[2] = strdup(phone);
63 }
64
65 void repository_add_note(Gom_ctxt ctxt, struct note_sub* note)
66 {
67   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
68   LINK_CHAIN_ELT(note_sub, repo->note, note)
69 }
70
71 void repository_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
72 {
73   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
74   LINK_CHAIN_ELT(user_ref_number, repo->ref, ref)
75 }
76
77 void repository_set_record_id(Gom_ctxt ctxt, char *rin)
78 {
79   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
80   repo->record_id = strdup(rin);
81 }
82
83 void repository_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
84 {
85   struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
86   repo->change_date = chan;
87 }
88
89 void repository_add_user_data(Gom_ctxt ctxt, struct user_data* data)
90 {
91   struct repository *obj = SAFE_CTXT_CAST(repository, ctxt);
92   LINK_CHAIN_ELT(user_data, obj->extra, data)
93 }
94
95 void repository_cleanup(struct repository* repo)
96 {
97   SAFE_FREE(repo->xrefstr);
98   SAFE_FREE(repo->name);
99   address_cleanup(repo->address);
100   SAFE_FREE(repo->phone[0]);
101   SAFE_FREE(repo->phone[1]);
102   SAFE_FREE(repo->phone[2]);
103   DESTROY_CHAIN_ELTS(note_sub, repo->note, note_sub_cleanup)
104   DESTROY_CHAIN_ELTS(user_ref_number, repo->ref, user_ref_cleanup)
105   SAFE_FREE(repo->record_id);
106   change_date_cleanup(repo->change_date);
107   DESTROY_CHAIN_ELTS(user_data, repo->extra, user_data_cleanup)
108 }
109
110 void repositories_cleanup()
111 {
112   DESTROY_CHAIN_ELTS(repository, gom_first_repository, repository_cleanup);
113 }
114
115 struct repository* gom_get_first_repository()
116 {
117   return gom_first_repository;
118 }
119
120 struct repository* make_repository_record(char* xrefstr)
121 {
122   struct repository* repo;
123   MAKE_CHAIN_ELT(repository, gom_first_repository, repo);
124   repo->xrefstr = strdup(xrefstr);
125   return repo;
126 }