InputMerger.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_INPUTMERGER_H
00002 #define TAGCOLL_INPUTMERGER_H
00003 
00011 /*
00012  * Copyright (C) 2003,2004,2005  Enrico Zini <enrico@debian.org>
00013  *
00014  * This library is free software; you can redistribute it and/or
00015  * modify it under the terms of the GNU Lesser General Public
00016  * License as published by the Free Software Foundation; either
00017  * version 2.1 of the License, or (at your option) any later version.
00018  *
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00027  */
00028 
00029 #include <tagcoll/Collection.h>
00030 
00031 #include <map>
00032 
00033 namespace Tagcoll
00034 {
00035 template<typename T1, typename T2> class PatchList;
00036 
00045 template<class ITEM, class TAG>
00046 class InputMerger : public Collection<ITEM, TAG>
00047 {
00048 protected:
00049     std::map< ITEM, OpSet<TAG> > coll;
00050     
00051     virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags);
00052 
00053     virtual OpSet<TAG> getTagsOfItem(const ITEM& item) const;
00054     virtual OpSet<ITEM> getItemsHavingTag(const TAG& tag) const;
00055     virtual OpSet<ITEM> getItemsHavingTags(const OpSet<TAG>& tags) const;
00056 
00057 
00058 public:
00059     virtual ~InputMerger<ITEM, TAG>() {}
00060 
00061     bool hasItem(const ITEM& item) const { return coll.find(item) != coll.end(); }
00062 
00063     void output(Consumer<ITEM, TAG>& consumer) const;
00064     void outputHavingTags(const OpSet<TAG>& ts, Consumer<ITEM, TAG>& consumer) const;
00065 
00070     void outputReversed(Consumer<TAG, ITEM>& consumer) const;
00071 
00072     void applyChange(const PatchList<ITEM, TAG>& change);
00073 
00074     virtual OpSet<ITEM> getTaggedItems() const
00075     {
00076         OpSet<ITEM> res;
00077         for (typename std::map< ITEM, OpSet<TAG> >::const_iterator i = coll.begin();
00078                 i != coll.end(); i++)
00079             res += i->first;
00080         return res;
00081     }
00082     
00083     OpSet<TAG> getAllTags() const;
00084 
00085     OpSet<TAG> getCompanionTags(const OpSet<TAG>& ts) const;
00086 
00087     OpSet<ITEM> getRelatedItems(const OpSet<TAG>& ts, int maxdistance = 1) const;
00088 
00092     unsigned int itemCount() const;
00093 
00097     void clear();
00098 };
00099 
00100 };
00101 
00102 // vim:set ts=4 sw=4:
00103 #endif

Generated on Tue Aug 21 13:07:09 2007 for libtagcoll by  doxygen 1.5.3