Consumer.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_CONSUMER_H
00002 #define TAGCOLL_CONSUMER_H
00003 
00008 /*
00009  * Copyright (C) 2003,2004,2005  Enrico Zini <enrico@debian.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Lesser General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2.1 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00024  */
00025 
00026 #include <tagcoll/OpSet.h>
00027 
00028 namespace Tagcoll
00029 {
00030 
00034 template< typename ITEM, typename TAG >
00035 class Consumer
00036 {
00037 protected:
00038     /*
00039      * Implementation note: to avoid problems with classes implementing only
00040      * some of the virtual methods, they are given different names.  The common
00041      * 'comsume' methods are just inlined calls to the right virtual functions,
00042      * and are a way of keeping the unoverridden methods from being hidden.
00043      */
00044     
00046     virtual void consumeItemUntagged(const ITEM& item) = 0;
00047 
00049     virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags) = 0;
00050 
00052     virtual void consumeItemsUntagged(const OpSet<ITEM>& items)
00053     {
00054         // Default implementation for consumer that have no special handling of
00055         // item groups
00056         for (typename OpSet<ITEM>::const_iterator i = items.begin();
00057                 i != items.end(); i++)
00058             consume(*i);
00059     }
00060 
00062     virtual void consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags)
00063     {
00064         // Default implementation for consumer that have no special handling of
00065         // item groups
00066         for (typename OpSet<ITEM>::const_iterator i = items.begin();
00067                 i != items.end(); i++)
00068             consume(*i, tags);
00069     }
00070 
00071 public:
00072     virtual ~Consumer() {}
00073 
00075     void consume(const ITEM& item) { consumeItemUntagged(item); }
00076 
00078     void consume(const ITEM& item, const OpSet<TAG>& tags) { consumeItem(item, tags); }
00079 
00081     void consume(const OpSet<ITEM>& items) { consumeItemsUntagged(items); }
00082 
00084     void consume(const OpSet<ITEM>& items, const OpSet<TAG>& tags) { consumeItems(items, tags); }
00085 };
00086 
00087 
00091 template<class ITEM, class TAG>
00092 class Sink : public Consumer<ITEM, TAG>
00093 {
00094 protected:
00095     virtual void consumeItemUntagged(const ITEM& item) {}
00096     virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags) {}
00097     virtual void consumeItemsUntagged(const OpSet<ITEM>& items) {}
00098     virtual void consumeItems(const OpSet<ITEM>& items, const OpSet<TAG>& tags) {}
00099 public:
00100 };
00101 
00102 };
00103 
00104 // vim:set ts=4 sw=4:
00105 #endif

Generated on Fri Mar 24 22:43:05 2006 for libtagcoll by  doxygen 1.4.6