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