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 |
|
---|
29 | text_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 |
|
---|
36 | return "unknown problem";
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | void ShortColInfo_t::clear() {
|
---|
41 | name.clear();
|
---|
42 | host.clear();
|
---|
43 | port = 0;
|
---|
44 | }
|
---|
45 |
|
---|
46 | void ColInfoResponse_t::clear () {
|
---|
47 | shortInfo.clear();
|
---|
48 | isPublic=false;
|
---|
49 | isBeta=false;
|
---|
50 | languages.erase(languages.begin(), languages.end());
|
---|
51 | ccsCols.erase(ccsCols.begin(), ccsCols.end());
|
---|
52 | buildDate=0;
|
---|
53 | buildType.clear();
|
---|
54 | numDocs=0;
|
---|
55 | numSections=0;
|
---|
56 | numWords=0;
|
---|
57 | numBytes=0;
|
---|
58 | format.erase(format.begin(), format.end());
|
---|
59 | building.erase(format.begin(), format.end());
|
---|
60 | httpdomain.clear();
|
---|
61 | httpprefix.clear();
|
---|
62 | receptionist.clear();
|
---|
63 | }
|
---|
64 |
|
---|
65 | void InfoFiltersResponse_t::clear () {
|
---|
66 | filterNames.erase(filterNames.begin(), filterNames.end());
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | void InfoFilterOptionsRequest_t::clear () {
|
---|
71 | filterName.clear();
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | void FilterOption_t::clear () {
|
---|
76 | name.clear();
|
---|
77 | type = booleant;
|
---|
78 | repeatable = onePerQuery;
|
---|
79 | defaultValue.clear();
|
---|
80 | validValues.erase(validValues.begin(), validValues.end());
|
---|
81 | }
|
---|
82 |
|
---|
83 | void FilterOption_t::check_defaultValue () {
|
---|
84 | text_tarray::iterator here, end;
|
---|
85 |
|
---|
86 | // how the default is interpreted depends on the option type
|
---|
87 | switch (type) {
|
---|
88 | case booleant:
|
---|
89 | case enumeratedt: // has to be one of the validValues
|
---|
90 | here = validValues.begin ();
|
---|
91 | end = validValues.end ();
|
---|
92 | while (here != end) {
|
---|
93 | if (*here == defaultValue) return;
|
---|
94 | here++;
|
---|
95 | }
|
---|
96 |
|
---|
97 | break;
|
---|
98 |
|
---|
99 | case integert: // has to be in the validValues range
|
---|
100 | if ((validValues.size() >= 2) &&
|
---|
101 | (validValues[0].getint() <= defaultValue.getint()) &&
|
---|
102 | (validValues[1].getint() >= defaultValue.getint()))
|
---|
103 | return;
|
---|
104 | break;
|
---|
105 |
|
---|
106 | case stringt: // any value is valid
|
---|
107 | return;
|
---|
108 | }
|
---|
109 |
|
---|
110 | // did not find the defaultValue
|
---|
111 | if (validValues.empty()) defaultValue.clear();
|
---|
112 | else defaultValue = validValues[0];
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
117 | return ((x.name == y.name) &&
|
---|
118 | (x.type == y.type) &&
|
---|
119 | (x.repeatable == y.repeatable) &&
|
---|
120 | (x.defaultValue == y.defaultValue) &&
|
---|
121 | (x.validValues == y.validValues));
|
---|
122 | }
|
---|
123 |
|
---|
124 | bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
|
---|
125 | return ((x.name < y.name) ||
|
---|
126 | ((x.name == y.name) &&
|
---|
127 | ((x.type < y.type) ||
|
---|
128 | ((x.type == y.type) &&
|
---|
129 | ((x.repeatable < y.repeatable) ||
|
---|
130 | ((x.repeatable == y.repeatable) &&
|
---|
131 | ((x.defaultValue < y.defaultValue) ||
|
---|
132 | ((x.defaultValue == y.defaultValue) &&
|
---|
133 | (x.validValues < y.validValues)))))))));
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 | void InfoFilterOptionsResponse_t::clear () {
|
---|
139 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | void OptionValue_t::clear () {
|
---|
144 | name.clear();
|
---|
145 | value.clear();
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | void FilterRequest_t::clear () {
|
---|
150 | filterName.clear();
|
---|
151 | filterOptions.erase(filterOptions.begin(), filterOptions.end());
|
---|
152 | docSet.erase(docSet.begin(), docSet.end());
|
---|
153 | filterResultOptions = 0;
|
---|
154 | requestParams.clear();
|
---|
155 | refParams.clear();
|
---|
156 | fields.erase(fields.begin(), fields.end());
|
---|
157 | getParents = false;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | void TermInfo_t::clear () {
|
---|
162 | term.clear();
|
---|
163 | freq = 0;
|
---|
164 | matchTerms.erase (matchTerms.begin(), matchTerms.end());
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | void MetadataInfo_t::clear () {
|
---|
169 | params.clear();
|
---|
170 | isRef = false;
|
---|
171 | values.erase(values.begin(), values.end());
|
---|
172 | if (parent != NULL) {
|
---|
173 | delete parent;
|
---|
174 | parent = NULL;
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
|
---|
179 |
|
---|
180 | // copy constructor
|
---|
181 | MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
|
---|
182 | params = x.params;
|
---|
183 | isRef = x.isRef;
|
---|
184 | values = x.values;
|
---|
185 | if (x.parent == NULL) parent = NULL;
|
---|
186 | else {
|
---|
187 | parent = new MetadataInfo_t ();
|
---|
188 | *parent = *(x.parent);
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | MetadataInfo_t::~MetadataInfo_t () {
|
---|
193 | if (parent != NULL) {
|
---|
194 | delete parent;
|
---|
195 | parent = NULL;
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
|
---|
200 | if (&x != this) {
|
---|
201 | params = x.params;
|
---|
202 | isRef = x.isRef;
|
---|
203 | values = x.values;
|
---|
204 | if (x.parent == NULL) parent = NULL;
|
---|
205 | else {
|
---|
206 | parent = new MetadataInfo_t ();
|
---|
207 | *parent = *(x.parent);
|
---|
208 | }
|
---|
209 | }
|
---|
210 | return *this;
|
---|
211 | }
|
---|
212 |
|
---|
213 | void ResultDocInfo_t::clear () {
|
---|
214 | OID.clear ();
|
---|
215 | ranking = 0;
|
---|
216 | result_num = 0;
|
---|
217 | num_terms_matched = 0;
|
---|
218 | num_phrase_match = 0;
|
---|
219 | docFreq.erase(docFreq.begin(), docFreq.end());
|
---|
220 | metadata.erase(metadata.begin(), metadata.end());
|
---|
221 | classifier_metadata_type.erase(classifier_metadata_type.begin(),
|
---|
222 | classifier_metadata_type.end());
|
---|
223 | classifier_metadata_offset = 0;
|
---|
224 |
|
---|
225 | }
|
---|
226 |
|
---|
227 | ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
|
---|
228 | OID = x.OID;
|
---|
229 | ranking = x.ranking;
|
---|
230 | result_num = x.result_num;
|
---|
231 | num_terms_matched = x.num_terms_matched;
|
---|
232 | num_phrase_match = x.num_phrase_match;
|
---|
233 | docFreq = x.docFreq;
|
---|
234 | metadata = x.metadata;
|
---|
235 | return *this;
|
---|
236 | }
|
---|
237 |
|
---|
238 | void FilterResponse_t::clear () {
|
---|
239 | numDocs = 0;
|
---|
240 | isApprox = Exact;
|
---|
241 | termInfo.erase (termInfo.begin(), termInfo.end());
|
---|
242 | docInfo.erase (docInfo.begin(), docInfo.end());
|
---|
243 | }
|
---|
244 |
|
---|
245 | FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
|
---|
246 | numDocs = x.numDocs;
|
---|
247 | isApprox = x.isApprox;
|
---|
248 | termInfo = x.termInfo;
|
---|
249 | docInfo = x.docInfo;
|
---|
250 | return *this;
|
---|
251 | }
|
---|
252 |
|
---|
253 | void DocumentRequest_t::clear () {
|
---|
254 | OID.clear();
|
---|
255 | docType.clear();
|
---|
256 | docFormat.clear();
|
---|
257 | }
|
---|
258 |
|
---|
259 | void DocumentResponse_t::clear () {
|
---|
260 | doc.clear();
|
---|
261 | }
|
---|