[Debtags-commits] [svn] r1688 - in tagcoll/2.0: . tagcoll
Enrico Zini
enrico at costa.debian.org
Tue May 2 08:48:34 UTC 2006
Author: enrico
Date: Tue May 2 08:48:33 2006
New Revision: 1688
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/Filters.cc
tagcoll/2.0/tagcoll/Filters.h
Log:
r2548 at viaza: enrico | 2006-05-02 08:35:06 +0200
Refactored UntaggedRemover
Modified: tagcoll/2.0/tagcoll/Filters.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Filters.cc (original)
+++ tagcoll/2.0/tagcoll/Filters.cc Tue May 2 08:48:33 2006
@@ -119,6 +119,47 @@
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"
+ );
+ std::string output_coll(
+ "b: c::D, e::F, f::g\n"
+ "c: c::D, e, f::g\n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, untaggedRemover(consumer(result)));
+
+ InputMerger<string, string> reference;
+ outputCollection(output_coll, reference);
+
+ gen_ensure_coll_equals(reference, result);
+}
+
+template<> template<>
+void to::test<3>()
+{
+ std::string input_coll(
+ "a: \n"
+ "b: c::D, e::F, f::g\n"
+ "c: c::D, e, f::g\n"
+ );
+ std::string output_coll(
+ "a: \n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, untaggedRemover(consumer(result), true));
+
+ InputMerger<string, string> reference;
+ outputCollection(output_coll, reference);
+
+ gen_ensure_coll_equals(reference, result);
+}
+
+template<> template<>
+void to::test<4>()
+{
+ std::string input_coll(
"a: b, c, d::e\n"
"b: c::D, e::F, f::g\n"
"c: c::D, e, f::g\n"
@@ -139,7 +180,7 @@
}
template<> template<>
-void to::test<3>()
+void to::test<5>()
{
std::string input_coll(
"a: b, c, d---e\n"
Modified: tagcoll/2.0/tagcoll/Filters.h
==============================================================================
--- tagcoll/2.0/tagcoll/Filters.h (original)
+++ tagcoll/2.0/tagcoll/Filters.h Tue May 2 08:48:33 2006
@@ -159,52 +159,45 @@
* It can also be used in 'inverse' mode, where in removes the packages which
* have tags and keeps the packages that have none.
*/
-template <typename ITEM, typename TAG>
-class UntaggedRemover : public Filter<ITEM, TAG>
+template <typename OUT>
+class UntaggedRemover
{
protected:
+ OUT out;
bool inverse;
- virtual void consumeItemUntagged(const ITEM& item)
- {
- if (inverse)
- this->consumer->consume(item);
- }
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
- {
- if (inverse)
- {
- if (tags.empty())
- this->consumer->consume(item);
- } else {
- if (!tags.empty())
- this->consumer->consume(item, tags);
- }
- }
- virtual void consumeItemsUntagged(const std::set<ITEM>& items)
- {
- if (inverse)
- this->consumer->consume(items);
- }
- virtual void consumeItemss(const std::set<ITEM>& items, const std::set<TAG>& tags)
+public:
+ UntaggedRemover(const OUT& out, bool inverse = false) : out(out), inverse(inverse) {}
+
+ UntaggedRemover<OUT>& operator++() { return *this; }
+
+ template<typename Items, typename Tags>
+ UntaggedRemover<OUT>& operator=(const std::pair<Items, Tags>& data)
{
- if (inverse)
+ if (data.second.begin() == data.second.end())
{
- if (tags.empty())
- this->consumer->consume(items);
+ if (inverse)
+ {
+ out = data;
+ ++out;
+ }
} else {
- if (!tags.empty())
- this->consumer->consume(items, tags);
+ if (!inverse)
+ {
+ out = data;
+ ++out;
+ }
}
+ return *this;
}
-
-public:
- UntaggedRemover(bool inverse = false) : inverse(inverse) {}
- UntaggedRemover(tagcoll::Consumer<ITEM, TAG>& cons, bool inverse = false)
- : Filter<ITEM, TAG>(cons), inverse(inverse) {}
- virtual ~UntaggedRemover() {}
};
+template<typename OUT>
+UntaggedRemover<OUT> untaggedRemover(const OUT& out, bool inverse = false)
+{
+ return UntaggedRemover<OUT>(out, inverse);
+}
+
/**
* Removes tags which are not inside a facet
More information about the Debtags-commits
mailing list