[Debtags-commits] [svn] r1732 - in tagcoll/2.0: . tagcoll
tagcoll/stream
Enrico Zini
enrico at costa.debian.org
Tue May 9 00:28:38 UTC 2006
Author: enrico
Date: Tue May 9 00:28:37 2006
New Revision: 1732
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/Expression.cc
tagcoll/2.0/tagcoll/Expression.h
tagcoll/2.0/tagcoll/stream/filters.cc
tagcoll/2.0/tagcoll/stream/filters.h
Log:
r2619 at viaza: enrico | 2006-05-08 12:50:44 -0500
Moved expression filters into stream/filters
Modified: tagcoll/2.0/tagcoll/Expression.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Expression.cc (original)
+++ tagcoll/2.0/tagcoll/Expression.cc Tue May 9 00:28:37 2006
@@ -257,58 +257,9 @@
ensure(e3(test1));
}
-template<> template<>
-void to::test<2>()
-{
- std::string input_coll(
- "a: b, c\n"
- "b:\n"
- "c: a\n"
- "d: c::D, e::F, f::g\n"
- );
- std::string output_coll(
- "a: b, c\n"
- "d: c::D, e::F, f::g\n"
- );
- InputMerger<string, string> result;
- parseCollection(input_coll, filterItemsByExpression(
- "(*::D && e::F) || c", inserter(result)));
-
- InputMerger<string, string> reference;
- parseCollection(output_coll, inserter(reference));
-
- ensure_coll_equals(reference, result);
}
-
-template<> template<>
-void to::test<3>()
-{
- std::string input_coll(
- "a: b, c, a::D\n"
- "b: D, *::D\n"
- "c: a\n"
- "d: c::D, e::F, f::g\n"
- );
- std::string output_coll(
- "a: c, a::D\n"
- "b: *::D\n"
- "d: c::D, e::F\n"
- );
- InputMerger<string, string> result;
- parseCollection(input_coll, filterTagsByExpression(
- "*::D || e::F || c", ExpressionFilter::PLAIN, inserter(result)));
-
- InputMerger<string, string> reference;
- parseCollection(output_coll, inserter(reference));
-
- ensure_coll_equals(reference, result);
}
-}
-}
-
-#include <tagcoll/TextFormat.tcc>
-
#endif
// vim:set ts=4 sw=4:
Modified: tagcoll/2.0/tagcoll/Expression.h
==============================================================================
--- tagcoll/2.0/tagcoll/Expression.h (original)
+++ tagcoll/2.0/tagcoll/Expression.h Tue May 9 00:28:37 2006
@@ -176,137 +176,6 @@
bool eval(const std::string& tag) const;
};
-class ExpressionFilter
-{
-public:
- enum MatchType { PLAIN, INVERTED };
-
-protected:
- Expression expr;
- MatchType matchType;
-
- template<typename Tags>
- bool match(const Tags& tags)
- {
- if (matchType == PLAIN)
- return expr(tags);
- else
- return !expr(tags);
- }
-
-public:
- /**
- * @param type
- * PLAIN: only keep the items that match the expression
- * INVERTED: only keep the items that do not match the expression
- */
- ExpressionFilter(const std::string& expr, MatchType type)
- : expr(expr), matchType(type) {}
- ExpressionFilter(const Expression& expr, MatchType type)
- : expr(expr), matchType(type) {}
-};
-
-/**
- * Remove the items that do not match a tag expression.
- */
-template<class OUT>
-class FilterItemsByExpression : public ExpressionFilter, public wibble::mixin::OutputIterator< FilterItemsByExpression<OUT> >
-{
-protected:
- OUT out;
-
-public:
- FilterItemsByExpression(const std::string& expr, ExpressionFilter::MatchType type, const OUT& out)
- : ExpressionFilter(expr, type), out(out) {}
- FilterItemsByExpression(const Expression& expr, ExpressionFilter::MatchType type, const OUT& out)
- : ExpressionFilter(expr, type), out(out) {}
-
- // output iterator interface
-
- template<typename Items, typename Tags>
- FilterItemsByExpression& operator=(const std::pair<Items, Tags>& data)
- {
- if (match(data.second))
- {
- *out = data;
- ++out;
- }
- return *this;
- }
-};
-
-template<typename EXPR, typename OUT>
-inline FilterItemsByExpression<OUT> filterItemsByExpression(const EXPR& expr, ExpressionFilter::MatchType type, const OUT& out)
-{
- return FilterItemsByExpression<OUT>(expr, type, out);
-}
-
-template<typename EXPR, typename OUT>
-inline FilterItemsByExpression<OUT> filterItemsByExpression(const EXPR& expr, const OUT& out)
-{
- return FilterItemsByExpression<OUT>(expr, ExpressionFilter::PLAIN, out);
-}
-
-/**
- * Remove the tags that do not singularly match a tag expression.
- *
- * This is a slight abuse of tag expressions, but it can prove useful to remove
- * tags matching, for example, "special::not-yet-tagged*" or
- * "!(use::gaming || game::*)".
- */
-template<class OUT>
-class FilterTagsByExpression : public ExpressionFilter, public wibble::mixin::OutputIterator< FilterTagsByExpression<OUT> >
-
-{
-protected:
- OUT out;
-
-public:
- FilterTagsByExpression(const std::string& expression, ExpressionFilter::MatchType type, const OUT& out) :
- ExpressionFilter(expression, type), out(out) {}
- FilterTagsByExpression(const Expression& expression, ExpressionFilter::MatchType type, const OUT& out) :
- ExpressionFilter(expression, type), out(out) {}
-
- // output iterator interface
-
- template<typename Items, typename Tags>
- FilterTagsByExpression& operator=(const std::pair<Items, Tags>& data)
- {
- // TODO:
- // We can use a vector since we know the input is sorted, and we
- // remove elements without altering the order of the remaining ones
- std::set<typename Tags::value_type> filtered;
- bool changed = false;
-
- for (typename Tags::const_iterator i = data.second.begin();
- i != data.second.end(); ++i)
- {
- if (match(wibble::singleton(*i)))
- filtered.insert(*i);
- else
- changed = true;
- }
- if (!changed)
- *out = data;
- else
- *out = std::make_pair(data.first, filtered);
- ++out;
- return *this;
- }
-};
-
-template<typename EXPR, typename OUT>
-inline FilterTagsByExpression<OUT> filterTagsByExpression(const EXPR& expr, ExpressionFilter::MatchType type, const OUT& out)
-{
- return FilterTagsByExpression<OUT>(expr, type, out);
-}
-
-template<typename EXPR, typename OUT>
-inline FilterTagsByExpression<OUT> filterTagsByExpression(const EXPR& expr, const OUT& out)
-{
- return FilterTagsByExpression<OUT>(expr, ExpressionFilter::PLAIN, out);
-}
-
};
// vim:set ts=4 sw=4:
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:28:37 2006
@@ -216,6 +216,53 @@
ensure_equals(count2, 3);
}
+template<> template<>
+void to::test<9>()
+{
+ std::string input_coll(
+ "a: b, c\n"
+ "b:\n"
+ "c: a\n"
+ "d: c::D, e::F, f::g\n"
+ );
+ std::string output_coll(
+ "a: b, c\n"
+ "d: c::D, e::F, f::g\n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, filterItemsByExpression(
+ "(*::D && e::F) || c", inserter(result)));
+
+ InputMerger<string, string> reference;
+ parseCollection(output_coll, inserter(reference));
+
+ ensure_coll_equals(reference, result);
+}
+
+template<> template<>
+void to::test<10>()
+{
+ std::string input_coll(
+ "a: b, c, a::D\n"
+ "b: D, *::D\n"
+ "c: a\n"
+ "d: c::D, e::F, f::g\n"
+ );
+ std::string output_coll(
+ "a: c, a::D\n"
+ "b: *::D\n"
+ "d: c::D, e::F\n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, filterTagsByExpression(
+ "*::D || e::F || c", ExpressionFilter::PLAIN, inserter(result)));
+
+ InputMerger<string, string> reference;
+ parseCollection(output_coll, inserter(reference));
+
+ ensure_coll_equals(reference, result);
+}
+
}
}
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:28:37 2006
@@ -26,6 +26,7 @@
#include <wibble/mixin.h>
#include <wibble/singleton.h>
#include <wibble/empty.h>
+#include <tagcoll/Expression.h>
#include <set>
#include <map>
#include <string>
@@ -379,6 +380,138 @@
return UngroupItems<OUT>(out);
}
+
+class ExpressionFilter
+{
+public:
+ enum MatchType { PLAIN, INVERTED };
+
+protected:
+ Expression expr;
+ MatchType matchType;
+
+ template<typename Tags>
+ bool match(const Tags& tags)
+ {
+ if (matchType == PLAIN)
+ return expr(tags);
+ else
+ return !expr(tags);
+ }
+
+public:
+ /**
+ * @param type
+ * PLAIN: only keep the items that match the expression
+ * INVERTED: only keep the items that do not match the expression
+ */
+ ExpressionFilter(const std::string& expr, MatchType type)
+ : expr(expr), matchType(type) {}
+ ExpressionFilter(const Expression& expr, MatchType type)
+ : expr(expr), matchType(type) {}
+};
+
+/**
+ * Remove the items that do not match a tag expression.
+ */
+template<class OUT>
+class FilterItemsByExpression : public ExpressionFilter, public wibble::mixin::OutputIterator< FilterItemsByExpression<OUT> >
+{
+protected:
+ OUT out;
+
+public:
+ FilterItemsByExpression(const std::string& expr, ExpressionFilter::MatchType type, const OUT& out)
+ : ExpressionFilter(expr, type), out(out) {}
+ FilterItemsByExpression(const Expression& expr, ExpressionFilter::MatchType type, const OUT& out)
+ : ExpressionFilter(expr, type), out(out) {}
+
+ // output iterator interface
+
+ template<typename Items, typename Tags>
+ FilterItemsByExpression& operator=(const std::pair<Items, Tags>& data)
+ {
+ if (match(data.second))
+ {
+ *out = data;
+ ++out;
+ }
+ return *this;
+ }
+};
+
+template<typename EXPR, typename OUT>
+inline FilterItemsByExpression<OUT> filterItemsByExpression(const EXPR& expr, ExpressionFilter::MatchType type, const OUT& out)
+{
+ return FilterItemsByExpression<OUT>(expr, type, out);
+}
+
+template<typename EXPR, typename OUT>
+inline FilterItemsByExpression<OUT> filterItemsByExpression(const EXPR& expr, const OUT& out)
+{
+ return FilterItemsByExpression<OUT>(expr, ExpressionFilter::PLAIN, out);
+}
+
+/**
+ * Remove the tags that do not singularly match a tag expression.
+ *
+ * This is a slight abuse of tag expressions, but it can prove useful to remove
+ * tags matching, for example, "special::not-yet-tagged*" or
+ * "!(use::gaming || game::*)".
+ */
+template<class OUT>
+class FilterTagsByExpression : public ExpressionFilter, public wibble::mixin::OutputIterator< FilterTagsByExpression<OUT> >
+
+{
+protected:
+ OUT out;
+
+public:
+ FilterTagsByExpression(const std::string& expression, ExpressionFilter::MatchType type, const OUT& out) :
+ ExpressionFilter(expression, type), out(out) {}
+ FilterTagsByExpression(const Expression& expression, ExpressionFilter::MatchType type, const OUT& out) :
+ ExpressionFilter(expression, type), out(out) {}
+
+ // output iterator interface
+
+ template<typename Items, typename Tags>
+ FilterTagsByExpression& operator=(const std::pair<Items, Tags>& data)
+ {
+ // TODO:
+ // We can use a vector since we know the input is sorted, and we
+ // remove elements without altering the order of the remaining ones
+ std::set<typename Tags::value_type> filtered;
+ bool changed = false;
+
+ for (typename Tags::const_iterator i = data.second.begin();
+ i != data.second.end(); ++i)
+ {
+ if (match(wibble::singleton(*i)))
+ filtered.insert(*i);
+ else
+ changed = true;
+ }
+ if (!changed)
+ *out = data;
+ else
+ *out = std::make_pair(data.first, filtered);
+ ++out;
+ return *this;
+ }
+};
+
+template<typename EXPR, typename OUT>
+inline FilterTagsByExpression<OUT> filterTagsByExpression(const EXPR& expr, ExpressionFilter::MatchType type, const OUT& out)
+{
+ return FilterTagsByExpression<OUT>(expr, type, out);
+}
+
+template<typename EXPR, typename OUT>
+inline FilterTagsByExpression<OUT> filterTagsByExpression(const EXPR& expr, const OUT& out)
+{
+ return FilterTagsByExpression<OUT>(expr, ExpressionFilter::PLAIN, out);
+}
+
}
}
More information about the Debtags-commits
mailing list