00001 #ifndef DEBTAGS_FILTERS_H 00002 #define DEBTAGS_FILTERS_H 00003 00008 /* 00009 * Copyright (C) 2005 Enrico Zini <enrico@debian.org> 00010 * 00011 * This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program 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 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 */ 00025 #include <debtags/Tag.h> 00026 #include <tagcoll/Consumer.h> 00027 #include <tagcoll/Filter.h> 00028 00029 namespace Debtags 00030 { 00031 00036 template<class ITEM> 00037 class TagToFacet : public Tagcoll::Consumer<ITEM, Tag> 00038 { 00039 protected: 00040 Tagcoll::Consumer<ITEM, Facet>* consumer; 00041 00042 Tagcoll::OpSet<Facet> strip(const Tagcoll::OpSet<Tag>& tags) 00043 { 00044 Tagcoll::OpSet<Debtags::Facet> res; 00045 for (Tagcoll::OpSet<Tag>::const_iterator i = tags.begin(); 00046 i != tags.end(); i++) 00047 res += i->facet(); 00048 return res; 00049 } 00050 00051 virtual void consumeItemUntagged(const ITEM& item) { consumer->consume(item); } 00052 virtual void consumeItem(const ITEM& item, const Tagcoll::OpSet<Debtags::Tag>& tags) 00053 { 00054 consumer->consume(item, strip(tags)); 00055 } 00056 virtual void consumeItemsUntagged(const Tagcoll::OpSet<ITEM>& items) { consumer->consume(items); } 00057 virtual void consumeItems(const Tagcoll::OpSet<ITEM>& items, const Tagcoll::OpSet<Tag>& tags) 00058 { 00059 consumer->consume(items, strip(tags)); 00060 } 00061 00062 public: 00063 TagToFacet() : consumer(0) {} 00064 TagToFacet(Tagcoll::Consumer<ITEM, Facet>& consumer) : consumer(&consumer) {} 00065 00066 Tagcoll::Consumer<ITEM, Facet>& getConsumer() const { return *consumer; } 00067 void setConsumer(Tagcoll::Consumer<ITEM, Facet>& consumer) { this->consumer = &consumer; } 00068 }; 00069 00070 } 00071 00072 // vim:set ts=4 sw=4: 00073 #endif