root/gsdl/trunk/src/colservr/source.h @ 15757

Revision 15591, 4.8 KB (checked in by mdewsnip, 12 years ago)

(Adding new DB support) Moved all the code in gdbmsource into source, and changed mggdbmsource and lucenegdbmsource to inherit from source instead of gdbmsource. This is part of removing GDBM from these files altogether.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 * source.h --
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
27#ifndef SOURCE_H
28#define SOURCE_H
29
30#include "gsdlconf.h"
31#include "text_t.h"
32#include "dbclass.h"
33#include "search.h"
34#include "comtypes.h"
35#include "maptools.h"
36
37
38class sourceclass {
39protected:
40  text_t classname;
41
42  text_t gsdlhome;
43  text_t dbhome;
44  text_t collection;
45  text_t collectdir;
46
47  stringmap indexmap;
48  stringmap subcollectionmap;
49  stringmap languagemap;
50
51  text_t defaultindex;
52  text_t defaultsubcollection;
53  text_t defaultlanguage;
54
55  text_t indexstem;
56
57  text_t parentOID;
58  infodbclass parentinfo;
59  text_tarray parentcontents;
60
61  text_t db_filename;
62  dbclass *db_ptr;
63
64  searchclass *textsearchptr;
65
66public:
67  sourceclass ();
68  virtual ~sourceclass ();
69
70  // the DB ptr remains the responsibility of the calling code
71  void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; }
72
73  // the textsearchptr remains the responsibility of the calling code
74  void set_textsearchptr (searchclass *textsearchptr_arg) { textsearchptr = textsearchptr_arg; }
75
76  // configure should be called once for each configuration line
77  virtual void configure (const text_t &key, const text_tarray &cfgline);
78
79  // init should be called after all the configuration is done but
80  // before any other methods are called
81  virtual bool init (ostream &logout);
82
83  // translate_OID translates OIDs using ".pr", ."fc" etc.
84  virtual bool translate_OID (const text_t &OIDin, text_t &OIDout,
85                  comerror_t &err, ostream &logout);
86
87  // get_metadata fills out the metadata if possible, if it is not responsable
88  // for the given OID then it will return false.
89  virtual bool get_metadata (const text_t &requestParams, const text_t &refParams,
90                 bool getParents, const text_tset &fields,
91                 const text_t &OID, MetadataInfo_tmap &metadata,
92                 comerror_t &err, ostream &logout);
93
94  virtual bool get_document (const text_t &OID, text_t &doc,
95                 comerror_t &err, ostream &logout);
96
97  virtual bool is_searchable(bool &issearchable, comerror_t &err, ostream &logout);
98};
99
100
101// The sourceptr class does not 'own' the source. The
102// source should be deleted by the code which created it.
103class sourceptr {
104public:
105  sourceclass *s;
106
107  sourceptr () {s=NULL;}
108  ~sourceptr () {}
109};
110
111bool operator==(const sourceptr &x, const sourceptr &y);
112bool operator<(const sourceptr &x, const sourceptr &y);
113
114typedef vector<sourceptr> sourceptrlist;
115
116// contains a list of sources
117class sourcelistclass {
118protected:
119  sourceptrlist sourceptrs;
120
121public:
122  // type support for sourcelistclass
123  typedef sourceptrlist::iterator iterator;
124  typedef sourceptrlist::const_iterator const_iterator;
125  typedef sourceptrlist::reference reference;
126  typedef sourceptrlist::const_reference const_reference;
127  typedef sourceptrlist::size_type size_type;
128
129  typedef sourceptrlist::difference_type difference_type;
130  typedef sourceptrlist::const_reverse_iterator const_reverse_iterator;
131  typedef sourceptrlist::reverse_iterator reverse_iterator;
132 
133  // basic container support
134  iterator begin () {return sourceptrs.begin();}
135  const_iterator begin () const {return sourceptrs.begin();}
136  iterator end () {return sourceptrs.end();}
137  const_iterator end () const {return sourceptrs.end();}
138
139  void erase(iterator pos) {sourceptrs.erase(pos);}
140  void erase(iterator first, iterator last) {sourceptrs.erase(first, last);}
141  sourcelistclass &operator=(const sourcelistclass &x)
142    {sourceptrs=x.sourceptrs;return *this;}
143
144  bool empty () const {return sourceptrs.empty();}
145  size_type size() const {return sourceptrs.size();}
146
147
148  // added functionality
149  void clear () {sourceptrs.erase(sourceptrs.begin(),sourceptrs.end());}
150
151  // thesource remains the property of the calling code but
152  // should not be deleted until it is removed from this list.
153  void addsource (sourceclass *thesource);
154};
155
156
157
158#endif
Note: See TracBrowser for help on using the browser.