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

Enrico Zini enrico at costa.debian.org
Tue May 9 00:44:37 UTC 2006


Author: enrico
Date: Tue May  9 00:44:36 2006
New Revision: 1734

Added:
   tagcoll/2.0/tagcoll/stream/substitutions.cc
   tagcoll/2.0/tagcoll/stream/substitutions.h
Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/Makefile.am
   tagcoll/2.0/tagcoll/stream/filters.cc
   tagcoll/2.0/tagcoll/stream/filters.h
Log:
 r2621 at viaza:  enrico | 2006-05-08 12:59:32 -0500
 Split substitutions out of filters


Modified: tagcoll/2.0/tagcoll/Makefile.am
==============================================================================
--- tagcoll/2.0/tagcoll/Makefile.am	(original)
+++ tagcoll/2.0/tagcoll/Makefile.am	Tue May  9 00:44:36 2006
@@ -15,6 +15,7 @@
 		stream/sink.h \
 		stream/filters.h \
 		stream/expression.h \
+		stream/substitutions.h \
 		Consumer.h \
 		ReadonlyCollection.h \
 		Collection.h \
@@ -62,6 +63,7 @@
 		stream/sink.cc \
 		stream/filters.cc \
 		stream/expression.cc \
+		stream/substitutions.cc \
 		Consumer.cc \
 		Patches.cc \
 		InputMerger.cc \

