00001 #ifndef TAGCOLL_INPUTMERGER_H
00002 #define TAGCOLL_INPUTMERGER_H
00003
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00103 #endif