[Debtags-commits] [svn] r1710 - in tagcoll/2.0: . tagcoll tools
Enrico Zini
enrico at costa.debian.org
Tue May 9 00:07:05 UTC 2006
Author: enrico
Date: Tue May 9 00:07:04 2006
New Revision: 1710
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/TDBIndexer.h
tagcoll/2.0/tagcoll/filters.cc
tagcoll/2.0/tagcoll/filters.h
tagcoll/2.0/tools/tagcoll.cc
Log:
r2597 at viaza: enrico | 2006-05-06 12:39:50 -0500
Moved ItemsOnly and Reverser from tagcoll.cc to filters.h
Modified: tagcoll/2.0/tagcoll/TDBIndexer.h
==============================================================================
--- tagcoll/2.0/tagcoll/TDBIndexer.h (original)
+++ tagcoll/2.0/tagcoll/TDBIndexer.h Tue May 9 00:07:04 2006
@@ -24,7 +24,6 @@
*/
#include <tagcoll/Collection.h>
-#include <tagcoll/Serializer.h>
#include <map>
namespace tagcoll
Modified: tagcoll/2.0/tagcoll/filters.cc
==============================================================================
--- tagcoll/2.0/tagcoll/filters.cc (original)
+++ tagcoll/2.0/tagcoll/filters.cc Tue May 9 00:07:04 2006
@@ -149,6 +149,50 @@
gen_ensure_coll_equals(reference, result);
}
+template<> template<>
+void to::test<6>()
+{
+ std::string input_coll(
+ "a: b, c, d::e\n"
+ "b: \n"
+ "c: c::D, e, f::g\n"
+ );
+ std::string output_coll(
+ "a: \n"
+ "b:\n"
+ "c: \n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, itemsOnly(consumer(result)));
+
+ InputMerger<string, string> reference;
+ outputCollection(output_coll, reference);
+
+ gen_ensure_coll_equals(reference, result);
+}
+
+template<> template<>
+void to::test<7>()
+{
+ std::string input_coll(
+ "a: 1, 2\n"
+ "b: \n"
+ "c: 2, 3\n"
+ );
+ std::string output_coll(
+ "1: a\n"
+ "2: a, c\n"
+ "3: c\n"
+ "z: b\n"
+ );
+ InputMerger<string, string> result;
+ parseCollection(input_coll, reverser(string("z"), consumer(result)));
+
+ InputMerger<string, string> reference;
+ outputCollection(output_coll, reference);
+
+ gen_ensure_coll_equals(reference, result);
+}
}
#include <tagcoll/TextFormat.tcc>
Modified: tagcoll/2.0/tagcoll/filters.h
==============================================================================
--- tagcoll/2.0/tagcoll/filters.h (original)
+++ tagcoll/2.0/tagcoll/filters.h Tue May 9 00:07:04 2006
@@ -24,6 +24,7 @@
*/
#include <wibble/mixin.h>
+#include <wibble/empty.h>
#include <set>
#include <map>
#include <string>
@@ -236,6 +237,65 @@
return UnfacetedRemover<OUT>(out, separator);
}
+template<typename OUT>
+class ItemsOnly : public wibble::mixin::OutputIterator< ItemsOnly<OUT> >
+{
+ OUT out;
+
+public:
+ ItemsOnly(const OUT& out) : out(out) {}
+
+ template<typename ITEMS, typename TAGS>
+ ItemsOnly<OUT>& operator=(const std::pair<ITEMS, TAGS>& data)
+ {
+ *out = make_pair(data.first, wibble::Empty<typename TAGS::value_type>());
+ ++out;
+ return *this;
+ }
+};
+
+template<typename OUT>
+ItemsOnly<OUT> itemsOnly(const OUT& out)
+{
+ return ItemsOnly<OUT>(out);
+}
+
+template<typename OUT, typename TAG>
+class Reverser : public wibble::mixin::OutputIterator< Reverser<OUT, TAG> >
+{
+ OUT out;
+ TAG reversedNull;
+
+public:
+ Reverser(const OUT& out, const TAG& reversedNull = TAG())
+ : out(out), reversedNull(reversedNull) {}
+
+ template<typename ITEMS>
+ Reverser<OUT, TAG>& operator=(const std::pair< ITEMS, wibble::Empty<TAG> >& data)
+ {
+ *out = make_pair(reversedNull, data.first);
+ ++out;
+ return *this;
+ }
+
+ template<typename ITEMS, typename TAGS>
+ Reverser<OUT, TAG>& operator=(const std::pair<ITEMS, TAGS>& data)
+ {
+ if (data.second.begin() == data.second.end())
+ *out = make_pair(reversedNull, data.first);
+ else
+ *out = make_pair(data.second, data.first);
+ ++out;
+ return *this;
+ }
+};
+
+template<typename OUT, typename TAG>
+Reverser<OUT, TAG> reverser(const TAG& reversedNull, const OUT& out)
+{
+ return Reverser<OUT, TAG>(out, reversedNull);
+}
+
};
// vim:set ts=4 sw=4:
Modified: tagcoll/2.0/tools/tagcoll.cc
==============================================================================
--- tagcoll/2.0/tools/tagcoll.cc (original)
+++ tagcoll/2.0/tools/tagcoll.cc Tue May 9 00:07:04 2006
@@ -38,16 +38,15 @@
#include <wibble/exception.h>
#include <wibble/operators.h>
-#include <tagcoll/stringf.h>
+
+#include <tagcoll/filters.h>
#include <tagcoll/CardinalityStore.h>
#include <tagcoll/SmartHierarchy.h>
#include <tagcoll/Consumer.h>
-#include <tagcoll/Filter.h>
#include <tagcoll/InputMerger.h>
#include <tagcoll/Implications.h>
-#include <tagcoll/Filters.h>
#include <tagcoll/Patches.h>
#include <tagcoll/DerivedTags.h>
@@ -78,9 +77,7 @@
{
for (set<string>::const_iterator i = items.begin();
i != items.end(); i++)
- {
- printf("%.*s%.*s\n", PFSTR(prefix), PFSTR(*i));
- }
+ cout << prefix << *i << endl;
}
void printNode(HierarchyNode<string, string>* node, string prefix = "")
@@ -248,61 +245,6 @@
}
}
-template<typename ITEM, typename TAG>
-class ItemsOnly : public Filter<ITEM, TAG>
-{
-protected:
- virtual void consumeItemUntagged(const ITEM& item)
- {
- this->consumer->consume(item);
- }
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
- {
- this->consumer->consume(item);
- }
- virtual void consumeItemsUntagged(const std::set<ITEM>& items)
- {
- this->consumer->consume(items);
- }
- virtual void consumeItem(const std::set<ITEM>& items, const std::set<TAG>& tags)
- {
- this->consumer->consume(items);
- }
-
-public:
- ItemsOnly() {}
- ItemsOnly(Consumer<ITEM, TAG>& cons) : Filter<ITEM, TAG>(cons) {}
-};
-
-template<typename ITEM, typename TAG>
-class Reverser : public Consumer<ITEM, TAG>
-{
-protected:
- Consumer<TAG, ITEM>* consumer;
- TAG reversedNull;
-
- virtual void consumeItemUntagged(const ITEM& item)
- {
- consumer->consume(reversedNull, std::set<ITEM>() + item);
- }
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags)
- {
- consumer->consume(tags, std::set<ITEM>() + item);
- }
- virtual void consumeItemsUntagged(const std::set<ITEM>& items)
- {
- consumer->consume(reversedNull, items);
- }
- virtual void consumeItem(const std::set<ITEM>& items, const std::set<TAG>& tags)
- {
- consumer->consume(tags, items);
- }
-
-public:
- Reverser(Consumer<TAG, ITEM>& cons, const TAG& reversedNull = TAG()) :
- consumer(&cons), reversedNull(reversedNull) {}
-};
-
class Reader
{
// Prepare the input filter chain
More information about the Debtags-commits
mailing list