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