root/gsdl/trunk/src/colservr/comtypes.cpp @ 15757

Revision 15416, 7.5 KB (checked in by mdewsnip, 12 years ago)

(Untangling colservr/recpt) Moved comtypes out of recpt and into colservr, since this defines the types used to communicate with the colservr.

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  isCollectGroup=false;
58  languages.erase(languages.begin(), languages.end());
59  ccsCols.erase(ccsCols.begin(), ccsCols.end());
60  ccsOptions = 0;
61  stemIndexes = 3; // old default was both provided
62  buildDate=0;
63  buildType.clear();
64  numDocs=0;
65  numSections=0;
66  numWords=0;
67  numBytes=0;
68  format.erase(format.begin(), format.end());
69  building.erase(building.begin(), building.end());
70  httpdomain.clear();
71  httpprefix.clear();
72  receptionist.clear();
73
74  // Setting some authentication parameters use with
75  // various parts of the code.
76 
77  authenticate.clear();         // turned off by default, individual collection authentication
78  auth_group.clear();              // turned off by default, authentication by groups method
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   
82}
83
84text_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
93void InfoFiltersResponse_t::clear () {
94  filterNames.erase(filterNames.begin(), filterNames.end());
95}
96
97
98void InfoFilterOptionsRequest_t::clear () {
99  filterName.clear();
100}
101
102
103void FilterOption_t::clear () {
104  name.clear();
105  type = booleant;
106  repeatable = onePerQuery;
107  defaultValue.clear();
108  validValues.erase(validValues.begin(), validValues.end());
109}
110
111void FilterOption_t::check_defaultValue () {
112  text_tarray::iterator here, end;
113
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;
122      ++here;
123    }
124   
125    break;
126
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;
136  }
137
138  // did not find the defaultValue
139  if (validValues.empty()) defaultValue.clear();
140  else defaultValue = validValues[0];
141}
142
143
144bool 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
152bool 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
166void InfoFilterOptionsResponse_t::clear () {
167  filterOptions.erase(filterOptions.begin(), filterOptions.end());
168}
169
170
171void OptionValue_t::clear () {
172  name.clear();
173  value.clear();
174}
175
176
177void FilterRequest_t::clear () {
178  filterName.clear();
179  filterLang.clear();
180  filterOptions.erase(filterOptions.begin(), filterOptions.end());
181  docSet.erase(docSet.begin(), docSet.end());
182  filterResultOptions = 0;
183  requestParams.clear();
184  refParams.clear();
185  fields.erase(fields.begin(), fields.end());
186  getParents = false;
187}
188
189
190void TermInfo_t::clear () {
191  term.clear();
192  freq = 0;
193  matchTerms.erase (matchTerms.begin(), matchTerms.end());
194}
195
196
197void MetadataInfo_t::clear () {
198  params.clear();
199  isRef = false;
200  values.erase(values.begin(), values.end());
201  if (parent != NULL) {
202    delete parent;
203    parent = NULL;
204  }
205}
206
207MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
208
209// copy constructor
210MetadataInfo_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
221MetadataInfo_t::~MetadataInfo_t () {
222  if (parent != NULL) {
223    delete parent;
224    parent = NULL;
225  }
226}
227
228MetadataInfo_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
242void ResultDocInfo_t::clear () {
243  OID.clear ();
244  ranking = 0;
245  result_num = 0;
246  num_terms_matched = 0;
247  num_phrase_match = 0;
248  docFreq.erase(docFreq.begin(), docFreq.end());
249  metadata.erase(metadata.begin(), metadata.end());
250  classifier_metadata_type.erase(classifier_metadata_type.begin(),
251                 classifier_metadata_type.end());
252  classifier_metadata_offset = 0;
253 
254}
255
256ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
257  OID = x.OID;
258  ranking = x.ranking;
259  result_num = x.result_num;
260  num_terms_matched = x.num_terms_matched;
261  num_phrase_match = x.num_phrase_match;
262  docFreq = x.docFreq;
263  metadata = x.metadata;
264  return *this;
265}
266
267void FilterResponse_t::clear () {
268  error_message = g_EmptyText;
269  numDocs = 0;
270  isApprox = Exact;
271  termInfo.erase (termInfo.begin(), termInfo.end());
272  docInfo.erase (docInfo.begin(), docInfo.end());
273  stopwords.clear();
274}
275
276FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
277  error_message = x.error_message;
278  numDocs = x.numDocs;
279  isApprox = x.isApprox;
280  termInfo = x.termInfo;
281  docInfo = x.docInfo;
282  stopwords = x.stopwords;
283  return *this;
284}
285
286void DocumentRequest_t::clear () {
287  OID.clear();
288  docType.clear();
289  docFormat.clear();
290}
291
292void DocumentResponse_t::clear () {
293  doc.clear();
294}
Note: See TracBrowser for help on using the browser.