Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ExpressionFilter.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_EXPRESSION_FILTER_H 00002 #define TAGCOLL_EXPRESSION_FILTER_H 00003 00004 /* 00005 * TagcollFilter that filters items using a tag expression 00006 * 00007 * Copyright (C) 2003 Enrico Zini <enrico@debian.org> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 // Set the expression to use for this filter 00053 // Return false if parsing the expression failed 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 // vim:set ts=4 sw=4: 00100 #endif

Generated on Sun Aug 15 14:14:30 2004 for libtagcoll by doxygen 1.3.8