source: trunk/gsdl/src/recpt/comtypes.cpp@ 671

Last change on this file since 671 was 671, checked in by sjboddie, 25 years ago

fixed bug in new parent metadata stuff

  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/**********************************************************************
2 *
3 * comtypes.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: comtypes.cpp 671 1999-10-14 23:02:34Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.20 1999/10/14 23:02:34 sjboddie
31 fixed bug in new parent metadata stuff
32
33 Revision 1.19 1999/10/10 07:49:35 sjboddie
34 - metadata now returns map rather than array
35 - redesigned browsing support (although it's not finished
36 so won't currently work ;-)
37
38 Revision 1.18 1999/09/07 04:56:54 sjboddie
39 added GPL notice
40
41 Revision 1.17 1999/09/02 00:25:26 rjmcnab
42 changes to get compiling on AIX
43
44 Revision 1.16 1999/08/13 04:19:05 sjboddie
45 added name attribute to metadata
46
47 Revision 1.15 1999/08/03 03:31:43 sjboddie
48 added ability to set receptionist from configuration files
49
50 Revision 1.14 1999/07/16 03:41:29 sjboddie
51 changed isApprox
52
53 Revision 1.13 1999/07/08 20:46:45 rjmcnab
54 Added the result number to the ResultDocInfo_t
55
56 Revision 1.12 1999/07/07 06:11:33 rjmcnab
57 Slight change for multiple phrase matching.
58
59 Revision 1.11 1999/07/01 22:47:49 sjboddie
60 added format option to collection info
61
62 Revision 1.10 1999/06/29 22:05:01 rjmcnab
63 Added a couple of fields to ResultDocInfo_t to handle a special
64 version of mg.
65
66 Revision 1.9 1999/06/16 02:01:22 sjboddie
67 Few changes to get getParents filter option to return metadata of parents
68 as well as current OID
69
70 Revision 1.8 1999/05/10 03:40:33 sjboddie
71 lots of changes - slowly getting document action sorted out
72
73 Revision 1.7 1999/04/21 05:23:14 sjboddie
74
75 Changed the way metadata is returned
76
77 Revision 1.6 1999/04/06 22:20:34 rjmcnab
78 Got browsefilter working.
79
80 Revision 1.5 1999/03/31 23:44:47 rjmcnab
81 Altered the protocol so that the metadata is part of the filter.
82
83 Revision 1.4 1999/03/11 00:11:19 rjmcnab
84 Added a function to get a string version of comerror_t
85
86 Revision 1.3 1999/03/09 21:00:47 rjmcnab
87 Reorganised the statusaction, added more functions to comtypes.
88
89 Revision 1.2 1999/03/04 21:19:15 rjmcnab
90
91 Added clear() functions to all the data types.
92
93 Revision 1.1 1999/02/21 22:35:25 rjmcnab
94
95 Initial revision.
96
97 */
98
99
100#include "comtypes.h"
101
102
103text_t get_comerror_string (comerror_t err) {
104 if (err == noError) return "no error";
105 else if (err == authenticationFailure) return "authentication failure";
106 else if (err == protocolError) return "protocol error";
107 else if (err == configurationError) return "configuration error";
108 else if (err == systemProblem) return "system problem";
109
110 return "unknown problem";
111}
112
113
114void ShortColInfo_t::clear() {
115 name.clear();
116 host.clear();
117 port = 0;
118}
119
120void ColInfoResponse_t::clear () {
121 shortInfo.clear();
122 isPublic=false;
123 isBeta=false;
124 buildDate=0;
125 numDocs=0;
126 numWords=0;
127 numBytes=0;
128 format.erase(format.begin(), format.end());
129 receptionist.clear();
130}
131
132void InfoFiltersResponse_t::clear () {
133 filterNames.erase(filterNames.begin(), filterNames.end());
134}
135
136
137void InfoFilterOptionsRequest_t::clear () {
138 filterName.clear();
139}
140
141
142void FilterOption_t::clear () {
143 name.clear();
144 type = booleant;
145 repeatable = onePerQuery;
146 defaultValue.clear();
147 validValues.erase(validValues.begin(), validValues.end());
148}
149
150void FilterOption_t::check_defaultValue () {
151 text_tarray::iterator here, end;
152
153 // how the default is interpreted depends on the option type
154 switch (type) {
155 case booleant:
156 case enumeratedt: // has to be one of the validValues
157 here = validValues.begin ();
158 end = validValues.end ();
159 while (here != end) {
160 if (*here == defaultValue) return;
161 here++;
162 }
163
164 break;
165
166 case integert: // has to be in the validValues range
167 if ((validValues.size() >= 2) &&
168 (validValues[0].getint() <= defaultValue.getint()) &&
169 (validValues[1].getint() >= defaultValue.getint()))
170 return;
171 break;
172
173 case stringt: // any value is valid
174 return;
175 }
176
177 // did not find the defaultValue
178 if (validValues.empty()) defaultValue.clear();
179 else defaultValue = validValues[0];
180}
181
182
183bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
184 return ((x.name == y.name) &&
185 (x.type == y.type) &&
186 (x.repeatable == y.repeatable) &&
187 (x.defaultValue == y.defaultValue) &&
188 (x.validValues == y.validValues));
189}
190
191bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
192 return ((x.name < y.name) ||
193 ((x.name == y.name) &&
194 ((x.type < y.type) ||
195 ((x.type == y.type) &&
196 ((x.repeatable < y.repeatable) ||
197 ((x.repeatable == y.repeatable) &&
198 ((x.defaultValue < y.defaultValue) ||
199 ((x.defaultValue == y.defaultValue) &&
200 (x.validValues < y.validValues)))))))));
201}
202
203
204
205void InfoFilterOptionsResponse_t::clear () {
206 filterOptions.erase(filterOptions.begin(), filterOptions.end());
207}
208
209
210void OptionValue_t::clear () {
211 name.clear();
212 value.clear();
213}
214
215
216void FilterRequest_t::clear () {
217 filterName.clear();
218 filterOptions.erase(filterOptions.begin(), filterOptions.end());
219 docSet.erase(docSet.begin(), docSet.end());
220 filterResultOptions = 0;
221 requestParams.clear();
222 refParams.clear();
223 fields.erase(fields.begin(), fields.end());
224 getParents = false;
225}
226
227
228void TermInfo_t::clear () {
229 term.clear();
230 freq = 0;
231 matchTerms.erase (matchTerms.begin(), matchTerms.end());
232}
233
234
235void MetadataInfo_t::clear () {
236 params.clear();
237 isRef = false;
238 values.erase(values.begin(), values.end());
239 if (parent != NULL) {
240 delete parent;
241 parent = NULL;
242 }
243}
244
245MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
246
247// copy constructor
248MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
249 params = x.params;
250 isRef = x.isRef;
251 values = x.values;
252 if (x.parent == NULL) parent = NULL;
253 else {
254 parent = new MetadataInfo_t ();
255 *parent = *(x.parent);
256 }
257}
258
259MetadataInfo_t::~MetadataInfo_t () {
260 if (parent != NULL) {
261 delete parent;
262 parent = NULL;
263 }
264}
265
266MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
267 if (&x != this) {
268 params = x.params;
269 isRef = x.isRef;
270 values = x.values;
271 if (x.parent == NULL) parent = NULL;
272 else {
273 parent = new MetadataInfo_t ();
274 *parent = *(x.parent);
275 }
276 }
277 return *this;
278}
279
280void ResultDocInfo_t::clear () {
281 OID.clear ();
282 ranking = 0;
283 result_num = 0;
284 num_terms_matched = 0;
285 num_phrase_match = 0;
286 docFreq.erase(docFreq.begin(), docFreq.end());
287 metadata.erase(metadata.begin(), metadata.end());
288}
289
290ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
291 OID=x.OID;
292 ranking=x.ranking;
293 result_num=x.result_num;
294 num_terms_matched=x.num_terms_matched;
295 num_phrase_match = x.num_phrase_match;
296 docFreq=x.docFreq;
297 metadata=x.metadata;
298 return *this;
299}
300
301
302void FilterResponse_t::clear () {
303 numDocs = 0;
304 isApprox = Exact;
305 termInfo.erase (termInfo.begin(), termInfo.end());
306 docInfo.erase (docInfo.begin(), docInfo.end());
307}
308
309
310void DocumentRequest_t::clear () {
311 OID.clear();
312 docType.clear();
313 docFormat.clear();
314}
315
316void DocumentResponse_t::clear () {
317 doc.clear();
318}
319
320
321
Note: See TracBrowser for help on using the repository browser.