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

TagConsumer.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_TAGCONSUMER_H 00002 #define TAGCOLL_TAGCONSUMER_H 00003 00004 /* 00005 * Package stream consumer and filter interfaces 00006 * 00007 * Copyright (C) 2003 Enrico Zini <enrico@debian.org> 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program 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 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; 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 namespace Tagcoll 00027 { 00028 00029 template<class ITEM> 00030 class Consumer 00031 { 00032 public: 00033 virtual void consume(const ITEM&) throw () = 0; 00034 }; 00035 00036 template<class ITEM> 00037 class Matcher 00038 { 00039 public: 00040 virtual bool match(const ITEM& item) const throw () 00041 { 00042 return true; 00043 } 00044 }; 00045 00046 template<class ITEM> 00047 class Filter : public Consumer<ITEM> 00048 { 00049 protected: 00050 Consumer<ITEM>& next; 00051 public: 00052 Filter<ITEM>(Consumer<ITEM>& next) throw () : next(next) {} 00053 00054 virtual void consume(const ITEM& item) throw () 00055 { 00056 next.consume(item); 00057 } 00058 }; 00059 00060 template<class ITEM> 00061 class MatcherFilter : public Filter<ITEM> 00062 { 00063 protected: 00064 Matcher<ITEM>& matcher; 00065 00066 public: 00067 MatcherFilter<ITEM>(Matcher<ITEM>& matcher, Consumer<ITEM>& next) throw () 00068 : Filter<ITEM>(next), matcher(matcher) {} 00069 00070 virtual void consume(const ITEM& item) throw () 00071 { 00072 if (matcher.match(item)) 00073 next.consume(item); 00074 } 00075 }; 00076 00077 00078 class Facet; 00079 class Tag; 00080 00081 class FacetConsumer : public Consumer<Facet> {}; 00082 class TagConsumer : public Consumer<Tag> {}; 00083 00084 class FacetMatcher : public Matcher<Facet> {}; 00085 class TagMatcher : public Matcher<Tag> {}; 00086 00087 class FacetFilter : public Filter<Facet> 00088 { 00089 public: 00090 FacetFilter(FacetConsumer& next) throw () : Filter<Facet>(next) {} 00091 }; 00092 class TagFilter : public Filter<Tag> 00093 { 00094 public: 00095 TagFilter(TagConsumer& next) throw () : Filter<Tag>(next) {} 00096 }; 00097 00098 class FacetMatcherFilter : public MatcherFilter<Facet> 00099 { 00100 public: 00101 FacetMatcherFilter(FacetMatcher& matcher, FacetConsumer& next) throw () 00102 : MatcherFilter<Facet>(matcher, next) {} 00103 }; 00104 00105 class TagMatcherFilter : public MatcherFilter<Tag> 00106 { 00107 public: 00108 TagMatcherFilter(TagMatcher& matcher, TagConsumer& next) throw () 00109 : MatcherFilter<Tag>(matcher, next) {} 00110 }; 00111 00112 }; 00113 00114 // vim:set ts=4 sw=4: 00115 #endif

Generated on Sun Aug 15 13:57:13 2004 for libtagcoll by doxygen 1.3.8