fix/change DiffApplicator to allow applying several diffs

basically we need a reset-Hook before applying the next diff,
because the existing elements need to be swaped and the
position reset to start
This commit is contained in:
Fischlurch 2015-10-31 05:15:47 +01:00
parent 52b1a2b9ae
commit b149432512
3 changed files with 19 additions and 4 deletions

View file

@ -294,6 +294,7 @@ namespace diff{
void
consume (DIFF&& diff)
{
target_.initDiffApplication();
for ( ; diff; ++diff )
diff->applyTo(target_);
}

View file

@ -162,10 +162,14 @@ namespace diff{
explicit
DiffApplicationStrategy(vector<E>& targetVector)
: seq_(targetVector)
, pos_(seq_.begin())
{ }
void
initDiffApplication()
{
swap (seq_, orig_); // pos_ still refers to original input sequence, which has been moved to orig_
seq_.reserve (targetVector.size() * 120 / 100); // heuristics for storage pre-allocation
swap (seq_, orig_);
seq_.reserve (orig_.size() * 120 / 100); // heuristics for storage pre-allocation
pos_ = orig_.begin();
}
};

View file

@ -102,6 +102,9 @@ namespace diff{
ScopeFrame(Mutator& toModify)
: target(toModify)
, content()
{ }
void init()
{
target.swapContent (content);
}
@ -298,7 +301,7 @@ namespace diff{
__expect_successful_location(n);
if (srcPos()->matches(n))
if (not endOfData() and srcPos()->matches(n))
++src(); // get /after/ an explicitly given position
}
@ -328,6 +331,13 @@ namespace diff{
{
scopes_.emplace(mutableTargetRecord);
}
void
initDiffApplication()
{
REQUIRE (1 == scopes_.size());
scopes_.top().init();
}
};