[Debtags-commits] [svn] r1699 - in tagcoll/2.0: . tagcoll
Enrico Zini
enrico at costa.debian.org
Fri May 5 06:58:25 UTC 2006
Author: enrico
Date: Fri May 5 06:58:17 2006
New Revision: 1699
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/Consumer.h
tagcoll/2.0/tagcoll/Patches.cc
tagcoll/2.0/tagcoll/Patches.h
tagcoll/2.0/tagcoll/Patches.tcc
Log:
r2578 at viaza: enrico | 2006-05-05 00:33:48 +0200
Patches now work with the new output iterators
Modified: tagcoll/2.0/tagcoll/Consumer.h
==============================================================================
--- tagcoll/2.0/tagcoll/Consumer.h (original)
+++ tagcoll/2.0/tagcoll/Consumer.h Fri May 5 06:58:17 2006
@@ -24,6 +24,7 @@
*/
#include <wibble/empty.h>
+#include <wibble/singleton.h>
#include <set>
namespace tagcoll
@@ -108,6 +109,13 @@
target.consume(data.first);
return *this;
}
+
+ template<typename Item, typename Tags>
+ ConsumerAdaptor<ITEM, TAG>& operator=(const std::pair<wibble::Singleton<Item>, Tags>& data)
+ {
+ target.consume(*data.first.begin(), data.second);
+ return *this;
+ }
};
template<typename ITEM, typename TAG>
Modified: tagcoll/2.0/tagcoll/Patches.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.cc (original)
+++ tagcoll/2.0/tagcoll/Patches.cc Fri May 5 06:58:17 2006
@@ -54,7 +54,7 @@
"d: c::D, c::d, e::F\n"
);
InputMerger<string, string> result;
- PatchList<string, string> patches(result);
+ PatchList<string, string> patches;
std::set<string> added;
std::set<string> removed;
@@ -71,7 +71,7 @@
removed.clear(); removed.insert("f::g");
patches.addPatch(Patch<string, string>("d", added, removed));
- outputCollection(input_coll, patches);
+ parseCollection(input_coll, patcher(patches, consumer(result)));
InputMerger<string, string> reference;
outputCollection(output_coll, reference);
@@ -81,6 +81,7 @@
}
+#include <tagcoll/TextFormat.tcc>
#include <tagcoll/Patches.tcc>
#endif
Modified: tagcoll/2.0/tagcoll/Patches.h
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.h (original)
+++ tagcoll/2.0/tagcoll/Patches.h Fri May 5 06:58:17 2006
@@ -47,55 +47,66 @@
std::set<TAG> removed;
public:
- Patch(const Patch<ITEM, TAG>& p) throw () : item(p.item), added(p.added), removed(p.removed) {}
- Patch(const ITEM& item) throw () : item(item) {}
- Patch(const ITEM& item, const std::set<TAG>& added, const std::set<TAG>& removed) throw ()
+ Patch(const Patch<ITEM, TAG>& p) : item(p.item), added(p.added), removed(p.removed) {}
+ Patch(const ITEM& item) : item(item) {}
+ Patch(const ITEM& item, const std::set<TAG>& added, const std::set<TAG>& removed)
: item(item), added(added-removed), removed(removed-added) {}
~Patch() {}
- void add(const TAG& tag) throw ()
+ void add(const TAG& tag)
{
using namespace wibble::operators;
added |= tag; removed -= tag;
}
- void add(const std::set<TAG>& tags) throw ()
+ void add(const std::set<TAG>& tags)
{
using namespace wibble::operators;
added |= tags; removed -= tags;
}
- void remove(const TAG& tag) throw ()
+ void remove(const TAG& tag)
{
using namespace wibble::operators;
removed |= tag; added -= tag;
}
- void remove(const std::set<TAG>& tags) throw ()
+ void remove(const std::set<TAG>& tags)
{
using namespace wibble::operators;
removed |= tags; added -= tags;
}
- const ITEM& getItem() const throw () { return item; }
- const std::set<TAG>& getAdded() const throw () { return added; }
- const std::set<TAG>& getRemoved() const throw () { return removed; }
+ const ITEM& getItem() const { return item; }
+ const std::set<TAG>& getAdded() const { return added; }
+ const std::set<TAG>& getRemoved() const { return removed; }
- Patch<ITEM, TAG> getReverse() const throw ()
+ Patch<ITEM, TAG> getReverse() const
{
return Patch<ITEM, TAG>(item, removed, added);
}
- void mergeWith(const Patch<ITEM, TAG>& patch) throw ()
+ void mergeWith(const Patch<ITEM, TAG>& patch)
{
add(patch.getAdded());
remove(patch.getRemoved());
}
- std::set<TAG> apply(const std::set<TAG>& ts) const throw ()
+ std::set<TAG> apply(const std::set<TAG>& ts) const
{
using namespace wibble::operators;
return (ts | added) - removed;
}
- void removeRedundant(const std::set<TAG> ts) throw ()
+ template<typename TAGS>
+ std::set<TAG> apply(const TAGS& tags) const
+ {
+ using namespace wibble::operators;
+ std::set<TAG> ts;
+ for (typename TAGS::const_iterator i = tags.begin();
+ i != tags.end(); ++i)
+ ts.insert(*i);
+ return (ts | added) - removed;
+ }
+
+ void removeRedundant(const std::set<TAG> ts)
{
using namespace wibble::operators;
// Don't add what already exists
@@ -109,23 +120,11 @@
* List of patches that can be applied to a TaggedCollection
*/
template <class ITEM, class TAG>
-class PatchList : public std::map<ITEM, Patch<ITEM, TAG> >, public Filter<ITEM, TAG>
+class PatchList : public std::map<ITEM, Patch<ITEM, TAG> >
{
-protected:
- /// Process an untagged item
- virtual void consumeItemUntagged(const ITEM& item);
-
- /// Process a tagged item, with its tags
- virtual void consumeItem(const ITEM& item, const std::set<TAG>& tags);
-
public:
- PatchList() : Filter<ITEM, TAG>() {}
- PatchList(Consumer<ITEM, TAG>& consumer) : Filter<ITEM, TAG>(consumer) {}
- PatchList(const PatchList& pl) : std::map<ITEM, Patch<ITEM, TAG> >(pl), Filter<ITEM, TAG>(pl) {}
- PatchList(const PatchList& pl, Consumer<ITEM, TAG>& consumer) :
- std::map<ITEM, Patch<ITEM, TAG> >(pl),
- Filter<ITEM, TAG>(consumer) {}
- virtual ~PatchList() throw () {}
+ PatchList() {}
+ PatchList(const PatchList& pl) : std::map<ITEM, Patch<ITEM, TAG> >(pl) {}
typedef typename std::map<ITEM, Patch<ITEM, TAG> >::const_iterator const_iterator;
typedef typename std::map<ITEM, Patch<ITEM, TAG> >::iterator iterator;
@@ -133,17 +132,17 @@
/**
* Add to this patchlist the patches needed to transform `im1' in `im2'
*/
- void addPatch(const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2) throw ();
+ void addPatch(const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2);
/**
* Add `patch' to this PatchList
*/
- void addPatch(const Patch<ITEM, TAG>& patch) throw ();
+ void addPatch(const Patch<ITEM, TAG>& patch);
/**
* Add `patches' to this PatchList
*/
- void addPatch(const PatchList<ITEM, TAG>& patches) throw ();
+ void addPatch(const PatchList<ITEM, TAG>& patches);
/**
* Patch a tagged item
@@ -151,14 +150,14 @@
* @return
* The new (patched) set of tags
*/
- std::set<TAG> patch(const ITEM& item, const std::set<TAG>& tagset) const throw ();
+ std::set<TAG> patch(const ITEM& item, const std::set<TAG>& tagset) const;
/*
// Output the patch list to a TagcollConsumer
void output(TagcollConsumer<ITEM, std::string>& consumer) const throw ();
*/
- PatchList<ITEM, TAG> getReverse() const throw ();
+ PatchList<ITEM, TAG> getReverse() const;
};
template<typename ITEM, typename TAG, typename OUT>
@@ -167,10 +166,11 @@
OUT out;
const PatchList<ITEM, TAG>& patches;
public:
- Patcher(const OUT& out, const PatchList<ITEM, TAG>& patches)
+ Patcher(const PatchList<ITEM, TAG>& patches, const OUT& out)
: out(out), patches(patches) {}
Patcher<ITEM, TAG, OUT>& operator++() { return *this; }
+ Patcher<ITEM, TAG, OUT>& operator*() { return *this; }
template<typename Items, typename Tags>
Patcher<ITEM, TAG, OUT>& operator=(const std::pair<Items, Tags>& data)
@@ -178,7 +178,13 @@
for (typename Items::const_iterator i = data.first.begin();
i != data.first.end(); ++i)
{
- out = make_pair(wibble::singleton(*i), patches.patch(data.second));
+ // Find the patch record for this item
+ typename PatchList<ITEM, TAG>::const_iterator p = patches.find(*i);
+ if (p == patches.end())
+ // If there are no patches, return the tagset unchanged
+ out = data;
+ else
+ out = make_pair(wibble::singleton(*i), p->second.apply(data.second));
++out;
}
return *this;
@@ -186,9 +192,9 @@
};
template<typename ITEM, typename TAG, typename OUT>
-Patcher<ITEM, TAG, OUT> patcher(const OUT& out, const PatchList<ITEM, TAG>& patches)
+Patcher<ITEM, TAG, OUT> patcher(const PatchList<ITEM, TAG>& patches, const OUT& out)
{
- return Patcher<ITEM, TAG, OUT>(out, patches);
+ return Patcher<ITEM, TAG, OUT>(patches, out);
}
};
Modified: tagcoll/2.0/tagcoll/Patches.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.tcc (original)
+++ tagcoll/2.0/tagcoll/Patches.tcc Fri May 5 06:58:17 2006
@@ -50,12 +50,12 @@
target.addPatch(Patch<ITEM, TAG>(item, added, removed));
}
public:
- PatchGenerator(PatchList<ITEM, TAG>& target, const ReadonlyCollection<ITEM, TAG>& second) throw ()
+ 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) throw ()
+void PatchList<ITEM, TAG>::addPatch(const Patch<ITEM, TAG>& patch)
{
// Filter out empty patches
if (patch.getAdded().empty() && patch.getRemoved().empty())
@@ -69,7 +69,7 @@
}
template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::addPatch(const PatchList<ITEM, TAG>& patches) throw ()
+void PatchList<ITEM, TAG>::addPatch(const PatchList<ITEM, TAG>& patches)
{
for (typename PatchList<ITEM, TAG>::const_iterator i = patches.begin();
i != patches.end(); i++)
@@ -78,14 +78,14 @@
template <class ITEM, class TAG>
void PatchList<ITEM, TAG>::addPatch(
- const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2) throw ()
+ const ReadonlyCollection<ITEM, TAG>& im1, const ReadonlyCollection<ITEM, TAG>& im2)
{
PatchGenerator<ITEM, TAG> patchgen(*this, im2);
im1.output(patchgen);
}
template <class ITEM, class TAG>
-std::set<TAG> PatchList<ITEM, TAG>::patch(const ITEM& item, const std::set<TAG>& tagset) const throw ()
+std::set<TAG> PatchList<ITEM, TAG>::patch(const ITEM& item, const std::set<TAG>& tagset) const
{
// Find the patch record for this item
const_iterator p = this->find(item);
@@ -98,7 +98,7 @@
}
template <class ITEM, class TAG>
-PatchList<ITEM, TAG> PatchList<ITEM, TAG>::getReverse() const throw ()
+PatchList<ITEM, TAG> PatchList<ITEM, TAG>::getReverse() const
{
PatchList<ITEM, TAG> res;
for (typename PatchList<ITEM, TAG>::const_iterator i = this->begin();
@@ -110,14 +110,14 @@
/*
template <class ITEM>
-void PatchList<ITEM>::consume(const ITEM& item, const std::set<string>& tags) throw ()
+void PatchList<ITEM>::consume(const ITEM& item, const std::set<string>& tags)
{
patches.insert(make_pair(item, tags));
}
// Output the patch list to a TagcollConsumer
template <class ITEM>
-void PatchList<ITEM>::output(TagcollConsumer<ITEM, std::string>& consumer) const throw ()
+void PatchList<ITEM>::output(TagcollConsumer<ITEM, std::string>& consumer) const
{
for (typename map< ITEM, std::set<string> >::const_iterator i = patches.begin();
i != patches.end(); i++)
@@ -128,28 +128,6 @@
}
*/
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::consumeItemUntagged(const ITEM& item)
-{
- std::set<TAG> patched = patch(item, std::set<TAG>());
-
- if (patched.size())
- this->consumer->consume(item, patched);
- else
- this->consumer->consume(item);
-}
-
-template <class ITEM, class TAG>
-void PatchList<ITEM, TAG>::consumeItem(const ITEM& item, const std::set<TAG>& tags)
-{
- std::set<TAG> patched = patch(item, tags);
-
- if (patched.size())
- this->consumer->consume(item, patched);
- else
- this->consumer->consume(item);
-}
-
}
// vim:set ts=4 sw=4:
More information about the Debtags-commits
mailing list