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

Enrico Zini enrico at costa.debian.org
Tue May 2 00:54:56 UTC 2006


Author: enrico
Date: Tue May  2 00:54:56 2006
New Revision: 1685

Added:
   tagcoll/2.0/tagcoll/Patches.tcc
Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/Makefile.am
   tagcoll/2.0/tagcoll/PatchCollection.cc
   tagcoll/2.0/tagcoll/Patches.cc
   tagcoll/2.0/tagcoll/test-utils.cc
Log:
 r2540 at viaza:  enrico | 2006-05-02 02:44:15 +0200
 Moved Patches into a .tcc and use it where it was needed


Modified: tagcoll/2.0/tagcoll/Makefile.am
==============================================================================
--- tagcoll/2.0/tagcoll/Makefile.am	(original)
+++ tagcoll/2.0/tagcoll/Makefile.am	Tue May  2 00:54:56 2006
@@ -20,7 +20,7 @@
 		ReadonlyCollection.h \
 		Collection.h \
 		Patches.h \
-		Patches.cc \
+		Patches.tcc \
 		InputMerger.h \
 		InputMerger.cc \
 		PatchCollection.h \

Modified: tagcoll/2.0/tagcoll/PatchCollection.cc
==============================================================================
--- tagcoll/2.0/tagcoll/PatchCollection.cc	(original)
+++ tagcoll/2.0/tagcoll/PatchCollection.cc	Tue May  2 00:54:56 2006
@@ -263,5 +263,7 @@
 
 }
 
+#include <tagcoll/Patches.tcc>
+
 #endif
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/Patches.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.cc	(original)
+++ tagcoll/2.0/tagcoll/Patches.cc	Tue May  2 00:54:56 2006
@@ -27,135 +27,6 @@
 using namespace std;
 using namespace wibble::operators;
 
-namespace tagcoll {
-
-template <class ITEM, class TAG>
-class PatchGenerator: public Consumer<ITEM, TAG>
-{
-protected:
-	PatchList<ITEM, TAG>& target;
-	const ReadonlyCollection<ITEM, TAG>& second;
-
-	// Process an untagged item
-	virtual void consumeItemUntagged(const ITEM& item)
-	{
-		std::set<TAG> ts2 = second.getTags(item);
-		if (!ts2.empty())
-			target.addPatch(Patch<ITEM, TAG>(item, ts2, std::set<TAG>()));
-	}
-
-	// Process a tagged item, with its tags
-	virtual void consumeItem(const ITEM& item, const std::set<TAG>& ts1)
-	{
-		std::set<TAG> ts2 = second.getTags(item);
-		std::set<TAG> added = ts2 - ts1;
-		std::set<TAG> removed = ts1 - ts2;
-		if (!added.empty() || !removed.empty())
-			target.addPatch(Patch<ITEM, TAG>(item, added, removed));
-	}
-public:
-	PatchGenerator(PatchList<ITEM, TAG>& target, const ReadonlyCollection<ITEM, TAG>& second) throw ()
-		: target(target), second(second) {}
-};
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::addPatch(const Patch<ITEM, TAG>& patch) throw ()
-{
-	// Filter out empty patches
-	if (patch.getAdded().empty() && patch.getRemoved().empty())
-		return;
-
-	iterator i = this->find(patch.getItem());
-	if (i == this->end())
-		insert(make_pair<ITEM, Patch<ITEM, TAG> >(patch.getItem(), patch));
-	else
-		i->second.mergeWith(patch);
-}
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::addPatch(const PatchList<ITEM, TAG>& patches) throw ()
-{
-	for (typename PatchList<ITEM, TAG>::const_iterator i = patches.begin();
-			i != patches.end(); i++)
-		addPatch(i->second);
-}
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::addPatch(
-		const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2) throw ()
-{
-	PatchGenerator<ITEM, TAG> patchgen(*this, im2);
-	im1.output(patchgen);
-}
-
-template <class ITEM, class TAG>
-std::set<TAG> PatchList<ITEM, TAG>::patch(const ITEM& item, const std::set<TAG>& tagset) const throw ()
-{
-	// Find the patch record for this item
-	const_iterator p = this->find(item);
-	if (p == this->end())
-		// If there are no patches, return the tagset unchanged
-		return tagset;
-
-	// There are patches: apply them:
-	return p->second.apply(tagset);
-}
-
-template <class ITEM, class TAG>
-PatchList<ITEM, TAG> PatchList<ITEM, TAG>::getReverse() const throw ()
-{
-	PatchList<ITEM, TAG> res;
-	for (typename PatchList<ITEM, TAG>::const_iterator i = this->begin();
-			i != this->end(); i++)
-		res.addPatch(i->second.getReverse());
-	return res;
-}
-
-
-/*
-template <class ITEM>
-void PatchList<ITEM>::consume(const ITEM& item, const std::set<string>& tags) throw ()
-{
-	patches.insert(make_pair(item, tags));
-}
-
-// Output the patch list to a TagcollConsumer
-template <class ITEM>
-void PatchList<ITEM>::output(TagcollConsumer<ITEM, std::string>& consumer) const throw ()
-{
-	for (typename map< ITEM, std::set<string> >::const_iterator i = patches.begin();
-			i != patches.end(); i++)
-		if (i->second.size() == 0)
-			consumer.consume(i->first);
-		else
-			consumer.consume(i->first, i->second);
-}
-*/
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::consumeItemUntagged(const ITEM& item)
-{
-	std::set<TAG> patched = patch(item, std::set<TAG>());
-
-	if (patched.size())
-		this->consumer->consume(item, patched);
-	else
-		this->consumer->consume(item);
-}
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::consumeItem(const ITEM& item, const std::set<TAG>& tags)
-{
-	std::set<TAG> patched = patch(item, tags);
-
-	if (patched.size())
-		this->consumer->consume(item, patched);
-	else
-		this->consumer->consume(item);
-}
-
-}
-
 #ifdef COMPILE_TESTSUITE
 
 #include <tests/test-utils.h>
