[Debtags-commits] [svn] r2076 - in tagcoll/2.0: . tagcoll/stream
Enrico Zini
enrico at alioth.debian.org
Fri Nov 17 16:08:17 CET 2006
Author: enrico
Date: Fri Nov 17 16:08:17 2006
New Revision: 2076
Modified:
tagcoll/2.0/ (props changed)
tagcoll/2.0/tagcoll/stream/patcher.h
Log:
r3648 at viaza: enrico | 2006-11-17 16:06:12 +0100
Stream patcher now detects the items that are introduced by the patch but not present in the input collection, and streams them out in the destructor. (ugly. The stream patcher should probably be declared deprecated in its current state; however, if it's used only on one-liner streams, the destructor is called right away and it can work)
Modified: tagcoll/2.0/tagcoll/stream/patcher.h
==============================================================================
--- tagcoll/2.0/tagcoll/stream/patcher.h (original)
+++ tagcoll/2.0/tagcoll/stream/patcher.h Fri Nov 17 16:08:17 2006
@@ -36,9 +36,30 @@
{
OUT out;
const PatchList<ITEM, TAG>& patches;
+ std::set<ITEM> newItems;
+
public:
Patcher(const PatchList<ITEM, TAG>& patches, const OUT& out)
- : out(out), patches(patches) {}
+ : out(out), patches(patches)
+ {
+ // Take note of the items that could possibly be introduced by the patch
+ for (typename PatchList<ITEM, TAG>::const_iterator i = patches.begin();
+ i != patches.end(); ++i)
+ if (!i->second.added.empty())
+ newItems.insert(i->first);
+ }
+ ~Patcher()
+ {
+ // Insert the items that were not present in the collection we got in
+ // input
+ for (typename std::set<ITEM>::const_iterator i = newItems.begin();
+ i != newItems.end(); ++i)
+ {
+ typename PatchList<ITEM, TAG>::const_iterator j = patches.find(*i);
+ *out = make_pair(wibble::singleton(*i), j->second.added);
+ ++out;
+ }
+ }
template<typename Items, typename Tags>
Patcher<ITEM, TAG, OUT>& operator=(const std::pair<Items, Tags>& data)
@@ -46,6 +67,7 @@
for (typename Items::const_iterator i = data.first.begin();
i != data.first.end(); ++i)
{
+ newItems.erase(*i);
// Find the patch record for this item
typename PatchList<ITEM, TAG>::const_iterator p = patches.find(*i);
if (p == patches.end())
More information about the Debtags-commits
mailing list