00001 #ifndef TAGCOLL_EXPRESSION_FILTER_H
00002 #define TAGCOLL_EXPRESSION_FILTER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma interface
00025
00026 #include <tagcoll/TagcollFilter.h>
00027 #include <tagcoll/tagexpr/Tagexpr.h>
00028
00029 #include <string>
00030
00031 namespace Tagcoll
00032 {
00033
00034 class ExpressionFilter : public TagcollFilter<std::string>
00035 {
00036 protected:
00037 Tagexpr* expr;
00038 int matched;
00039
00040 bool match(const OpSet<std::string>& ts) const throw ();
00041
00042 public:
00043 enum MatchType { PLAIN, INVERTED };
00044
00045 protected:
00046 MatchType matchType;
00047
00048 public:
00049 ExpressionFilter() throw () : expr(0), matched(0), matchType(PLAIN) {}
00050 virtual ~ExpressionFilter() throw () { if (expr) delete expr; }
00051
00052
00053
00054 bool setExpression(const std::string& expression) throw ();
00055
00056 void setMatchType(MatchType type) throw () { matchType = type; }
00057
00058 int countMatched() const throw () { return matched; }
00059
00060 virtual void consume(const std::string& item) throw ()
00061 {
00062 if (match(OpSet<std::string>()))
00063 {
00064 matched++;
00065 consumer->consume(item);
00066 }
00067 }
00068
00069 virtual void consume(const std::string& item, const OpSet<std::string>& tags) throw ()
00070 {
00071 if (match(tags))
00072 {
00073 matched++;
00074 consumer->consume(item, tags);
00075 }
00076 }
00077
00078 virtual void consume(const OpSet<std::string>& items) throw ()
00079 {
00080 if (match(OpSet<std::string>()))
00081 {
00082 matched += items.size();
00083 consumer->consume(items);
00084 }
00085 }
00086
00087 virtual void consume(const OpSet<std::string>& items, const OpSet<std::string>& tags) throw ()
00088 {
00089 if (match(tags))
00090 {
00091 matched += items.size();
00092 consumer->consume(items, tags);
00093 }
00094 }
00095 };
00096
00097 };
00098
00099
00100 #endif