1 /* Submission 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 "submission.h"
27 #include "submitter.h"
31 #include "gom_internal.h"
33 struct submission* gom_submission = NULL;
35 DEFINE_REC_CB(submission, subn_start)
36 DEFINE_XREF_CB(submission, subn_subm_start, submitter, submitter)
37 DEFINE_STRING_CB(submission, subn_famf_start, family_file)
38 DEFINE_STRING_CB(submission, subn_temp_start, temple_code)
39 DEFINE_STRING_CB(submission, subn_ance_start, nr_of_ancestor_gens)
40 DEFINE_STRING_CB(submission, subn_desc_start, nr_of_descendant_gens)
41 DEFINE_STRING_CB(submission, subn_ordi_start, ordinance_process_flag)
42 DEFINE_STRING_CB(submission, subn_rin_start, record_id)
44 DEFINE_ADDFUNC2(submission, user_data, extra)
46 void submission_subscribe()
48 gedcom_subscribe_to_record(REC_SUBN, subn_start, def_rec_end);
49 gedcom_subscribe_to_element(ELT_SUBN_SUBM, subn_subm_start, def_elt_end);
50 gedcom_subscribe_to_element(ELT_SUBN_FAMF, subn_famf_start, def_elt_end);
51 gedcom_subscribe_to_element(ELT_SUBN_TEMP, subn_temp_start, def_elt_end);
52 gedcom_subscribe_to_element(ELT_SUBN_ANCE, subn_ance_start, def_elt_end);
53 gedcom_subscribe_to_element(ELT_SUBN_DESC, subn_desc_start, def_elt_end);
54 gedcom_subscribe_to_element(ELT_SUBN_ORDI, subn_ordi_start, def_elt_end);
55 gedcom_subscribe_to_element(ELT_SUBN_RIN, subn_rin_start, def_elt_end);
58 void UNREFALLFUNC(submission)()
61 unref_xref_value(gom_submission->submitter);
62 UNREFALLFUNC(user_data)(gom_submission->extra);
66 void CLEANFUNC(submission)()
69 SAFE_FREE(gom_submission->xrefstr);
70 SAFE_FREE(gom_submission->family_file);
71 SAFE_FREE(gom_submission->temple_code);
72 SAFE_FREE(gom_submission->nr_of_ancestor_gens);
73 SAFE_FREE(gom_submission->nr_of_descendant_gens);
74 SAFE_FREE(gom_submission->ordinance_process_flag);
75 SAFE_FREE(gom_submission->record_id);
76 DESTROY_CHAIN_ELTS(user_data, gom_submission->extra);
78 SAFE_FREE(gom_submission);
81 struct submission* gom_get_submission()
83 return gom_submission;
86 struct submission* MAKEFUNC(submission)(const char* xref)
88 if (! gom_submission) {
89 gom_submission = (struct submission*)malloc(sizeof(struct submission));
93 memset(gom_submission, 0, sizeof(struct submission));
94 gom_submission->xrefstr = strdup(xref);
95 if (!gom_submission->xrefstr) MEMORY_ERROR;
99 return gom_submission;
102 void DESTROYFUNC(submission)()
104 if (gom_submission) {
105 submission_cleanup();
106 SAFE_FREE(gom_submission);
110 struct submission* ADDFUNC(submission)(const char* xrefstr)
112 if (!gom_submission) {
113 struct xref_value* xrv = gedcom_get_by_xref(xrefstr);
115 gom_xref_already_in_use(xrefstr);
117 gom_submission = MAKEFUNC(submission)(xrefstr);
118 if (gom_submission) {
119 xrv = gedcom_add_xref(XREF_SUBN, xrefstr, gom_submission);
121 DESTROYFUNC(submission)(gom_submission);
122 gom_submission = NULL;
126 return gom_submission;
132 int DELETEFUNC(submission)()
135 if (gom_submission) {
136 result = gedcom_delete_xref(gom_submission->xrefstr);
138 UNREFALLFUNC(submission)();
139 DESTROYFUNC(submission)();
145 int write_submission(Gedcom_write_hndl hndl)
149 if (gom_submission) {
150 result |= gedcom_write_record_str(hndl, REC_SUBN,
151 gom_submission->xrefstr, NULL);
152 if (gom_submission->submitter)
153 result |= gedcom_write_element_xref(hndl, ELT_SUBN_SUBM, 0,
154 REC_SUBN, gom_submission->submitter);
155 if (gom_submission->family_file)
156 result |= gedcom_write_element_str(hndl, ELT_SUBN_FAMF, 0, REC_SUBN,
157 gom_submission->family_file);
158 if (gom_submission->temple_code)
159 result |= gedcom_write_element_str(hndl, ELT_SUBN_TEMP, 0, REC_SUBN,
160 gom_submission->temple_code);
161 if (gom_submission->nr_of_ancestor_gens)
162 result |= gedcom_write_element_str(hndl, ELT_SUBN_ANCE, 0, REC_SUBN,
163 gom_submission->nr_of_ancestor_gens);
164 if (gom_submission->nr_of_descendant_gens)
165 result |= gedcom_write_element_str(hndl, ELT_SUBN_DESC, 0, REC_SUBN,
166 gom_submission->nr_of_descendant_gens);
167 if (gom_submission->ordinance_process_flag)
168 result |= gedcom_write_element_str(hndl, ELT_SUBN_ORDI, 0, REC_SUBN,
169 gom_submission->ordinance_process_flag);
170 if (gom_submission->record_id)
171 result |= gedcom_write_element_str(hndl, ELT_SUBN_RIN, 0, REC_SUBN,
172 gom_submission->record_id);
173 if (gom_submission->extra)
174 result |= write_user_data(hndl, gom_submission->extra);