[216] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * filter.h --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * PUT COPYRIGHT NOTICE HERE
|
---|
| 7 | *
|
---|
| 8 | * $Id: filter.h 472 1999-08-25 04:50:00Z sjboddie $
|
---|
| 9 | *
|
---|
| 10 | *********************************************************************/
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | #ifndef FILTER_H
|
---|
| 14 | #define FILTER_H
|
---|
| 15 |
|
---|
| 16 | #include "gsdlconf.h"
|
---|
| 17 | #include "text_t.h"
|
---|
| 18 | #include "comtypes.h"
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | class filterclass {
|
---|
[226] | 22 | protected:
|
---|
| 23 | text_t gsdlhome;
|
---|
| 24 | text_t collection;
|
---|
| 25 | text_t collectdir;
|
---|
| 26 |
|
---|
| 27 | FilterOption_tmap filterOptions;
|
---|
| 28 |
|
---|
[216] | 29 | public:
|
---|
| 30 | filterclass ();
|
---|
| 31 | virtual ~filterclass ();
|
---|
| 32 |
|
---|
| 33 | // configure should be called once for each configuration line
|
---|
[226] | 34 | // default configures the default filter options
|
---|
[216] | 35 | virtual void configure (const text_t &key, const text_tarray &cfgline);
|
---|
| 36 |
|
---|
| 37 | // init should be called after all the configuration is done but
|
---|
| 38 | // before any other methods are called
|
---|
[226] | 39 | // default checks all the filter option defaults
|
---|
[216] | 40 | virtual bool init (ostream &logout);
|
---|
| 41 |
|
---|
| 42 | // returns the name of this filter
|
---|
| 43 | virtual text_t get_filter_name ();
|
---|
| 44 |
|
---|
[226] | 45 | // returns the current filter options
|
---|
| 46 | virtual void get_filteroptions (InfoFilterOptionsResponse_t &response,
|
---|
| 47 | comerror_t &err, ostream &logout);
|
---|
[216] | 48 |
|
---|
| 49 | virtual void filter (const FilterRequest_t &request,
|
---|
| 50 | FilterResponse_t &response,
|
---|
| 51 | comerror_t &err, ostream &logout);
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 |
|
---|
[220] | 55 | // The filterptr class does not 'own' the filter. The
|
---|
| 56 | // filter should be deleted by the code which created it.
|
---|
| 57 | class filterptr {
|
---|
| 58 | public:
|
---|
| 59 | filterclass *f;
|
---|
| 60 |
|
---|
| 61 | filterptr () {f=NULL;}
|
---|
| 62 | };
|
---|
| 63 |
|
---|
| 64 | typedef map<text_t, filterptr, lttext_t> filterptrmap;
|
---|
| 65 |
|
---|
| 66 | // contains a list of filters indexed by their name
|
---|
| 67 | class filtermapclass {
|
---|
| 68 | protected:
|
---|
| 69 | filterptrmap filterptrs;
|
---|
| 70 |
|
---|
| 71 | public:
|
---|
| 72 | // type support for filterptrmap
|
---|
| 73 | typedef filterptrmap::iterator iterator;
|
---|
| 74 | typedef filterptrmap::const_iterator const_iterator;
|
---|
| 75 | typedef filterptrmap::reference reference;
|
---|
| 76 | typedef filterptrmap::const_reference const_reference;
|
---|
| 77 | typedef filterptrmap::size_type size_type;
|
---|
| 78 |
|
---|
| 79 | typedef filterptrmap::difference_type difference_type;
|
---|
| 80 | typedef filterptrmap::const_reverse_iterator const_reverse_iterator;
|
---|
| 81 | typedef filterptrmap::reverse_iterator reverse_iterator;
|
---|
| 82 |
|
---|
| 83 | // basic container support
|
---|
| 84 | iterator begin () {return filterptrs.begin();}
|
---|
| 85 | const_iterator begin () const {return filterptrs.begin();}
|
---|
| 86 | iterator end () {return filterptrs.end();}
|
---|
| 87 | const_iterator end () const {return filterptrs.end();}
|
---|
| 88 |
|
---|
| 89 | void erase(iterator pos) {filterptrs.erase(pos);}
|
---|
| 90 | void erase(iterator first, iterator last) {filterptrs.erase(first, last);}
|
---|
| 91 | filtermapclass &operator=(const filtermapclass &x) {filterptrs=x.filterptrs;return *this;}
|
---|
| 92 |
|
---|
| 93 | bool empty () const {return filterptrs.empty();}
|
---|
| 94 | size_type size() const {return filterptrs.size();}
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | // added functionality
|
---|
| 98 | void clear () {filterptrs.erase(filterptrs.begin(),filterptrs.end());}
|
---|
| 99 |
|
---|
| 100 | // thefilter remains the property of the calling code but
|
---|
| 101 | // should not be deleted until it is removed from this list.
|
---|
| 102 | void addfilter (filterclass *thefilter);
|
---|
| 103 |
|
---|
| 104 | // getfilter will return NULL if the filter could not be found
|
---|
| 105 | filterclass *getfilter (const text_t &key);
|
---|
| 106 | };
|
---|
| 107 |
|
---|
| 108 |
|
---|
[226] | 109 |
|
---|
| 110 | // some useful functions for dealing with document sets
|
---|
| 111 |
|
---|
| 112 | // intersect places the result in set1
|
---|
| 113 | void intersect (text_tset &set1, const text_tset &set2);
|
---|
[249] | 114 | void intersect (text_tarray &set1, const text_tset &set2);
|
---|
[472] | 115 | void intersect (text_tarray &set1, const text_tarray &set2);
|
---|
[226] | 116 |
|
---|
[235] | 117 | // tests to see if el is in set
|
---|
| 118 | bool in_set (const text_tset &set1, const text_t &el);
|
---|
[472] | 119 | bool in_set (const text_tarray &set1, const text_t &el);
|
---|
[235] | 120 |
|
---|
[216] | 121 | #endif
|
---|