1 /* $Id: record.c,v 1.6 2007-04-24 22:19:19 marc 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.6 2007-04-24 22:19:19 marc 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)
63 struct record * record = 0;
68 record = nmem_malloc(nmem, sizeof(struct record));
71 // which client should I use for record->client = cl; ??
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;
90 struct record_metadata * record_metadata_insert(NMEM nmem,
91 struct record_metadata ** rmd,
92 union data_types data)
94 struct record_metadata * tmp_rmd = 0;
100 // construct new record_metadata
101 tmp_rmd = nmem_malloc(nmem, sizeof(struct record_metadata));
102 tmp_rmd->data = data;
105 // insert in *rmd's place, moving *rmd one down the list
106 tmp_rmd->next = *rmd;
112 struct record_metadata * record_add_metadata_field_id(NMEM nmem,
113 struct record * record,
115 union data_types data)
117 if (field_id < 0 || !record || !record->metadata)
120 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
124 struct record_metadata * record_add_metadata(NMEM nmem,
125 struct record * record,
126 struct conf_service * service,
128 union data_types data)
132 if (!record || !record->metadata || !service || !name)
135 field_id = conf_service_metadata_field_id(service, name);
140 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
148 union data_types * record_assign_sortkey_field_id(NMEM nmem,
149 struct record * record,
151 union data_types data)
153 if (field_id < 0 || !record || !record->sortkeys)
156 return data_types_assign(nmem, &(record->sortkeys[field_id]), data);
161 union data_types * record_assign_sortkey(NMEM nmem,
162 struct record * record,
163 struct conf_service * service,
165 union data_types data)
169 if (!record || !service || !name)
172 field_id = conf_service_sortkey_field_id(service, name);
174 if (!(-1 < field_id) || !(field_id < service->num_sortkeys))
177 return record_assign_sortkey_field_id(nmem, record, field_id, data);
185 * indent-tabs-mode: nil
187 * vim: shiftwidth=4 tabstop=8 expandtab