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