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

Last change on this file since 11985 was 11985, checked in by kjdon, 18 years ago

no searchTypes array any more - it is now a format statement

  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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 *********************************************************************/
25
26#include "comtypes.h"
27
28
29text_t get_comerror_string (comerror_t err) {
30 if (err == noError) return "no error";
31 else if (err == authenticationFailure) return "authentication failure";
32 else if (err == protocolError) return "protocol error";
33 else if (err == configurationError) return "configuration error";
34 else if (err == systemProblem) return "system problem";
35 else if (err == syntaxError) return "query syntax error";
36 return "unknown problem";
37}
38
39
40void ShortColInfo_t::clear() {
41 name.clear();
42 host.clear();
43 port = 0;
44}
45
46/*
47 isPublic now defaults to true most values are default
48 similar to a constructor in a class to make some initializations
49*/
50
51void ColInfoResponse_t::clear () {
52 shortInfo.clear();
53 isPublic=true;
54 isBeta=false;
55 isSegmented=false;
56 languages.erase(languages.begin(), languages.end());
57 ccsCols.erase(ccsCols.begin(), ccsCols.end());
58 ccsOptions = 0;
59 buildDate=0;
60 buildType.clear();
61 numDocs=0;
62 numSections=0;
63 numWords=0;
64 numBytes=0;
65 format.erase(format.begin(), format.end());
66 building.erase(building.begin(), building.end());
67 httpdomain.clear();
68 httpprefix.clear();
69 receptionist.clear();
70
71 // Setting some authentication parameters use with
72 // various parts of the code.
73
74 authenticate.clear(); // turned off by default, individual collection authentication
75 auth_group.clear(); // turned off by default, authentication by groups method
76 public_documents.clear(); // turned off by default, allow access to these documents <list>
77 private_documents.clear(); // turned off by default, disallow access to these documents <list>
78
79}
80
81text_t ColInfoResponse_t::get_collectionmeta(text_t name, text_t lang) {
82 text_t value = collectionmeta[name][lang];
83 if (value.empty()) {
84 value = collectionmeta[name][g_EmptyText];
85 }
86 return value;
87
88}
89
90void InfoFiltersResponse_t::clear () {
91 filterNames.erase(filterNames.begin(), filterNames.end());
92}
93
94
95void InfoFilterOptionsRequest_t::clear () {
96 filterName.clear();
97}
98
99
100void FilterOption_t::clear () {
101 name.clear();
102 type = booleant;
103 repeatable = onePerQuery;
104 defaultValue.clear();
105 validValues.erase(validValues.begin(), validValues.end());
106}
107
108void FilterOption_t::check_defaultValue () {
109 text_tarray::iterator here, end;
110
111 // how the default is interpreted depends on the option type
112 switch (type) {
113 case booleant:
114 case enumeratedt: // has to be one of the validValues
115 here = validValues.begin ();
116 end = validValues.end ();
117 while (here != end) {
118 if (*here == defaultValue) return;
119 ++here;
120 }
121
122 break;
123
124 case integert: // has to be in the validValues range
125 if ((validValues.size() >= 2) &&
126 (validValues[0].getint() <= defaultValue.getint()) &&
127 (validValues[1].getint() >= defaultValue.getint()))
128 return;
129 break;
130
131 case stringt: // any value is valid
132 return;
133 }
134
135 // did not find the defaultValue
136 if (validValues.empty()) defaultValue.clear();
137 else defaultValue = validValues[0];
138}
139
140
141bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
142 return ((x.name == y.name) &&
143 (x.type == y.type) &&
144 (x.repeatable == y.repeatable) &&
145 (x.defaultValue == y.defaultValue) &&
146 (x.validValues == y.validValues));
147}
148
149bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
150 return ((x.name < y.name) ||
151 ((x.name == y.name) &&
152 ((x.type < y.type) ||
153 ((x.type == y.type) &&
154 ((x.repeatable < y.repeatable) ||
155 ((x.repeatable == y.repeatable) &&
156 ((x.defaultValue < y.defaultValue) ||
157 ((x.defaultValue == y.defaultValue) &&
158 (x.validValues < y.validValues)))))))));
159}
160
161
162
163void InfoFilterOptionsResponse_t::clear () {
164 filterOptions.erase(filterOptions.begin(), filterOptions.end());
165}
166
167
168void OptionValue_t::clear () {
169 name.clear();
170 value.clear();
171}
172
173
174void FilterRequest_t::clear () {
175 filterName.clear();
176 filterLang.clear();
177 filterOptions.erase(filterOptions.begin(), filterOptions.end());
178 docSet.erase(docSet.begin(), docSet.end());
179 filterResultOptions = 0;
180 requestParams.clear();
181 refParams.clear();
182 fields.erase(fields.begin(), fields.end());
183 getParents = false;
184}
185
186
187void TermInfo_t::clear () {
188 term.clear();
189 freq = 0;
190 matchTerms.erase (matchTerms.begin(), matchTerms.end());
191}
192
193
194void MetadataInfo_t::clear () {
195 params.clear();
196 isRef = false;
197 values.erase(values.begin(), values.end());
198 if (parent != NULL) {
199 delete parent;
200 parent = NULL;
201 }
202}
203
204MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
205
206// copy constructor
207MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
208 params = x.params;
209 isRef = x.isRef;
210 values = x.values;
211 if (x.parent == NULL) parent = NULL;
212 else {
213 parent = new MetadataInfo_t ();
214 *parent = *(x.parent);
215 }
216}
217
218MetadataInfo_t::~MetadataInfo_t () {
219 if (parent != NULL) {
220 delete parent;
221 parent = NULL;
222 }
223}
224
225MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
226 if (&x != this) {
227 params = x.params;
228 isRef = x.isRef;
229 values = x.values;
230 if (x.parent == NULL) parent = NULL;
231 else {
232 parent = new MetadataInfo_t ();
233 *parent = *(x.parent);
234 }
235 }
236 return *this;
237}
238
239void ResultDocInfo_t::clear () {
240 OID.clear ();
241 ranking = 0;
242 result_num = 0;
243 num_terms_matched = 0;
244 num_phrase_match = 0;
245 docFreq.erase(docFreq.begin(), docFreq.end());
246 metadata.erase(metadata.begin(), metadata.end());
247 classifier_metadata_type.erase(classifier_metadata_type.begin(),
248 classifier_metadata_type.end());
249 classifier_metadata_offset = 0;
250
251}
252
253ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
254 OID = x.OID;
255 ranking = x.ranking;
256 result_num = x.result_num;
257 num_terms_matched = x.num_terms_matched;
258 num_phrase_match = x.num_phrase_match;
259 docFreq = x.docFreq;
260 metadata = x.metadata;
261 return *this;
262}
263
264void FilterResponse_t::clear () {
265 numDocs = 0;
266 isApprox = Exact;
267 termInfo.erase (termInfo.begin(), termInfo.end());
268 docInfo.erase (docInfo.begin(), docInfo.end());
269}
270
271FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
272 numDocs = x.numDocs;
273 isApprox = x.isApprox;
274 termInfo = x.termInfo;
275 docInfo = x.docInfo;
276 return *this;
277}
278
279void DocumentRequest_t::clear () {
280 OID.clear();
281 docType.clear();
282 docFormat.clear();
283}
284
285void DocumentResponse_t::clear () {
286 doc.clear();
287}
Note: See TracBrowser for help on using the repository browser.