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