source: gsdl/trunk/src/colservr/filter.h@ 16445

Last change on this file since 16445 was 16310, checked in by davidb, 16 years ago

Introduction of 'collecthome' which parallels 'gsdlhome' to allow the toplevel collect folder to be outside of the gsdlhome area

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/**********************************************************************
2 *
3 * filter.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 FILTER_H
28#define FILTER_H
29
30#include "gsdlconf.h"
31#include "text_t.h"
32#include "comtypes.h"
33
34
35class filterclass {
36protected:
37 text_t gsdlhome;
38 text_t collecthome;
39 text_t dbhome;
40 text_t collection;
41 text_t collectdir;
42
43 FilterOption_tmap filterOptions;
44
45public:
46 filterclass ();
47 virtual ~filterclass ();
48
49 // configure should be called once for each configuration line
50 // default configures the default filter options
51 virtual void configure (const text_t &key, const text_tarray &cfgline);
52
53 // init should be called after all the configuration is done but
54 // before any other methods are called
55 // default checks all the filter option defaults
56 virtual bool init (ostream &logout);
57
58 // returns the name of this filter
59 virtual text_t get_filter_name ();
60
61 // returns the current filter options
62 virtual void get_filteroptions (InfoFilterOptionsResponse_t &response,
63 comerror_t &err, ostream &logout);
64
65 virtual void filter (const FilterRequest_t &request,
66 FilterResponse_t &response,
67 comerror_t &err, ostream &logout);
68
69 protected:
70 text_t resolve_db_filename(const text_t& idx,const text_t& file_ext);
71
72
73};
74
75
76// The filterptr class does not 'own' the filter. The
77// filter should be deleted by the code which created it.
78class filterptr {
79public:
80 filterclass *f;
81
82 filterptr () {f=NULL;}
83 ~filterptr () {}
84};
85
86bool operator==(const filterptr &x, const filterptr &y);
87bool operator<(const filterptr &x, const filterptr &y);
88
89
90typedef map<text_t, filterptr, lttext_t> filterptrmap;
91
92// contains a list of filters indexed by their name
93class filtermapclass {
94protected:
95 filterptrmap filterptrs;
96
97public:
98 // type support for filterptrmap
99 typedef filterptrmap::iterator iterator;
100 typedef filterptrmap::const_iterator const_iterator;
101 typedef filterptrmap::reference reference;
102 typedef filterptrmap::const_reference const_reference;
103 typedef filterptrmap::size_type size_type;
104
105 typedef filterptrmap::difference_type difference_type;
106 typedef filterptrmap::const_reverse_iterator const_reverse_iterator;
107 typedef filterptrmap::reverse_iterator reverse_iterator;
108
109 // basic container support
110 iterator begin () {return filterptrs.begin();}
111 const_iterator begin () const {return filterptrs.begin();}
112 iterator end () {return filterptrs.end();}
113 const_iterator end () const {return filterptrs.end();}
114
115 void erase(iterator pos) {filterptrs.erase(pos);}
116 void erase(iterator first, iterator last) {filterptrs.erase(first, last);}
117 filtermapclass &operator=(const filtermapclass &x) {filterptrs=x.filterptrs;return *this;}
118
119 bool empty () const {return filterptrs.empty();}
120 size_type size() const {return filterptrs.size();}
121
122
123 // added functionality
124 void clear () {filterptrs.erase(filterptrs.begin(),filterptrs.end());}
125
126 // thefilter remains the property of the calling code but
127 // should not be deleted until it is removed from this list.
128 void addfilter (filterclass *thefilter);
129
130 // getfilter will return NULL if the filter could not be found
131 filterclass *getfilter (const text_t &key);
132};
133
134
135
136// some useful functions for dealing with document sets
137
138// intersect places the result in set1
139void intersect (text_tset &set1, const text_tset &set2);
140void intersect (text_tarray &set1, const text_tset &set2);
141void intersect (text_tarray &set1, const text_tarray &set2);
142
143// tests to see if el is in set
144bool in_set (const text_tset &set1, const text_t &el);
145bool in_set (const text_tarray &set1, const text_t &el);
146
147#endif
Note: See TracBrowser for help on using the repository browser.