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);
51 repo->address = address;
54 void repository_add_phone(Gom_ctxt ctxt, char *phone)
56 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
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);
65 void repository_add_note(Gom_ctxt ctxt, struct note_sub* note)
67 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
68 LINK_CHAIN_ELT(note_sub, repo->note, note)
71 void repository_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
73 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
74 LINK_CHAIN_ELT(user_ref_number, repo->ref, ref)
77 void repository_set_record_id(Gom_ctxt ctxt, char *rin)
79 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
80 repo->record_id = strdup(rin);
83 void repository_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
85 struct repository *repo = SAFE_CTXT_CAST(repository, ctxt);
86 repo->change_date = chan;
89 void repository_add_user_data(Gom_ctxt ctxt, struct user_data* data)
91 struct repository *obj = SAFE_CTXT_CAST(repository, ctxt);
92 LINK_CHAIN_ELT(user_data, obj->extra, data)
95 void repository_cleanup(struct repository* repo)
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)
110 void repositories_cleanup()
112 DESTROY_CHAIN_ELTS(repository, gom_first_repository, repository_cleanup);
115 struct repository* gom_get_first_repository()
117 return gom_first_repository;
120 struct repository* make_repository_record(char* xrefstr)
122 struct repository* repo;
123 MAKE_CHAIN_ELT(repository, gom_first_repository, repo);
124 repo->xrefstr = strdup(xrefstr);