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

Last change on this file since 13982 was 13982, checked in by lh92, 17 years ago

Added UseBook variable for Realistic Book

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