00001 #ifndef CONSUMER_H
00002 #define CONSUMER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 namespace buffy {
00025
00026 template<class ITEM>
00027 class Consumer
00028 {
00029 public:
00030 virtual ~Consumer() {}
00031 virtual void consume(ITEM&) = 0;
00032 };
00033
00034 template<class ITEM>
00035 class Matcher
00036 {
00037 public:
00038 virtual ~Matcher() {}
00039 virtual bool match(ITEM& item) const
00040 {
00041 return true;
00042 }
00043 };
00044
00045 template<class ITEM>
00046 class Filter : public Consumer<ITEM>
00047 {
00048 protected:
00049 Consumer<ITEM>& next;
00050 public:
00051 Filter<ITEM>(Consumer<ITEM>& next) : next(next) {}
00052
00053 virtual void consume(ITEM& item)
00054 {
00055 next.consume(item);
00056 }
00057 };
00058
00059 template<class ITEM>
00060 class MatcherFilter : public Filter<ITEM>
00061 {
00062 protected:
00063 Matcher<ITEM>& matcher;
00064
00065 public:
00066 MatcherFilter<ITEM>(Matcher<ITEM>& matcher, Consumer<ITEM>& next) throw ()
00067 : Filter<ITEM>(next), matcher(matcher) {}
00068
00069 virtual void consume(ITEM& item)
00070 {
00071 if (matcher.match(item))
00072 this->next.consume(item);
00073 }
00074 };
00075
00076 }
00077
00078
00079 #endif