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 1279 2000-07-12 22:21:53Z sjboddie $
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*
|
---|
29 | $Log$
|
---|
30 | Revision 1.22.4.1 2000/07/12 22:21:36 sjboddie
|
---|
31 | merged changes to trunk into New_Config_Format branch
|
---|
32 |
|
---|
33 | Revision 1.23 2000/06/29 00:22:58 sjboddie
|
---|
34 | added new numsections field to collection info and made the statusaction
|
---|
35 | recognize it
|
---|
36 |
|
---|
37 | Revision 1.22 1999/12/13 02:24:33 davidb
|
---|
38 | Data fields for cross collection searching (CCS)
|
---|
39 |
|
---|
40 | Support for multiple meta-data entries for same document/section.
|
---|
41 |
|
---|
42 | Revision 1.21 1999/11/01 22:00:50 sjboddie
|
---|
43 | added assignment operator for FilterResponse_t
|
---|
44 |
|
---|
45 | Revision 1.20 1999/10/14 23:02:34 sjboddie
|
---|
46 | fixed bug in new parent metadata stuff
|
---|
47 |
|
---|
48 | Revision 1.19 1999/10/10 07:49:35 sjboddie
|
---|
49 | - metadata now returns map rather than array
|
---|
50 | - redesigned browsing support (although it's not finished
|
---|
51 | so won't currently work ;-)
|
---|
52 |
|
---|
53 | Revision 1.18 1999/09/07 04:56:54 sjboddie
|
---|
54 | added GPL notice
|
---|
55 |
|
---|
56 | Revision 1.17 1999/09/02 00:25:26 rjmcnab
|
---|
57 | changes to get compiling on AIX
|
---|
58 |
|
---|
59 | Revision 1.16 1999/08/13 04:19:05 sjboddie
|
---|
60 | added name attribute to metadata
|
---|
61 |
|
---|
62 | Revision 1.15 1999/08/03 03:31:43 sjboddie
|
---|
63 | added ability to set receptionist from configuration files
|
---|
64 |
|
---|
65 | Revision 1.14 1999/07/16 03:41:29 sjboddie
|
---|
66 | changed isApprox
|
---|
67 |
|
---|
68 | Revision 1.13 1999/07/08 20:46:45 rjmcnab
|
---|
69 | Added the result number to the ResultDocInfo_t
|
---|
70 |
|
---|
71 | Revision 1.12 1999/07/07 06:11:33 rjmcnab
|
---|
72 | Slight change for multiple phrase matching.
|
---|
73 |
|
---|
74 | Revision 1.11 1999/07/01 22:47:49 sjboddie
|
---|
75 | added format option to collection info
|
---|
76 |
|
---|
77 | Revision 1.10 1999/06/29 22:05:01 rjmcnab
|
---|
78 | Added a couple of fields to ResultDocInfo_t to handle a special
|
---|
79 | version of mg.
|
---|
80 |
|
---|
81 | Revision 1.9 1999/06/16 02:01:22 sjboddie
|
---|
82 | Few changes to get getParents filter option to return metadata of parents
|
---|
83 | as well as current OID
|
---|
84 |
|
---|
85 | Revision 1.8 1999/05/10 03:40:33 sjboddie
|
---|
86 | lots of changes - slowly getting document action sorted out
|
---|
87 |
|
---|
88 | Revision 1.7 1999/04/21 05:23:14 sjboddie
|
---|
89 |
|
---|
90 | Changed the way metadata is returned
|
---|
91 |
|
---|
92 | Revision 1.6 1999/04/06 22:20:34 rjmcnab
|
---|
93 | Got browsefilter working.
|
---|
94 |
|
---|
95 | Revision 1.5 1999/03/31 23:44:47 rjmcnab
|
---|
96 | Altered the protocol so that the metadata is part of the filter.
|
---|
97 |
|
---|
98 | Revision 1.4 1999/03/11 00:11:19 rjmcnab
|
---|
99 | Added a function to get a string version of comerror_t
|
---|
100 |
|
---|
101 | Revision 1.3 1999/03/09 21:00:47 rjmcnab
|
---|
102 | Reorganised the statusaction, added more functions to comtypes.
|
---|
103 |
|
---|
104 | Revision 1.2 1999/03/04 21:19:15 rjmcnab
|
---|
105 |
|
---|
106 | Added clear() functions to all the data types.
|
---|
107 |
|
---|
108 | Revision 1.1 1999/02/21 22:35:25 rjmcnab
|
---|
109 |
|
---|
110 | Initial revision.
|
---|
111 |
|
---|
112 | */
|
---|
113 |
|
---|
114 |
|
---|
115 | #include "comtypes.h"
|
---|
116 |
|
---|
117 |
|
---|
118 | text_t get_comerror_string (comerror_t err) {
|
---|
119 | if (err == noError) return "no error";
|
---|
120 | else if (err == authenticationFailure) return "authentication failure";
|
---|
121 | else if (err == protocolError) return "protocol error";
|
---|
122 | else if (err == configurationError) return "configuration error";
|
---|
123 | else if (err == systemProblem) return "system problem";
|
---|
124 |
|
---|
125 | return "unknown problem";
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | void ShortColInfo_t::clear() {
|
---|
130 | name.clear();
|
---|
131 | host.clear();
|
---|
132 | port = 0;
|
---|
133 | }
|
---|
134 |
|
---|
135 | void ColInfoResponse_t::clear () {
|
---|
136 | shortInfo.clear();
|
---|
137 | isPublic=false;
|
---|
138 | isBeta=false;
|
---|
139 | languages.erase(languages.begin(), languages.end());
|
---|
140 | ccsCols.erase(ccsCols.begin(), ccsCols.end());
|
---|
141 | buildDate=0;
|
---|
142 | numDocs=0;
|
---|
143 | numSections=0;
|
---|
144 | numWords=0;
|
---|
145 | numBytes=0;
|
---|
146 | format.erase(format.begin(), format.end());
|
---|
147 | building.erase(format.begin(), format.end());
|
---|
148 | receptionist.clear();
|
---|
149 | }
|
---|
150 |
|
---|
151 | void InfoFiltersResponse_t::clear () {
|
---|
152 | filterNames.erase(filterNames.begin(), filterNames.end());
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | void InfoFilterOptionsRequest_t::clear () {
|
---|
157 | filterName.clear();
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | void FilterOption_t::clear () {
|
---|
162 | name.clear();
|
---|
163 | type = booleant;
|
---|
164 | repeatable = onePerQuery;
|
---|
165 | defaultValue.clear();
|
---|
166 | validValues.erase(validValues.begin(), validValues.end());
|
---|
167 | }
|
---|
168 |
|
---|
169 | void FilterOption_t::check_defaultValue () {
|
---|
170 | text_tarray::iterator here, end;
|
---|
171 |
|
---|
172 | // how the default is interpreted depends on the option type
|
---|
173 | switch (type) {
|
---|
174 | case booleant:
|
---|
175 | case enumeratedt: // has to be one of the validValues
|
---|
176 | here = validValues.begin ();
|
---|
177 | end = validValues.end ();
|
---|
178 | while (here != end) {
|
---|
179 | if (*here == defaultValue) return;
|
---|
180 | here++;
|
---|
181 | }
|
---|
182 |
|
---|
183 | break;
|
---|
184 |
|
---|
185 | case integert: // has to be in the validValues range
|
---|
186 | if ((validValues.size() >= 2) &&
|
---|
187 | (validValues[0].getint() <= defaultValue.getint()) &&
|
---|
188 | (validValues[1].getint() >= defaultValue.getint()))
|
---|
189 | return;
|
---|
190 | break;
|
---|
191 |
|
---|
192 | case stringt: // any value is valid
|
---|
193 | return;
|
---|
194 | }
|
---|
195 |
|
---|
196 | // did not find the defaultValue
|
---|
197 | if (validValues.empty()) defaultValue.clear();
|
---|
198 | else defaultValue = validValues[0];
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 | bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
203 | return ((x.name == y.name) &&
|
---|
204 | (x.type == y.type) &&
|
---|
205 | (x.repeatable == y.repeatable) &&
|
---|
206 | (x.defaultValue == y.defaultValue) &&
|
---|
207 | (x.validValues == y.validValues));
|
---|
208 | }
|
---|
209 |
|
---|
210 | bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
211 | return ((x.name < y.name) ||
|
---|
212 | ((x.name == y.name) &&
|
---|
213 | ((x.type < y.type) ||
|
---|
214 | ((x.type == y.type) &&
|
---|
215 | ((x.repeatable < y.repeatable) ||
|
---|
216 | ((x.repeatable == y.repeatable) &&
|
---|
217 | ((x.defaultValue < y.defaultValue) ||
|
---|
218 | ((x.defaultValue == y.defaultValue) &&
|
---|
219 | (x.validValues < y.validValues)))))))));
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 | void InfoFilterOptionsResponse_t::clear () {
|
---|
225 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | void OptionValue_t::clear () {
|
---|
230 | name.clear();
|
---|
231 | value.clear();
|
---|
232 | }
|
---|
233 |
|
---|
234 |
|
---|
235 | void FilterRequest_t::clear () {
|
---|
236 | filterName.clear();
|
---|
237 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
238 | docSet.erase(docSet.begin(), docSet.end());
|
---|
239 | filterResultOptions = 0;
|
---|
240 | requestParams.clear();
|
---|
241 | refParams.clear();
|
---|
242 | fields.erase(fields.begin(), fields.end());
|
---|
243 | getParents = false;
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | void TermInfo_t::clear () {
|
---|
248 | term.clear();
|
---|
249 | freq = 0;
|
---|
250 | matchTerms.erase (matchTerms.begin(), matchTerms.end());
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | void MetadataInfo_t::clear () {
|
---|
255 | params.clear();
|
---|
256 | isRef = false;
|
---|
257 | values.erase(values.begin(), values.end());
|
---|
258 | if (parent != NULL) {
|
---|
259 | delete parent;
|
---|
260 | parent = NULL;
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
|
---|
265 |
|
---|
266 | // copy constructor
|
---|
267 | MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
|
---|
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 |
|
---|
278 | MetadataInfo_t::~MetadataInfo_t () {
|
---|
279 | if (parent != NULL) {
|
---|
280 | delete parent;
|
---|
281 | parent = NULL;
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
|
---|
286 | if (&x != this) {
|
---|
287 | params = x.params;
|
---|
288 | isRef = x.isRef;
|
---|
289 | values = x.values;
|
---|
290 | if (x.parent == NULL) parent = NULL;
|
---|
291 | else {
|
---|
292 | parent = new MetadataInfo_t ();
|
---|
293 | *parent = *(x.parent);
|
---|
294 | }
|
---|
295 | }
|
---|
296 | return *this;
|
---|
297 | }
|
---|
298 |
|
---|
299 | void ResultDocInfo_t::clear () {
|
---|
300 | OID.clear ();
|
---|
301 | ranking = 0;
|
---|
302 | result_num = 0;
|
---|
303 | num_terms_matched = 0;
|
---|
304 | num_phrase_match = 0;
|
---|
305 | docFreq.erase(docFreq.begin(), docFreq.end());
|
---|
306 | metadata.erase(metadata.begin(), metadata.end());
|
---|
307 | classifier_metadata_type.erase(classifier_metadata_type.begin(),
|
---|
308 | classifier_metadata_type.end());
|
---|
309 | classifier_metadata_offset = 0;
|
---|
310 |
|
---|
311 | }
|
---|
312 |
|
---|
313 | ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
|
---|
314 | OID = x.OID;
|
---|
315 | ranking = x.ranking;
|
---|
316 | result_num = x.result_num;
|
---|
317 | num_terms_matched = x.num_terms_matched;
|
---|
318 | num_phrase_match = x.num_phrase_match;
|
---|
319 | docFreq = x.docFreq;
|
---|
320 | metadata = x.metadata;
|
---|
321 | return *this;
|
---|
322 | }
|
---|
323 |
|
---|
324 | void FilterResponse_t::clear () {
|
---|
325 | numDocs = 0;
|
---|
326 | isApprox = Exact;
|
---|
327 | termInfo.erase (termInfo.begin(), termInfo.end());
|
---|
328 | docInfo.erase (docInfo.begin(), docInfo.end());
|
---|
329 | }
|
---|
330 |
|
---|
331 | FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
|
---|
332 | numDocs = x.numDocs;
|
---|
333 | isApprox = x.isApprox;
|
---|
334 | termInfo = x.termInfo;
|
---|
335 | docInfo = x.docInfo;
|
---|
336 | return *this;
|
---|
337 | }
|
---|
338 |
|
---|
339 | void DocumentRequest_t::clear () {
|
---|
340 | OID.clear();
|
---|
341 | docType.clear();
|
---|
342 | docFormat.clear();
|
---|
343 | }
|
---|
344 |
|
---|
345 | void DocumentResponse_t::clear () {
|
---|
346 | doc.clear();
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|