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.
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 "repository.h"
30 #include "change_date.h"
34 #include "gom_internal.h"
36 struct repository* gom_first_repository = NULL;
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)
42 void repository_subscribe()
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);
48 void repository_add_address(Gom_ctxt ctxt, struct address* address)
50 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
52 repo->address = address;
55 void repository_add_phone(Gom_ctxt ctxt, char *phone)
57 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
60 while (i<2 && repo->phone[i]) i++;
61 if (! repo->phone[i]) {
62 repo->phone[i] = strdup(phone);
63 if (! repo->phone[i]) MEMORY_ERROR;
68 void repository_add_note(Gom_ctxt ctxt, struct note_sub* note)
70 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
72 LINK_CHAIN_ELT(note_sub, repo->note, note);
75 void repository_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
77 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
79 LINK_CHAIN_ELT(user_ref_number, repo->ref, ref);
82 void repository_set_record_id(Gom_ctxt ctxt, char *rin)
84 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
86 repo->record_id = strdup(rin);
87 if (! repo->record_id) MEMORY_ERROR;
91 void repository_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
93 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
95 repo->change_date = chan;
98 void repository_add_user_data(Gom_ctxt ctxt, struct user_data* data)
100 struct repository *obj = SAFE_CTXT_CAST(repository, ctxt);
102 LINK_CHAIN_ELT(user_data, obj->extra, data);
105 void repository_cleanup(struct repository* repo)
108 SAFE_FREE(repo->xrefstr);
109 SAFE_FREE(repo->name);
110 address_cleanup(repo->address);
111 SAFE_FREE(repo->phone[0]);
112 SAFE_FREE(repo->phone[1]);
113 SAFE_FREE(repo->phone[2]);
114 DESTROY_CHAIN_ELTS(note_sub, repo->note, note_sub_cleanup);
115 DESTROY_CHAIN_ELTS(user_ref_number, repo->ref, user_ref_cleanup);
116 SAFE_FREE(repo->record_id);
117 change_date_cleanup(repo->change_date);
118 DESTROY_CHAIN_ELTS(user_data, repo->extra, user_data_cleanup);
122 void repositories_cleanup()
124 DESTROY_CHAIN_ELTS(repository, gom_first_repository, repository_cleanup);
127 struct repository* gom_get_first_repository()
129 return gom_first_repository;
132 struct repository* make_repository_record(char* xrefstr)
134 struct repository* repo = NULL;
135 MAKE_CHAIN_ELT(repository, gom_first_repository, repo);
137 repo->xrefstr = strdup(xrefstr);
138 if (! repo->xrefstr) MEMORY_ERROR;