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