Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

InputMerger.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_INPUTMERGER_H
00002 #define TAGCOLL_INPUTMERGER_H
00003 
00004 /*
00005  * Merge tags of items appearing multiple times in a stream of tagged items
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/TagcollChange.h>
00028 
00029 #include <map>
00030 
00031 namespace Tagcoll
00032 {
00033 
00034 template<class ITEM>
00035 class PatchList;
00036 
00037 // Merge input values: if an item appears multiple times, merge his various
00038 // tagsets in a single one
00039 template<class T, class Tag>
00040 class InputMerger : public TagcollConsumer<T, Tag>
00041 {
00042 protected:
00043     std::map< T, OpSet<Tag> > coll;
00044     
00045 public:
00046     virtual ~InputMerger<T, Tag>() throw () {}
00047 
00048     virtual void consume(const T& item) throw ();
00049     virtual void consume(const T& item, const OpSet<Tag>& tags) throw ();
00050 
00051     // Return true if the collection contains `item'
00052     bool hasItem(const T& item) const throw () { return coll.find(item) != coll.end(); }
00053 
00054     // Get the tagset of item `item'.  Return an empty set if `item' does not exist
00055     OpSet<Tag> getTagsetForItem(const T& item) const throw ();
00056 
00057     // Send the merged data to a consumer
00058     void output(TagcollConsumer<T, Tag>& consumer) const throw ();
00059 
00060     // Apply a Change to the collection; return a reverse change that can be
00061     // reused to undo the operation
00062     TagcollChange<T, Tag> applyChange(const TagcollChange<T, Tag>& change) throw ();
00063 
00064     // Get the set of all tags in this collection
00065     OpSet<Tag> getAllTags() const throw ();
00066 
00067     // Get the set of all tags in this collection that appear in tagsets
00068     // containing `ts'
00069     OpSet<Tag> getCompanionTags(const OpSet<Tag>& ts) const throw ();
00070 
00071     // Get the related items at the given maximum distance
00072     OpSet<T> getRelatedItems(const T& item, int maxdistance = 1) const throw ();
00073 
00074     // Get the related items at the given maximum distance
00075     OpSet<T> getRelatedItems(const OpSet<Tag>& ts, int maxdistance = 1) const throw ();
00076 
00077     // Get the items whose tagset contains `ts'
00078     OpSet<T> getItemsContaining(const OpSet<Tag>& ts) const throw ();
00079 
00080     friend class PatchList<T>;
00081 };
00082 
00083 };
00084 
00085 // vim:set ts=4 sw=4:
00086 #endif

Generated on Tue Oct 26 19:31:33 2004 for libtagcoll by  doxygen 1.3.9.1