Modified: tagcoll/2.0/tagcoll/stream/filters.cc
==============================================================================
--- tagcoll/2.0/tagcoll/stream/filters.cc	(original)
+++ tagcoll/2.0/tagcoll/stream/filters.cc	Tue May  9 00:44:36 2006
@@ -42,37 +42,6 @@
 void to::test<1>()
 {
 	std::string input_coll(
-			"a: b, c\n"
-			"b:\n"
-			"c: \n"
-			"d:  c::D, e::F,    f::g\n"
-			);
-	std::string input_subst(
-			"b: c\n"
-			"c::D: e::F\n"
-			);
-	std::string output_coll(
-			"a: b\n"
-			"b:\n"
-			"c: \n"
-			"d:  c::D,    f::g\n"
-			);
-	InputMerger<string, string> result;
-	Substitutions<string> changes;
-
-	parseCollection(input_subst, changes.inserter());
-	parseCollection(input_coll, substitute(changes, inserter(result))); 
-
-	InputMerger<string, string> reference;
-	parseCollection(output_coll, inserter(reference));
-
-	ensure_coll_equals(reference, result);
-}
-
-template<> template<>
-void to::test<2>()
-{
-	std::string input_coll(
 			"a: \n"
 			"b: c::D, e::F, f::g\n"
 			"c: c::D, e, f::g\n"
@@ -91,7 +60,7 @@
 }
 
 template<> template<>
-void to::test<3>()
+void to::test<2>()
 {
 	std::string input_coll(
 			"a: \n"
@@ -111,7 +80,7 @@
 }
 
 template<> template<>
-void to::test<4>()
+void to::test<3>()
 {
 	std::string input_coll(
 			"a: b, c, d::e\n"
@@ -133,7 +102,7 @@
 }
 
 template<> template<>
-void to::test<5>()
+void to::test<4>()
 {
 	std::string input_coll(
 			"a: b, c, d---e\n"
@@ -155,7 +124,7 @@
 }
 
 template<> template<>
-void to::test<6>()
+void to::test<5>()
 {
 	std::string input_coll(
 			"a: b, c, d::e\n"
@@ -177,7 +146,7 @@
 }
 
 template<> template<>
-void to::test<7>()
+void to::test<6>()
 {
 	std::string input_coll(
 			"a: 1, 2\n"
@@ -200,7 +169,7 @@
 }
 
 template<> template<>
-void to::test<8>()
+void to::test<7>()
 {
 	std::string input_coll(
 			"a: 1, 2\n"

Modified: tagcoll/2.0/tagcoll/stream/filters.h
==============================================================================
--- tagcoll/2.0/tagcoll/stream/filters.h	(original)
+++ tagcoll/2.0/tagcoll/stream/filters.h	Tue May  9 00:44:36 2006
@@ -6,7 +6,7 @@
  */
 
 /*
- * Copyright (C) 2003,2004,2005  Enrico Zini <enrico at debian.org>
+ * Copyright (C) 2003,2004,2005,2006  Enrico Zini <enrico at debian.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -89,124 +89,6 @@
 }
 
 /**
- * Store a list of substitutions to operate on std::set
- *
- * It uses a Consumer interface to allow to be populated using a decoder for
- * collections such as TextFormat.
- */
-template<typename T>
-class Substitutions
-{
-protected:
-	typedef std::map<T, T> changes_t;
-	changes_t changes;
-
-public:
-	template<typename IT>
-	class SubstitutionsInserter : public wibble::mixin::OutputIterator< SubstitutionsInserter<IT> >
-	{
-		Substitutions<IT>& out;
-
-	public:
-		SubstitutionsInserter(Substitutions<IT>& out)
-			: out(out) {}
-
-		template<typename NewItems, typename OldItems>
-		SubstitutionsInserter& operator=(const std::pair<NewItems, OldItems>& data)
-		{
-			for (typename NewItems::const_iterator i = data.first.begin();
-					i != data.first.end(); ++i)
-				for (typename OldItems::const_iterator j = data.second.begin();
-						j != data.second.end(); ++j)
-					out.add(*j, *i);
-			return *this;
-		}
-	};
-
-	/// Change all the items in a set
-	template<typename Items>
-	std::set<T> change(const Items& values) const
-	{
-		std::set<T> res;
-		for (typename Items::const_iterator t = values.begin();
-				t != values.end(); ++t)
-			res.insert(change(*t));
-		return res;
-	}
-
-	/// Change a single value
-	T change(const T& v) const
-	{
-		typename changes_t::const_iterator i = changes.find(v);
-
-		return (i == changes.end()) ? v : i->second;
-	}
-
-	/// Add one substitution to the list
-	void add(const T& oldItem, const T& newItem)
-	{
-		changes.insert(make_pair(oldItem, newItem));
-	}
-
-	/// Create an inserter for this class
-	SubstitutionsInserter<T> inserter()
-	{
-		return SubstitutionsInserter<T>(*this);
-	}
-};
-
-/**
- * Filter replacing tags according to a list of Substitutions
- *
- * Example:
- *
- * \code
- *   Substitute<Item, Tag> filter(consumer);
- *
- *   // Parse substitutions from a file into the filter
- *   TextFormat<Item, Tag>::parse(itemconv, tagconv, input, filter.substitutions());
- *
- *   // Filter the collection
- *   coll.output(filter);
- * \endcode
- */
-template<typename T, typename OUT>
-class Substitute : public wibble::mixin::OutputIterator< Substitute<T, OUT> >
-{
-protected:
-	Substitutions<T> changes;
-	OUT out;
-	
-public:
-	Substitute(const OUT& out) : out(out) {}
-	Substitute(const Substitutions<T>& changes, const OUT& out) : changes(changes), out(out) {}
-
-	/**
-	 * Access the internal Substitution list
-	 */
-	Substitutions<T>& substitutions() { return changes; }
-
-	/**
-	 * Access the internal Substitution list (const version)
-	 */
-	const Substitutions<T>& substitutions() const { return changes; }
-
-	template<typename Items, typename Tags>
-	Substitute<T, OUT>& operator=(const std::pair<Items, Tags>& data)
-	{
-		*out = make_pair(data.first, changes.change(data.second));
-		++out;
-		return *this;
-	}
-};
-
-template<typename T, typename OUT>
-Substitute<T, OUT> substitute(const Substitutions<T>& changes, const OUT& out)
-{
-	return Substitute<T, OUT>(changes, out);
-}
-
-/**
  * Remove packages with no tags.
  *
  * It can also be used in 'inverse' mode, where in removes the packages which



More information about the Debtags-commits mailing list