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 "comtypes.h"
|
---|
33 |
|
---|
34 |
|
---|
35 | class sourceclass {
|
---|
36 | public:
|
---|
37 | sourceclass ();
|
---|
38 | virtual ~sourceclass ();
|
---|
39 |
|
---|
40 | // configure should be called once for each configuration line
|
---|
41 | virtual void configure (const text_t &key, const text_tarray &cfgline);
|
---|
42 |
|
---|
43 | // init should be called after all the configuration is done but
|
---|
44 | // before any other methods are called
|
---|
45 | virtual bool init (ostream &logout);
|
---|
46 |
|
---|
47 | // translate_OID translates OIDs using ".pr", ."fc" etc.
|
---|
48 | virtual bool translate_OID (const text_t &OIDin, text_t &OIDout,
|
---|
49 | comerror_t &err, ostream &logout);
|
---|
50 |
|
---|
51 | // get_metadata fills out the metadata if possible, if it is not responsable
|
---|
52 | // for the given OID then it will return false.
|
---|
53 | virtual bool get_metadata (const text_t &requestParams, const text_t &refParams,
|
---|
54 | bool getParents, const text_tset &fields,
|
---|
55 | const text_t &OID, MetadataInfo_tmap &metadata,
|
---|
56 | comerror_t &err, ostream &logout);
|
---|
57 |
|
---|
58 | virtual bool get_document (const text_t &OID, text_t &doc,
|
---|
59 | comerror_t &err, ostream &logout);
|
---|
60 |
|
---|
61 | virtual bool is_searchable(bool &issearchable, comerror_t &err, ostream &logout);
|
---|
62 | };
|
---|
63 |
|
---|
64 |
|
---|
65 | // The sourceptr class does not 'own' the source. The
|
---|
66 | // source should be deleted by the code which created it.
|
---|
67 | class sourceptr {
|
---|
68 | public:
|
---|
69 | sourceclass *s;
|
---|
70 |
|
---|
71 | sourceptr () {s=NULL;}
|
---|
72 | ~sourceptr () {}
|
---|
73 | };
|
---|
74 |
|
---|
75 | bool operator==(const sourceptr &x, const sourceptr &y);
|
---|
76 | bool operator<(const sourceptr &x, const sourceptr &y);
|
---|
77 |
|
---|
78 | typedef vector<sourceptr> sourceptrlist;
|
---|
79 |
|
---|
80 | // contains a list of sources
|
---|
81 | class sourcelistclass {
|
---|
82 | protected:
|
---|
83 | sourceptrlist sourceptrs;
|
---|
84 |
|
---|
85 | public:
|
---|
86 | // type support for sourcelistclass
|
---|
87 | typedef sourceptrlist::iterator iterator;
|
---|
88 | typedef sourceptrlist::const_iterator const_iterator;
|
---|
89 | typedef sourceptrlist::reference reference;
|
---|
90 | typedef sourceptrlist::const_reference const_reference;
|
---|
91 | typedef sourceptrlist::size_type size_type;
|
---|
92 |
|
---|
93 | typedef sourceptrlist::difference_type difference_type;
|
---|
94 | typedef sourceptrlist::const_reverse_iterator const_reverse_iterator;
|
---|
95 | typedef sourceptrlist::reverse_iterator reverse_iterator;
|
---|
96 |
|
---|
97 | // basic container support
|
---|
98 | iterator begin () {return sourceptrs.begin();}
|
---|
99 | const_iterator begin () const {return sourceptrs.begin();}
|
---|
100 | iterator end () {return sourceptrs.end();}
|
---|
101 | const_iterator end () const {return sourceptrs.end();}
|
---|
102 |
|
---|
103 | void erase(iterator pos) {sourceptrs.erase(pos);}
|
---|
104 | void erase(iterator first, iterator last) {sourceptrs.erase(first, last);}
|
---|
105 | sourcelistclass &operator=(const sourcelistclass &x)
|
---|
106 | {sourceptrs=x.sourceptrs;return *this;}
|
---|
107 |
|
---|
108 | bool empty () const {return sourceptrs.empty();}
|
---|
109 | size_type size() const {return sourceptrs.size();}
|
---|
110 |
|
---|
111 |
|
---|
112 | // added functionality
|
---|
113 | void clear () {sourceptrs.erase(sourceptrs.begin(),sourceptrs.end());}
|
---|
114 |
|
---|
115 | // thesource remains the property of the calling code but
|
---|
116 | // should not be deleted until it is removed from this list.
|
---|
117 | void addsource (sourceclass *thesource);
|
---|
118 | };
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | #endif
|
---|