started record constructors. still unfnished, but yet only used in test_relevance.c
[pazpar2-moved-to-github.git] / src / record.c
1 /* $Id: record.c,v 1.1 2007-04-20 14:37:17 marc Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
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
9 version.
10
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
14 for more details.
15
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
19 02111-1307, USA.
20  */
21
22 /* $Id: record.c,v 1.1 2007-04-20 14:37:17 marc Exp $ */
23
24
25 #include <string.h>
26
27 #include <yaz/yaz-util.h>
28 #include <yaz/nmem.h>
29
30 #if HAVE_CONFIG_H
31 #include <cconfig.h>
32 #endif
33
34 //#define CONFIG_NOEXTERNS
35 #include "config.h"
36 #include "record.h"
37
38
39 struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys)
40 {
41     struct record * record = 0;
42     
43     // assert(nmem);
44
45     record = nmem_malloc(nmem, sizeof(struct record));
46
47     record->next = 0;
48     // which client should I use for record->client = cl;  ??
49     record->client = 0;
50
51     record->metadata 
52         = nmem_malloc(nmem, 
53                       sizeof(struct record_metadata*) * num_metadata);
54     memset(record->metadata, 0, 
55            sizeof(struct record_metadata*) * num_metadata);
56     
57     record->sortkeys  
58         = nmem_malloc(nmem, 
59                       sizeof(union data_types*) * num_sortkeys);
60     memset(record->metadata, 0, 
61            sizeof(union data_types*) * num_sortkeys);
62     
63     
64     return record;
65 }
66
67
68 struct record_metadata * record_add_metadata_fieldno(NMEM nmem, 
69                                                      struct record * record,
70                                                      int fieldno, 
71                                                      union data_types data)
72 {
73     struct record_metadata * rmd = 0;
74     
75     if (!record || fieldno < 0 
76         || !record->metadata || !record->metadata[fieldno] )
77         return 0;
78
79     // construct new record_metadata    
80     rmd  = nmem_malloc(nmem, sizeof(struct record_metadata));
81     rmd->data = data;
82     rmd->next = 0;
83
84     // still needs to be assigned ..
85
86     return rmd;
87     
88 };
89
90
91 /*
92  * Local variables:
93  * c-basic-offset: 4
94  * indent-tabs-mode: nil
95  * End:
96  * vim: shiftwidth=4 tabstop=8 expandtab
97  */