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

Enrico Zini enrico at costa.debian.org
Sat May 6 08:42:35 UTC 2006


Author: enrico
Date: Sat May  6 08:42:34 2006
New Revision: 1706

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/DerivedTags.cc
   tagcoll/2.0/tagcoll/DerivedTags.h
Log:
 r2592 at viaza:  enrico | 2006-05-06 00:42:04 +0200
 Ported DerivedTags to the new architecture


Modified: tagcoll/2.0/tagcoll/DerivedTags.cc
==============================================================================
--- tagcoll/2.0/tagcoll/DerivedTags.cc	(original)
+++ tagcoll/2.0/tagcoll/DerivedTags.cc	Sat May  6 08:42:34 2006
@@ -64,12 +64,12 @@
 			"d: coffee, milk, sugar, sweet_cappuccino\n"
 			);
 	InputMerger<string, string> result;
-	AddDerived<string> filter(result);
+	DerivedTags derivations;
 
-	filter.derivedTags().add("cappuccino", Expression("coffee && milk && !sugar"));
-	filter.derivedTags().add("sweet_cappuccino", Expression("coffee && milk && sugar"));
+	derivations.add("cappuccino", Expression("coffee && milk && !sugar"));
+	derivations.add("sweet_cappuccino", Expression("coffee && milk && sugar"));
 
-	outputCollection(input_coll, filter); 
+	parseCollection(input_coll, addDerived(derivations, consumer(result)));
 
 	InputMerger<string, string> reference;
 	outputCollection(output_coll, reference); 
@@ -93,12 +93,12 @@
 			"d: coffee, milk, sugar\n"
 			);
 	InputMerger<string, string> result;
-	RemoveDerived<string> filter(result);
+	DerivedTags derivations;
 
-	filter.derivedTags().add("cappuccino", Expression("coffee && milk && !sugar"));
-	filter.derivedTags().add("sweet_cappuccino", Expression("coffee && milk && sugar"));
+	derivations.add("cappuccino", Expression("coffee && milk && !sugar"));
+	derivations.add("sweet_cappuccino", Expression("coffee && milk && sugar"));
 
-	outputCollection(input_coll, filter); 
+	parseCollection(input_coll, removeDerived(derivations, consumer(result)));
 
 	InputMerger<string, string> reference;
 	outputCollection(output_coll, reference); 
@@ -108,6 +108,8 @@
 
 }
 
+#include <tagcoll/TextFormat.tcc>
+
 #endif
 
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/DerivedTags.h
==============================================================================
--- tagcoll/2.0/tagcoll/DerivedTags.h	(original)
+++ tagcoll/2.0/tagcoll/DerivedTags.h	Sat May  6 08:42:34 2006
@@ -24,10 +24,10 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
 
-#include <tagcoll/Filter.h>
 #include <tagcoll/Expression.h>
 
 #include <wibble/operators.h>
+#include <wibble/mixin.h>
 #include <map>
 #include <string>
 
@@ -58,113 +58,104 @@
 	 */
 	std::set<std::string> derivedTags(const std::set<std::string>& tags) const
 	{
-		using namespace wibble::operators;
 		std::set<std::string> res;
 		for (const_iterator i = begin(); i != end(); i++)
 		{
 			TagexprContext context(tags, *this);
 			if (i->second(context))
-				res |= i->first;
+				res.insert(i->first);
 		}
 		return res;
+	}
+
+	template<typename TAGS>
+	std::set<std::string> derivedTags(const TAGS& tags) const
+	{
+		std::set<std::string> tagset;
+		for (typename TAGS::const_iterator i = tags.begin();
+				i != tags.end(); ++i)
+			tagset.insert(*i);
 
+		std::set<std::string> res;
+		for (const_iterator i = begin(); i != end(); i++)
+		{
+			TagexprContext context(tagset, *this);
+			if (i->second(context))
+				res.insert(i->first);
+		}
+		return res;
 	}
 };
 
 /**
  * Filter that adds derived tags to a collection
  */
