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

Consumer.h

Go to the documentation of this file.
00001 #ifndef CONSUMER_H
00002 #define CONSUMER_H
00003 
00004 /*
00005  * 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 template<class ITEM>
00027 class Consumer
00028 {
00029 public:
00030     virtual void consume(ITEM&) = 0;
00031 };
00032 
00033 template<class ITEM>
00034 class Matcher
00035 {
00036 public:
00037     virtual bool match(ITEM& item) const
00038     {
00039         return true;
00040     }
00041 };
00042 
00043 template<class ITEM>
00044 class Filter : public Consumer<ITEM>
00045 {
00046 protected:
00047     Consumer<ITEM>& next;
00048 public:
00049     Filter<ITEM>(Consumer<ITEM>& next) : next(next) {}
00050 
00051     virtual void consume(ITEM& item)
00052     {
00053         next.consume(item);
00054     }
00055 };
00056 
00057 template<class ITEM>
00058 class MatcherFilter : public Filter<ITEM>
00059 {
00060 protected:
00061     Matcher<ITEM>& matcher;
00062 
00063 public:
00064     MatcherFilter<ITEM>(Matcher<ITEM>& matcher, Consumer<ITEM>& next) throw ()
00065         : Filter<ITEM>(next), matcher(matcher) {}
00066 
00067     virtual void consume(ITEM& item)
00068     {
00069         if (matcher.match(item))
00070             this->next.consume(item);
00071     }
00072 };
00073 
00074 // vim:set ts=4 sw=4:
00075 #endif

Generated on Wed Mar 23 12:37:00 2005 for libbuffy by  doxygen 1.4.0