1 /* $Id: record.c,v 1.9 2007-06-07 12:27:03 adam Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* $Id: record.c,v 1.9 2007-06-07 12:27:03 adam Exp $ */
27 #include <yaz/yaz-util.h>
34 //#define CONFIG_NOEXTERNS
40 union data_types * data_types_assign(NMEM nmem,
41 union data_types ** data1,
42 union data_types data2)
53 *data1 = nmem_malloc(nmem, sizeof(union data_types));
61 struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys,
62 struct client *client)
64 struct record * record = 0;
69 record = nmem_malloc(nmem, sizeof(struct record));
72 record->client = client;
76 sizeof(struct record_metadata*) * num_metadata);
77 for (i = 0; i < num_metadata; i++)
78 record->metadata[i] = 0;
82 sizeof(union data_types*) * num_sortkeys);
83 for (i = 0; i < num_sortkeys; i++)
84 record->sortkeys[i] = 0;
89 struct record_metadata * record_metadata_create(NMEM nmem)
91 struct record_metadata * rec_md
92 = nmem_malloc(nmem, sizeof(struct record_metadata));
98 struct record_metadata * record_metadata_insert(NMEM nmem,
99 struct record_metadata ** rmd,
100 union data_types data)
102 struct record_metadata * tmp_rmd = 0;
108 // construct new record_metadata
109 tmp_rmd = nmem_malloc(nmem, sizeof(struct record_metadata));
110 tmp_rmd->data = data;
113 // insert in *rmd's place, moving *rmd one down the list
114 tmp_rmd->next = *rmd;
120 struct record_metadata * record_add_metadata_field_id(NMEM nmem,
121 struct record * record,
123 union data_types data)
125 if (field_id < 0 || !record || !record->metadata)
128 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
132 struct record_metadata * record_add_metadata(NMEM nmem,
133 struct record * record,
134 struct conf_service * service,
136 union data_types data)
140 if (!record || !record->metadata || !service || !name)
143 field_id = conf_service_metadata_field_id(service, name);
148 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
156 union data_types * record_assign_sortkey_field_id(NMEM nmem,
157 struct record * record,
159 union data_types data)
161 if (field_id < 0 || !record || !record->sortkeys)
164 return data_types_assign(nmem, &(record->sortkeys[field_id]), data);
169 union data_types * record_assign_sortkey(NMEM nmem,
170 struct record * record,
171 struct conf_service * service,
173 union data_types data)
177 if (!record || !service || !name)
180 field_id = conf_service_sortkey_field_id(service, name);
182 if (!(-1 < field_id) || !(field_id < service->num_sortkeys))
185 return record_assign_sortkey_field_id(nmem, record, field_id, data);
193 * indent-tabs-mode: nil
195 * vim: shiftwidth=4 tabstop=8 expandtab