@@ -212,5 +83,7 @@
 
 }
 
+#include <tagcoll/Patches.tcc>
+
 #endif
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/test-utils.cc
==============================================================================
--- tagcoll/2.0/tagcoll/test-utils.cc	(original)
+++ tagcoll/2.0/tagcoll/test-utils.cc	Tue May  2 00:54:56 2006
@@ -34,11 +34,13 @@
 #include <tagcoll/TextFormat.h>
 #include <tagcoll/InputMerger.h>
 #include <tagcoll/Patches.h>
+#include <wibble/operators.h>
 
 namespace tut_tagcoll {
 
 using namespace std;
 using namespace tagcoll;
+using namespace wibble::operators;
 using namespace tut;
 	
 void _gen_ensure(const Location& loc, bool res)
@@ -67,7 +69,7 @@
 			f += i->first;
 			f += ": ";
 			bool first = true;
-			for (OpSet<string>::const_iterator j = i->second.getAdded().begin();
+			for (std::set<string>::const_iterator j = i->second.getAdded().begin();
 					j != i->second.getAdded().end(); j++)
 				if (first)
 				{
@@ -76,7 +78,7 @@
 				} else {
 					f += ", +" + *j;
 				}
-			for (OpSet<string>::const_iterator j = i->second.getRemoved().begin();
+			for (std::set<string>::const_iterator j = i->second.getRemoved().begin();
 					j != i->second.getRemoved().end(); j++)
 				if (first)
 				{
@@ -94,25 +96,25 @@
 
 void __output_test_collection(const Location& loc, Consumer<string, string>& tc)
 {
-	OpSet<string> tagset;
+	std::set<string> tagset;
 
 	tagset.clear();
 	tc.consume("gnocco");
 
 	tagset.clear();
-	tagset += "tomato"; tagset += "mozzarella";
+	tagset.insert("tomato"); tagset.insert("mozzarella");
 	tc.consume("margherita", tagset);
 
 	tagset.clear();
-	tagset += "tomato"; tagset += "mozzarella"; tagset += "mushrooms";
+	tagset.insert("tomato"); tagset.insert("mozzarella"); tagset.insert("mushrooms");
 	tc.consume("funghi", tagset);
 
 	tagset.clear();
-	tagset += "garlic"; tagset += "rosemerry";
+	tagset.insert("garlic"); tagset.insert("rosemerry");
 	tc.consume("rosmarino", tagset);
 
 	tagset.clear();
-	tagset += "garlic"; tagset += "tomato";
+	tagset.insert("garlic"); tagset.insert("tomato");
 	tc.consume("marinara", tagset);
 }
 
@@ -252,18 +254,18 @@
 	inner_ensure_not_contains(s, string("rosmarino"));
 	inner_ensure_not_contains(s, string("marinara"));
 
-	// TODO:    virtual OpSet<ITEM> getTaggedItems() const = 0;
-	// TODO:    virtual OpSet<TAG> getAllTags() const = 0;
+	// TODO:    virtual std::set<ITEM> getTaggedItems() const = 0;
+	// TODO:    virtual std::set<TAG> getAllTags() const = 0;
 	// TODO:    virtual int getCardinality(const TAG& tag) const
-	// TODO:    virtual OpSet<TAG> getCompanionTags(const OpSet<TAG>& tags) const
-	// TODO:    virtual OpSet<ITEM> getRelatedItems(const OpSet<TAG>& tags, int maxdistance = 1) const
+	// TODO:    virtual std::set<TAG> getCompanionTags(const std::set<TAG>& tags) const
+	// TODO:    virtual std::set<ITEM> getRelatedItems(const std::set<TAG>& tags, int maxdistance = 1) const
 
 	// void output(Consumer<ITEM, TAG>& consumer) const
 	InputMerger<string, string> coll1;
 	tc.output(coll1);
 	inner_ensure_coll_equals(tc, coll1);
 
-	// TODO:    virtual void outputHavingTags(const OpSet<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
+	// TODO:    virtual void outputHavingTags(const std::set<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
 }
 
 void __test_collection(const Location& loc, Collection<string, string>& tc)
@@ -423,6 +425,7 @@
 }
 
 #include <tagcoll/TextFormat.tcc>
+#include <tagcoll/Patches.tcc>
 
 #endif
 



More information about the Debtags-commits mailing list