-template <class ITEM>
-class AddDerived : public Filter<ITEM, std::string>
+template <typename OUT>
+class AddDerived : public wibble::mixin::OutputIterator< AddDerived<OUT> >
 {
 protected:
-	DerivedTags dtags;
+	const DerivedTags& dtags;
+	OUT out;
 
-	virtual void consumeItemUntagged(const ITEM& item)
-	{
-		this->consumer->consume(item, dtags.derivedTags(std::set<std::string>()));
-	}
-	virtual void consumeItem(const ITEM& item, const std::set<std::string>& tags)
-	{
-		using namespace wibble::operators;
-		this->consumer->consume(item, tags | dtags.derivedTags(tags));
-	}
-	virtual void consumeItemsUntagged(const std::set<ITEM>& items)
-	{
-		this->consumer->consume(items, dtags.derivedTags(std::set<std::string>()));
-	}
-	virtual void consumeItems(const std::set<ITEM>& items, const std::set<std::string>& tags)
+public:
+	AddDerived(const DerivedTags& dtags, const OUT& out)
+		: dtags(dtags), out(out) {}
+
+	template<typename ITEMS, typename TAGS>
+	AddDerived<OUT>& operator=(const std::pair<ITEMS, TAGS>& data)
 	{
 		using namespace wibble::operators;
-		this->consumer->consume(items, tags | dtags.derivedTags(tags));
+		std::set<typename TAGS::value_type> newts;
+		for (typename TAGS::const_iterator i = data.second.begin();
+				i != data.second.end(); ++i)
+			newts.insert(*i);
+		newts |= dtags.derivedTags(data.second);
+		*out = make_pair(data.first, newts);
+		++out;
+		return *this;
 	}
-	
-public:
-	AddDerived() {}
-	AddDerived(Consumer<ITEM, std::string>& cons) : Filter<ITEM, std::string>(cons) {}
-	AddDerived(const DerivedTags& dtags) : dtags(dtags) {}
-	AddDerived(Consumer<ITEM, std::string>& cons, const DerivedTags& dtags)
-		: Filter<ITEM, std::string>(cons), dtags(dtags) {}
-	virtual ~AddDerived() {}
-
-	/**
-	 * Access the internal DerivedTags table
-	 */
-	DerivedTags& derivedTags() { return dtags; }
-
-	/**
-	 * Access the internal DerivedTags table (const version)
-	 */
-	const DerivedTags& derivedTags() const { return dtags; }
 };
 
+template<class OUT>
+AddDerived<OUT> addDerived(const DerivedTags& dtags, const OUT& out)
+{
+	return AddDerived<OUT>(dtags, out);
+}
+
 /**
  * Filter that removes redundant derived tags from a collection
  */
-template <class ITEM>
-class RemoveDerived : public Filter<ITEM, std::string>
+template <typename OUT>
+class RemoveDerived : public wibble::mixin::OutputIterator< RemoveDerived<OUT> >
 {
 protected:
 	DerivedTags dtags;
+	OUT out;
 
-	virtual void consumeItemUntagged(const ITEM& item)
-	{
-		this->consumer->consume(item);
-	}
-	virtual void consumeItem(const ITEM& item, const std::set<std::string>& tags)
-	{
-		using namespace wibble::operators;
-		this->consumer->consume(item, tags - dtags.derivedTags(tags));
-	}
-	virtual void consumeItemsUntagged(const std::set<ITEM>& items)
-	{
-		this->consumer->consume(items);
-	}
-	virtual void consumeItems(const std::set<ITEM>& items, const std::set<std::string>& tags)
+public:
+	RemoveDerived(const DerivedTags& dtags, const OUT& out)
+		: dtags(dtags), out(out) {}
+
+	template<typename ITEM, typename TAGS>
+	RemoveDerived<OUT>& operator=(const std::pair<ITEM, TAGS>& data)
 	{
 		using namespace wibble::operators;
-		this->consumer->consume(items, tags - dtags.derivedTags(tags));
+		std::set<typename TAGS::value_type> newts;
+		for (typename TAGS::const_iterator i = data.second.begin();
+				i != data.second.end(); ++i)
+			newts.insert(*i);
+		*out = make_pair(data.first, newts - dtags.derivedTags(data.second));
+		++out;
+		return *this;
 	}
-
-public:
-	RemoveDerived() {}
-	RemoveDerived(Consumer<ITEM, std::string>& cons) : Filter<ITEM, std::string>(cons) {}
-	RemoveDerived(const DerivedTags& dtags) : dtags(dtags) {}
-	RemoveDerived(Consumer<ITEM, std::string>& cons, const DerivedTags& dtags)
-		: Filter<ITEM, std::string>(cons), dtags(dtags) {}
-	virtual ~RemoveDerived() {}
-
-	/**
-	 * Access the internal DerivedTags table
-	 */
-	DerivedTags& derivedTags() { return dtags; }
-
-	/**
-	 * Access the internal DerivedTags table (const version)
-	 */
-	const DerivedTags& derivedTags() const { return dtags; }
 };
 
+template<class OUT>
+RemoveDerived<OUT> removeDerived(const DerivedTags& dtags, const OUT& out)
+{
+	return RemoveDerived<OUT>(dtags, out);
+}
+
 };
 
 // vim:set ts=4 sw=4:



More information about the Debtags-commits mailing list