[Debtags-commits] [svn] r1700 - in tagcoll/2.0: . tagcoll

Enrico Zini enrico at costa.debian.org
Fri May 5 08:25:46 UTC 2006


Author: enrico
Date: Fri May  5 08:25:45 2006
New Revision: 1700

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/PatchCollection.cc
   tagcoll/2.0/tagcoll/Patches.h
   tagcoll/2.0/tagcoll/ReadonlyCollection.h
Log:
 r2580 at viaza:  enrico | 2006-05-05 10:24:02 +0200
 Started removing all Filter references from PatchCollection


Modified: tagcoll/2.0/tagcoll/PatchCollection.cc
==============================================================================
--- tagcoll/2.0/tagcoll/PatchCollection.cc	(original)
+++ tagcoll/2.0/tagcoll/PatchCollection.cc	Fri May  5 08:25:45 2006
@@ -18,9 +18,11 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <tagcoll/Consumer.h>
 #include <tagcoll/PatchCollection.h>
 
 #include <wibble/operators.h>
+#include <wibble/mixin.h>
 
 using namespace std;
 using namespace wibble::operators;
@@ -153,36 +155,47 @@
 	return res;
 }
 
-template<class ITEM, class TAG>
-class NoPatched : public tagcoll::Filter<ITEM, TAG>
+template<typename ITEM, typename TAG, typename OUT>
+class UnpatchedOnly : wibble::mixin::OutputIterator< UnpatchedOnly<ITEM, TAG, OUT> >
 {
 protected:
+	OUT out;
 	const PatchList<ITEM, TAG>& changes;
 
-	virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
+public:	
+	UnpatchedOnly(const PatchList<ITEM, TAG>& changes, const OUT& out) : out(out), changes(changes) {}
+
+	UnpatchedOnly<ITEM, TAG, OUT>& operator++() { return *this; }
+	
+	template<typename Items, typename Tags>
+	UnpatchedOnly<ITEM, TAG, OUT>& operator=(const std::pair<Items, Tags>& data)
 	{
-		if (changes.find(item) == changes.end())
-			this->consumer->consume(item, tags);
+		for (typename Items::const_iterator i = data.first.begin();
+				i != data.first.end(); ++i)
+			if (changes.find(*i) == changes.end())
+			{
+				*out = data;
+				++out;
+			}
 	}
-
-public:	
-	NoPatched(const PatchList<ITEM, TAG>& changes) : changes(changes) {}
-	NoPatched(const PatchList<ITEM, TAG>& changes, tagcoll::Consumer<ITEM, TAG>& cons)
-		: tagcoll::Filter<ITEM, TAG>(cons), changes(changes) {}
 };
 
+template<typename ITEM, typename TAG, typename OUT>
+UnpatchedOnly<ITEM, TAG, OUT> unpatchedOnly(const PatchList<ITEM, TAG>& changes, const OUT& out)
+{
+	return UnpatchedOnly<ITEM, TAG, OUT>(changes, out);
+}
+
 template<class ITEM, class TAG>
-void PatchCollection<ITEM, TAG>::output(Consumer<ITEM, TAG>& consumer) const
+void PatchCollection<ITEM, TAG>::output(Consumer<ITEM, TAG>& cons) const
 {
 	// First, only pass the unpatched items
-	NoPatched<ITEM, TAG> onlyUnpatched(changes);
-	onlyUnpatched.setConsumer(consumer);
-	coll.output(onlyUnpatched);
+	coll.outputToIterator(unpatchedOnly(changes, consumer(cons)));
 
 	// Then output the items in the patch
 	for (typename PatchList<ITEM, TAG>::const_iterator i = changes.begin();
 			i != changes.end(); i++)
-		consumer.consume(i->first,
+		cons.consume(i->first,
 				changes.patch(i->first, coll.getTags(i->first)));
 }
 

Modified: tagcoll/2.0/tagcoll/Patches.h
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.h	(original)
+++ tagcoll/2.0/tagcoll/Patches.h	Fri May  5 08:25:45 2006
@@ -23,8 +23,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
 
-#include <tagcoll/Consumer.h>
-#include <tagcoll/Filter.h>
 #include <tagcoll/Collection.h>
 
 #include <wibble/operators.h>

Modified: tagcoll/2.0/tagcoll/ReadonlyCollection.h
==============================================================================
--- tagcoll/2.0/tagcoll/ReadonlyCollection.h	(original)
+++ tagcoll/2.0/tagcoll/ReadonlyCollection.h	Fri May  5 08:25:45 2006
@@ -38,6 +38,43 @@
 template<typename ITEM, typename TAG>
 class ReadonlyCollection
 {
+	template<typename OUT>
+	class Forwarder : Consumer<ITEM, TAG>
+	{
+		OUT out;
+
+		virtual void consumeItemUntagged(const ITEM& item)
+		{
+			*out = std::make_pair(wibble::Singleton<ITEM>(item), wibble::Empty<TAG>());
+			++out;
+		}
+
+		/// Process a tagged item, with its tags
+		virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
+		{
+			*out = std::make_pair(wibble::Singleton<ITEM>(item), tags);
+			++out;
+		}
+
+		/// Process a set of items, all with no tags
+		virtual void consumeItemsUntagged(const std::set<ITEM>& items)
+		{
+			*out = std::make_pair(items, wibble::Empty<TAG>());
+			++out;
+		}
+
+		/// Process a set of items identically tagged, with their tags
+		virtual void consumeItems(const std::set<ITEM>& items, const std::set<TAG>& tags)
+		{
+			*out = std::make_pair(items, tags);
+			++out;
+		}
+
+	public:
+		Forwarder(const OUT& out) : out(out) {}
+		virtual ~Forwarder() {}
+	};
+
 protected:
 	/**
 	 * Get the items which are tagged with at least the tag `tag'
@@ -230,6 +267,12 @@
 	 */
 	virtual void output(Consumer<ITEM, TAG>& consumer) const = 0;
 
+	template<typename OUT>
+	void outputToIterator(OUT& cons) const
+	{
+		output(Forwarder<OUT>(cons));
+	}
+
 	/**
 	 * Send to a consumer all the items which are tagged with at least the
 	 * given tags



More information about the Debtags-commits mailing list