[Debtags-commits] [svn] r1724 - in tagcoll/2.0: . tagcoll
tagcoll/tests
Enrico Zini
enrico at costa.debian.org
Tue May 9 00:19:22 UTC 2006
Author: enrico
Date: Tue May 9 00:19:18 2006
New Revision: 1724
Added:
tagcoll/2.0/tagcoll/test-utils.tcc
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/Collection.h
tagcoll/2.0/tagcoll/InputMerger.cc
tagcoll/2.0/tagcoll/InputMerger.h
tagcoll/2.0/tagcoll/Patches.cc
tagcoll/2.0/tagcoll/Patches.h
tagcoll/2.0/tagcoll/Patches.tcc
tagcoll/2.0/tagcoll/ReadonlyCollection.h
tagcoll/2.0/tagcoll/filters.cc
tagcoll/2.0/tagcoll/filters.h
tagcoll/2.0/tagcoll/test-utils.cc
tagcoll/2.0/tagcoll/tests/test-utils.h
Log:
r2611 at viaza: enrico | 2006-05-07 17:02:53 -0500
Collection reorganization begins -- InputMerger is refactored.
Modified: tagcoll/2.0/tagcoll/Collection.h
==============================================================================
--- tagcoll/2.0/tagcoll/Collection.h (original)
+++ tagcoll/2.0/tagcoll/Collection.h Tue May 9 00:19:18 2006
@@ -24,7 +24,7 @@
*/
#include <tagcoll/ReadonlyCollection.h>
-#include <tagcoll/Consumer.h>
+#include <wibble/mixin.h>
namespace tagcoll
{
@@ -37,10 +37,10 @@
* not to store the items themselves. This means that collections are not
* required to keep track of items with no tags.
*/
-template<typename ITEM, typename TAG>
-class Collection : public Consumer<ITEM, TAG>, public ReadonlyCollection<ITEM, TAG>
+template<typename Self>
+class Collection : public ReadonlyCollection<Self>
{
-protected:
+//protected:
/*
* Implementation note: to avoid problems with classes implementing only
* some of the virtual methods, they are given different names. The common
@@ -48,11 +48,11 @@
* and are a way of keeping the unoverridden methods from being hidden.
*/
- void consumeItemUntagged(const ITEM&) {}
- void consumeItemsUntagged(const std::set<ITEM>&) {}
+ //void consumeItemUntagged(const ITEM&) {}
+ //void consumeItemsUntagged(const std::set<ITEM>&) {}
public:
- virtual ~Collection() {}
+ //virtual ~Collection() {}
/**
* Apply a patch to the collection
@@ -66,9 +66,35 @@
* }
* \endcode
*/
- virtual void applyChange(const PatchList<ITEM, TAG>& change) = 0;
+// void applyChange(
+// const PatchList<
+// typename coll_traits<Self>::item_type,
+// typename coll_traits<Self>::tag_type>& change);
};
+
+template<typename COLL>
+class Inserter : public wibble::mixin::OutputIterator< Inserter<COLL> >
+{
+ COLL& coll;
+
+public:
+ Inserter(COLL& coll) : coll(coll) {}
+
+ template<typename Items, typename Tags>
+ Inserter<COLL>& operator=(const std::pair<Items, Tags>& data)
+ {
+ coll.insert(data.first, data.second);
+ return *this;
+ }
+};
+
+template<typename COLL>
+Inserter<COLL> inserter(COLL& target)
+{
+ return Inserter<COLL>(target);
+}
+
};
// vim:set ts=4 sw=4:
Modified: tagcoll/2.0/tagcoll/InputMerger.cc
==============================================================================
--- tagcoll/2.0/tagcoll/InputMerger.cc (original)
+++ tagcoll/2.0/tagcoll/InputMerger.cc Tue May 9 00:19:18 2006
@@ -28,6 +28,7 @@
namespace tagcoll {
+#if 0
template<class T, class Tag>
void InputMerger<T, Tag>::consumeItem(const T& item, const std::set<Tag>& tags)
{
@@ -37,20 +38,21 @@
else
i->second |= tags;
}
+#endif
-template<class T, class Tag>
-std::set<Tag> InputMerger<T, Tag>::getTagsOfItem(const T& item) const
+template<class ITEM, class TAG>
+std::set<TAG> InputMerger<ITEM, TAG>::getTags(const ITEM& item) const
{
- typename map< T, std::set<Tag> >::const_iterator i = coll.find(item);
+ typename map< ITEM, std::set<TAG> >::const_iterator i = coll.find(item);
if (i == coll.end())
- return std::set<Tag>();
+ return std::set<TAG>();
else
return i->second;
}
template<class ITEM, class TAG>
-std::set<ITEM> InputMerger<ITEM, TAG>::getItemsHavingTag(const TAG& tag) const
+std::set<ITEM> InputMerger<ITEM, TAG>::getItems(const TAG& tag) const
{
std::set<ITEM> res;
for (typename map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
@@ -60,8 +62,8 @@
return res;
}
-template<class ITEM, class TAG>
-std::set<ITEM> InputMerger<ITEM, TAG>::getItemsHavingTags(const std::set<TAG>& tags) const
+template<class ITEM, class TAG> template<typename TAGS>
+std::set<ITEM> InputMerger<ITEM, TAG>::getItems(const TAGS& tags) const
{
std::set<ITEM> res;
for (typename map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
@@ -71,6 +73,7 @@
return res;
}
+#if 0
template<class T, class Tag>
void InputMerger<T, Tag>::output(Consumer<T, Tag>& consumer) const
{
@@ -91,16 +94,19 @@
consumer.consume(i->second, items);
}
}
+#endif
-template<class ITEM, class TAG>
-void InputMerger<ITEM, TAG>::outputHavingTags(const std::set<TAG>& ts, Consumer<ITEM, TAG>& consumer) const
+template<class ITEM, class TAG> template<typename TAGS, typename OUT>
+void InputMerger<ITEM, TAG>::outputHavingTags(const TAGS& ts, OUT& out) const
{
for (typename map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
- i != coll.end(); i++)
+ i != coll.end(); ++i)
if (set_contains(i->second, ts))
- consumer.consume(i->first, i->second);
+ {
+ *out = *i;
+ ++out;
+ }
}
-
@@ -202,7 +208,7 @@
{
InputMerger<string, string> coll;
- output_test_collection(coll);
+ output_test_collection(inserter(coll));
test_readonly_collection(coll);
}
Modified: tagcoll/2.0/tagcoll/InputMerger.h
==============================================================================
--- tagcoll/2.0/tagcoll/InputMerger.h (original)
+++ tagcoll/2.0/tagcoll/InputMerger.h Tue May 9 00:19:18 2006
@@ -34,6 +34,19 @@
{
template<typename T1, typename T2> class PatchList;
+template<typename ITEM, typename TAG>
+class InputMerger;
+
+template<typename ITEM, typename TAG>
+struct coll_traits< InputMerger<ITEM, TAG> >
+{
+ typedef ITEM item_type;
+ typedef TAG tag_type;
+ typedef std::set<ITEM> tagset_type;
+ typedef std::set<TAG> itemset_type;
+};
+
+
/**
* Simple Collection.
*
@@ -42,24 +55,52 @@
*
* It is also a full-featured collection, although not very optimized.
*/
-template<class ITEM, class TAG>
-class InputMerger : public Collection<ITEM, TAG>
+template<typename ITEM, typename TAG>
+class InputMerger : public Collection< InputMerger<ITEM, TAG> >
{
protected:
std::map< ITEM, std::set<TAG> > coll;
+#if 0
virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags);
- virtual std::set<TAG> getTagsOfItem(const ITEM& item) const;
- virtual std::set<ITEM> getItemsHavingTag(const TAG& tag) const;
virtual std::set<ITEM> getItemsHavingTags(const std::set<TAG>& tags) const;
-
+#endif
public:
- virtual ~InputMerger<ITEM, TAG>() {}
+ typedef typename std::map< ITEM, std::set<TAG> >::const_iterator const_iterator;
+ typedef typename std::map< ITEM, std::set<TAG> >::iterator iterator;
+
+ const_iterator begin() const { return coll.begin(); }
+ const_iterator end() const { return coll.end(); }
+ iterator begin() { return coll.begin(); }
+ iterator end() { return coll.end(); }
+
+ template<typename ITEMS, typename TAGS>
+ void insert(const ITEMS& items, const TAGS& tags)
+ {
+ for (typename ITEMS::const_iterator i = items.begin();
+ i != items.end(); ++i)
+ {
+ typename std::map< ITEM, std::set<TAG> >::iterator iter = coll.find(*i);
+ if (iter == coll.end())
+ coll.insert(std::make_pair(*i, std::set<TAG>() | tags));
+ else
+ iter->second |= tags;
+ }
+ }
bool hasItem(const ITEM& item) const { return coll.find(item) != coll.end(); }
+ std::set<TAG> getTags(const ITEM& item) const;
+ std::set<ITEM> getItems(const TAG& tag) const;
+ template<typename TAGS>
+ std::set<ITEM> getItems(const TAGS& tag) const;
+
+ template<typename TAGS, typename OUT>
+ void outputHavingTags(const TAGS& tags, OUT& out) const;
+
+#if 0
void output(Consumer<ITEM, TAG>& consumer) const;
void outputHavingTags(const std::set<TAG>& ts, Consumer<ITEM, TAG>& consumer) const;
@@ -68,10 +109,11 @@
* and they are tagged with the items that had them
*/
void outputReversed(Consumer<TAG, ITEM>& consumer) const;
+#endif
void applyChange(const PatchList<ITEM, TAG>& change);
- virtual std::set<ITEM> getTaggedItems() const
+ std::set<ITEM> getTaggedItems() const
{
std::set<ITEM> res;
for (typename std::map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
Modified: tagcoll/2.0/tagcoll/Patches.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.cc (original)
+++ tagcoll/2.0/tagcoll/Patches.cc Tue May 9 00:19:18 2006
@@ -72,10 +72,10 @@
removed.clear(); removed.insert("f::g");
patches.addPatch(Patch<string, string>("d", added, removed));
- parseCollection(input_coll, patcher(patches, consumer(result)));
+ parseCollection(input_coll, patcher(patches, inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
Modified: tagcoll/2.0/tagcoll/Patches.h
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.h (original)
+++ tagcoll/2.0/tagcoll/Patches.h Tue May 9 00:19:18 2006
@@ -131,7 +131,8 @@
/**
* Add to this patchlist the patches needed to transform `im1' in `im2'
*/
- void addPatch(const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2);
+ template<typename COLL1, typename COLL2>
+ void addPatch(const COLL1& im1, const COLL2& im2);
/**
* Add `patch' to this PatchList
Modified: tagcoll/2.0/tagcoll/Patches.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.tcc (original)
+++ tagcoll/2.0/tagcoll/Patches.tcc Tue May 9 00:19:18 2006
@@ -26,35 +26,6 @@
namespace tagcoll {
template <class ITEM, class TAG>
-class PatchGenerator: public Consumer<ITEM, TAG>
-{
-protected:
- PatchList<ITEM, TAG>& target;
- const ReadonlyCollection<ITEM, TAG>& second;
-
- // Process an untagged item
- virtual void consumeItemUntagged(const ITEM& item)
- {
- std::set<TAG> ts2 = second.getTags(item);
- if (!ts2.empty())
- target.addPatch(Patch<ITEM, TAG>(item, ts2, std::set<TAG>()));
- }
-
- // Process a tagged item, with its tags
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& ts1)
- {
- std::set<TAG> ts2 = second.getTags(item);
- std::set<TAG> added = ts2 - ts1;
- std::set<TAG> removed = ts1 - ts2;
- if (!added.empty() || !removed.empty())
- target.addPatch(Patch<ITEM, TAG>(item, added, removed));
- }
-public:
- PatchGenerator(PatchList<ITEM, TAG>& target, const ReadonlyCollection<ITEM, TAG>& second)
- : target(target), second(second) {}
-};
-
-template <class ITEM, class TAG>
void PatchList<ITEM, TAG>::addPatch(const Patch<ITEM, TAG>& patch)
{
// Filter out empty patches
@@ -76,12 +47,18 @@
addPatch(i->second);
}
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::addPatch(
- const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2)
+template <class ITEM, class TAG> template<typename COLL1, typename COLL2>
+void PatchList<ITEM, TAG>::addPatch(const COLL1& im1, const COLL2& im2)
{
- PatchGenerator<ITEM, TAG> patchgen(*this, im2);
- im1.output(patchgen);
+ for (typename COLL1::const_iterator i1 = im1.begin();
+ i1 = im1.end(); ++i1)
+ {
+ std::set<TAG> ts2 = im2.getTags(i1.first);
+ std::set<TAG> added = ts2 - i1.second;
+ std::set<TAG> removed = i1.second - ts2;
+ if (!added.empty() || !removed.empty())
+ addPatch(Patch<ITEM, TAG>(i1.first, added, removed));
+ }
}
template <class ITEM, class TAG>
Modified: tagcoll/2.0/tagcoll/ReadonlyCollection.h
==============================================================================
--- tagcoll/2.0/tagcoll/ReadonlyCollection.h (original)
+++ tagcoll/2.0/tagcoll/ReadonlyCollection.h Tue May 9 00:19:18 2006
@@ -23,11 +23,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <tagcoll/Consumer.h>
#include <tagcoll/setutils.h>
namespace tagcoll
{
+
+template<typename T>
+class coll_traits;
+
/**
* Interface for all collections of tagged items.
*
@@ -35,9 +38,10 @@
* not to store the items themselves. This means that collections are not
* required to keep track of items with no tags.
*/
-template<typename ITEM, typename TAG>
+template<typename Self>
class ReadonlyCollection
{
+#if 0
template<typename OUT>
class Forwarder : public Consumer<ITEM, TAG>
{
@@ -74,37 +78,16 @@
Forwarder(const OUT& out) : out(out) {}
virtual ~Forwarder() {}
};
+#endif
-protected:
+//protected:
/**
* Get the items which are tagged with at least the tag `tag'
*
* \return
* The items found, or an empty set if no items have that tag
*/
- virtual std::set<ITEM> getItemsHavingTag(const TAG& tag) const = 0;
-
- /**
- * Get the items which are tagged with at least the tags `tags'
- *
- * \return
- * The items found, or an empty set if no items have that tag
- */
- virtual std::set<ITEM> getItemsHavingTags(const std::set<TAG>& tags) const
- {
- using namespace wibble::operators;
- if (tags.empty())
- return std::set<ITEM>();
-
- typename std::set<TAG>::const_iterator i = tags.begin();
- std::set<ITEM> res = getItemsHavingTag(*i);
-
- for ( ; i != tags.end(); i++)
- res &= getItemsHavingTag(*i);
-
- return res;
-
- }
+ //virtual std::set<ITEM> getItemsHavingTag(const TAG& tag) const = 0;
/**
* Get the tags attached to an item.
@@ -115,30 +98,9 @@
* The set of tags, or an empty set if the item has no tags or it does
* not exist.
*/
- virtual std::set<TAG> getTagsOfItem(const ITEM& item) const = 0;
-
- /**
- * Get all the tags attached to the items in a set.
- *
- * \param items
- * The items to query
- * \return
- * The set of tags, or an empty set if the items have no tags or do not
- * exist.
- */
- virtual std::set<TAG> getTagsOfItems(const std::set<ITEM>& items) const
- {
- using namespace wibble::operators;
- std::set<TAG> res;
- for (typename std::set<ITEM>::const_iterator i = items.begin();
- i != items.end(); i++)
- res |= getTagsOfItem(*i);
- return res;
- }
+ //virtual std::set<TAG> getTagsOfItem(const ITEM& item) const = 0;
public:
- virtual ~ReadonlyCollection() {}
-
/**
* Check if the collection contains a tag
*
@@ -147,7 +109,7 @@
* \return
* true if the collection contains tag, false otherwise
*/
- virtual bool hasTag(const TAG& tag) const
+ bool hasTag(const typename coll_traits<Self>::tag_type& tag) const
{
return !getItems(tag).empty();
}
@@ -155,37 +117,70 @@
/**
* Get the tags of item `item'. Return an empty set if `item' does not exist
*/
- std::set<TAG> getTags(const ITEM& item) const { return getTagsOfItem(item); }
+ //std::set<Self::tag_type> getTags(const typename Self::item_type& item) const = 0;
/**
- * Get all the tags of items `items'. Return an empty set if all of `item' do not exist
+ * Get all the tags attached to the items in a set.
+ *
+ * \param items
+ * The items to query
+ * \return
+ * The set of tags, or an empty set if the items have no tags or do not
+ * exist.
*/
- std::set<TAG> getTags(const std::set<ITEM>& items) const { return getTagsOfItems(items); }
+ template<typename ITEMS>
+ typename coll_traits<Self>::tagset_type getTags(const ITEMS& items) const
+ {
+ using namespace wibble::operators;
+ typename coll_traits<Self>::tagset_type res;
+ for (typename ITEMS::const_iterator i = items.begin();
+ i != items.end(); i++)
+ res |= getTagsOfItem(*i);
+ return res;
+ }
+
/**
* Get the items with tag `tag'. Return an empty set if `tag' does not exist
*/
- std::set<ITEM> getItems(const TAG& tag) const { return getItemsHavingTag(tag); }
+ //std::set<typename Self::item_type> getItems(const TAG& tag) const { return getItemsHavingTag(tag); }
/**
- * Get the items with tag `tag'. Return an empty set if `tag' does not exist
+ * Get the items which are tagged with at least the tags `tags'
+ *
+ * \return
+ * The items found, or an empty set if no items have that tag
*/
- std::set<ITEM> getItems(const std::set<TAG>& tags) const { return getItemsHavingTags(tags); }
+ template<typename TAGS>
+ typename coll_traits<Self>::itemset_type getItems(const TAGS& tags) const
+ {
+ using namespace wibble::operators;
+ if (tags.empty())
+ return Self::itemset_type();
+
+ typename TAGS::const_iterator i = tags.begin();
+ typename Self::itemset_type res = getItemsHavingTag(*i);
+
+ for ( ; i != tags.end(); ++i)
+ res &= getItemsHavingTag(*i);
+
+ return res;
+ }
/**
* Get the set of all the items that have tags according to this collection
*/
- virtual std::set<ITEM> getTaggedItems() const = 0;
+ //virtual std::set<Self::item_type> getTaggedItems() const = 0;
/**
* Get the set of all the tags in this collection
*/
- virtual std::set<TAG> getAllTags() const = 0;
+ //virtual std::set<Self::tag_type> getAllTags() const = 0;
/**
* Get the cardinality of tag `tag' (that is, the number of items who have it)
*/
- virtual int getCardinality(const TAG& tag) const
+ int getCardinality(const typename coll_traits<Self>::tag_type& tag) const
{
return getItemsHavingTag(tag).size();
}
@@ -203,7 +198,8 @@
* }
* \endcode
*/
- virtual std::set<TAG> getCompanionTags(const std::set<TAG>& tags) const
+ template<typename TAGS>
+ typename coll_traits<Self>::tagset_type getCompanionTags(const TAGS& tags) const
{
using namespace wibble::operators;
return getTagsOfItems(getItemsHavingTags(tags)) - tags;
@@ -240,19 +236,20 @@
* }
* \endcode
*/
- virtual std::set<ITEM> getRelatedItems(const std::set<TAG>& tags, int maxdistance = 1) const
+ template<typename TAGS>
+ typename coll_traits<Self>::itemset_type getRelatedItems(const TAGS& tags, int maxdistance = 1) const
{
using namespace wibble::operators;
- std::set<ITEM> packages;
- std::set<ITEM> res;
+ typename coll_traits<Self>::itemset_type packages;
+ typename coll_traits<Self>::itemset_type res;
// First get a list of packages that have a non-empty intersection with `tags'
- for (typename std::set<TAG>::const_iterator i = tags.begin(); i != tags.end(); i++)
+ for (typename TAGS::const_iterator i = tags.begin(); i != tags.end(); i++)
packages |= getItemsHavingTag(*i);
// Then keep only those within the given distance
- for (typename std::set<ITEM>::const_iterator i = packages.begin(); i != packages.end(); i++)
+ for (typename coll_traits<Self>::itemset_type::const_iterator i = packages.begin(); i != packages.end(); i++)
{
int dist = set_distance(tags, getTagsOfItem(*i));
if (dist >= 0 && dist <= maxdistance)
@@ -265,25 +262,31 @@
/**
* Output all the contents of the collection to a Consumer
*/
- virtual void output(Consumer<ITEM, TAG>& consumer) const = 0;
+ //virtual void output(Consumer<ITEM, TAG>& consumer) const = 0;
+#if 0
template<typename OUT>
void outputToIterator(const OUT& cons) const
{
Forwarder<OUT> forwarder(cons);
output(forwarder);
}
+#endif
/**
* Send to a consumer all the items which are tagged with at least the
* given tags
*/
- virtual void outputHavingTags(const std::set<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
+ template<typename TAGS, typename OUT>
+ void outputHavingTags(const TAGS& tags, OUT& out) const
{
- std::set<ITEM> items = getItemsHavingTags(tags);
- for (typename std::set<ITEM>::const_iterator i = items.begin();
+ typename coll_traits<Self>::itemset_type items = getItemsHavingTags(tags);
+ for (typename coll_traits<Self>::itemset_type::const_iterator i = items.begin();
i != items.end(); i++)
- consumer.consume(*i, getTagsOfItem(*i));
+ {
+ *out = std::make_pair(*i, getTagsOfItem(*i));
+ ++out;
+ }
}
};
Modified: tagcoll/2.0/tagcoll/filters.cc
==============================================================================
--- tagcoll/2.0/tagcoll/filters.cc (original)
+++ tagcoll/2.0/tagcoll/filters.cc Tue May 9 00:19:18 2006
@@ -58,10 +58,10 @@
Substitutions<string> changes;
parseCollection(input_subst, changes.inserter());
- parseCollection(input_coll, substitute(changes, consumer(result)));
+ parseCollection(input_coll, substitute(changes, inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -79,10 +79,10 @@
"c: c::D, e, f::g\n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, untaggedRemover(consumer(result)));
+ parseCollection(input_coll, untaggedRemover(inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -99,10 +99,10 @@
"a: \n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, untaggedRemover(consumer(result), true));
+ parseCollection(input_coll, untaggedRemover(inserter(result), true));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -121,10 +121,10 @@
"c: c::D, f::g\n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, unfacetedRemover(consumer(result)));
+ parseCollection(input_coll, unfacetedRemover(inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -143,10 +143,10 @@
"c: c---D, f---g\n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, unfacetedRemover(consumer(result), "---"));
+ parseCollection(input_coll, unfacetedRemover(inserter(result), "---"));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -165,10 +165,10 @@
"c: \n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, itemsOnly(consumer(result)));
+ parseCollection(input_coll, itemsOnly(inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
@@ -188,10 +188,10 @@
"z: b\n"
);
InputMerger<string, string> result;
- parseCollection(input_coll, reverser(string("z"), consumer(result)));
+ parseCollection(input_coll, reverser(string("z"), inserter(result)));
InputMerger<string, string> reference;
- parseCollection(output_coll, consumer(reference));
+ parseCollection(output_coll, inserter(reference));
ensure_coll_equals(reference, result);
}
Modified: tagcoll/2.0/tagcoll/filters.h
==============================================================================
--- tagcoll/2.0/tagcoll/filters.h (original)
+++ tagcoll/2.0/tagcoll/filters.h Tue May 9 00:19:18 2006
@@ -329,7 +329,7 @@
template<typename ITEMS>
Reverser<OUT, TAG>& operator=(const std::pair< ITEMS, wibble::Empty<TAG> >& data)
{
- *out = make_pair(reversedNull, data.first);
+ *out = make_pair(wibble::singleton(reversedNull), data.first);
++out;
return *this;
}
@@ -338,7 +338,7 @@
Reverser<OUT, TAG>& operator=(const std::pair<ITEMS, TAGS>& data)
{
if (data.second.begin() == data.second.end())
- *out = make_pair(reversedNull, data.first);
+ *out = make_pair(wibble::singleton(reversedNull), data.first);
else
*out = make_pair(data.second, data.first);
++out;
Modified: tagcoll/2.0/tagcoll/test-utils.cc
==============================================================================
--- tagcoll/2.0/tagcoll/test-utils.cc (original)
+++ tagcoll/2.0/tagcoll/test-utils.cc Tue May 9 00:19:18 2006
@@ -80,30 +80,6 @@
}
}
-void __output_test_collection(const Location& loc, Consumer<string, string>& tc)
-{
- std::set<string> tagset;
-
- tagset.clear();
- tc.consume("gnocco");
-
- tagset.clear();
- tagset.insert("tomato"); tagset.insert("mozzarella");
- tc.consume("margherita", tagset);
-
- tagset.clear();
- tagset.insert("tomato"); tagset.insert("mozzarella"); tagset.insert("mushrooms");
- tc.consume("funghi", tagset);
-
- tagset.clear();
- tagset.insert("garlic"); tagset.insert("rosemerry");
- tc.consume("rosmarino", tagset);
-
- tagset.clear();
- tagset.insert("garlic"); tagset.insert("tomato");
- tc.consume("marinara", tagset);
-}
-
void __test_readonly_collection(const Location& loc, ReadonlyCollection<string, string>& tc)
{
std::set<string> s, s1;
Modified: tagcoll/2.0/tagcoll/tests/test-utils.h
==============================================================================
--- tagcoll/2.0/tagcoll/tests/test-utils.h (original)
+++ tagcoll/2.0/tagcoll/tests/test-utils.h Tue May 9 00:19:18 2006
@@ -56,9 +56,8 @@
__tc_ensure_coll_equals(Location(__FILE__, __LINE__, #a " == " #b), a, b)
#define inner_ensure_coll_equals(a, b) \
__tc_ensure_coll_equals(Location(loc, __FILE__, __LINE__, #a " == " #b), a, b)
-void __tc_ensure_coll_equals(const Location& loc,
- const tagcoll::ReadonlyCollection<string, string>& c1,
- const tagcoll::ReadonlyCollection<string, string>& c2);
+template<typename COLL1, typename COLL2>
+void __tc_ensure_coll_equals(const Location& loc, const COLL1& c1, const COLL2& c2);
#define ensure_contains(a, b) \
_ensure_contains(Location(__FILE__, __LINE__, #a " contains " #b), a, b)
@@ -112,15 +111,18 @@
#define output_test_collection(x) (__output_test_collection(Location(__FILE__, __LINE__, #x), (x)))
#define inner_output_test_collection(x) (__output_test_collection(Location(loc, __FILE__, __LINE__, $x), (x)))
-void __output_test_collection(const Location& loc, Consumer<string, string>& tc);
+template<typename OUT>
+void __output_test_collection(const Location& loc, OUT tc);
#define test_readonly_collection(x) (__test_readonly_collection(Location(__FILE__, __LINE__, #x), (x)))
#define inner_test_readonly_collection(x) (__test_readonly_collection(Location(loc, __FILE__, __LINE__, #x), (x)))
-void __test_readonly_collection(const Location& loc, ReadonlyCollection<string, string>& tc);
+template<typename ROCOLL>
+void __test_readonly_collection(const Location& loc, const ROCOLL& tc);
#define test_collection(x) (__test_collection(Location(__FILE__, __LINE__, #x), (x)))
-void __test_collection(const Location& loc, Collection<string, string>& tc);
+template<typename COLL>
+void __test_collection(const Location& loc, COLL& tc);
#endif
}
More information about the Debtags-commits
mailing list