00001 #ifndef TAGCOLL_ITEM_GROUPER_H 00002 #define TAGCOLL_ITEM_GROUPER_H 00003 00004 /* 00005 * Group items having the same tagset 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/TagcollConsumer.h> 00027 #include <tagcoll/OpSet.h> 00028 00029 #include <map> 00030 #include <string> 00031 00032 namespace Tagcoll 00033 { 00034 00035 template<class ITEM, class TAG> 00036 class ItemGrouper : public TagcollConsumer<ITEM, TAG> 00037 { 00038 protected: 00039 // tagset -> item group 00040 std::map<OpSet<TAG>, OpSet<ITEM> > groups; 00041 00042 public: 00043 virtual ~ItemGrouper() throw () {} 00044 00045 virtual void consume(const ITEM& item) throw () 00046 { 00047 groups[OpSet<TAG>()] += item; 00048 } 00049 00050 virtual void consume(const ITEM& item, const OpSet<TAG>& tags) throw () 00051 { 00052 groups[tags] += item; 00053 } 00054 00055 virtual void consume(const OpSet<ITEM>& items) throw () 00056 { 00057 groups[OpSet<TAG>()] += items; 00058 } 00059 00060 virtual void consume(const OpSet<ITEM>& items, const OpSet<TAG>& tags) throw () 00061 { 00062 groups[tags] += items; 00063 } 00064 00065 // Send the reversed data to a consumer 00066 void output(TagcollConsumer<ITEM, TAG>& consumer) throw (); 00067 }; 00068 00069 }; 00070 00071 // vim:set ts=4 sw=4: 00072 #endif