From 2882d78755b860399e99ac13c58c7530eff26c98 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 24 Oct 2015 03:15:35 +0200 Subject: [PATCH] implementation: simplest case (insert element) ...so now the stage is set. We can reimplement the handling of the list diff cases here in the context of tree diff application. The additional twist of course being the distinction between attribute and child scope --- src/lib/diff/record-content-mutator.hpp | 6 ++++++ src/lib/diff/record.hpp | 8 ++++++++ src/lib/diff/tree-diff-application.hpp | 9 ++++++++- tests/library/diff/generic-record-update-test.cpp | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/diff/record-content-mutator.hpp b/src/lib/diff/record-content-mutator.hpp index 05b79dfee..e0b93d109 100644 --- a/src/lib/diff/record-content-mutator.hpp +++ b/src/lib/diff/record-content-mutator.hpp @@ -119,6 +119,12 @@ namespace diff{ pos = attribs.begin(); } + void + jumpToChildScope() + { + pos = children.begin(); + } + void preAllocateStorage(size_t attribCnt, size_t childrenCnt) { diff --git a/src/lib/diff/record.hpp b/src/lib/diff/record.hpp index 7fe87d1e0..98633e32b 100644 --- a/src/lib/diff/record.hpp +++ b/src/lib/diff/record.hpp @@ -439,6 +439,14 @@ namespace diff{ return *this; } + Mutator& + appendAttrib (VAL const& newAttrib) + { + REQUIRE (Rec::isAttribute(newAttrib)); + record_.attribs_.push_back (newAttrib); + return *this; + } + Mutator& appendChild (VAL const& newChild) { diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index b782ad986..d5152beef 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -95,7 +95,14 @@ namespace diff{ void ins (GenNode const& n) override { - UNIMPLEMENTED("insert node"); + if (n.isNamed()) + target_.appendAttrib(n); + else + { + target_.appendChild(n); + if (content_.currIsAttrib()) + content_.jumpToChildScope(); + } } void diff --git a/tests/library/diff/generic-record-update-test.cpp b/tests/library/diff/generic-record-update-test.cpp index 582e210da..ea61e6ee5 100644 --- a/tests/library/diff/generic-record-update-test.cpp +++ b/tests/library/diff/generic-record-update-test.cpp @@ -147,6 +147,10 @@ namespace test{ CHECK (rawElm == & *content.pos); ++content; CHECK ("b = β" == *content.pos); + content.jumpToChildScope(); + CHECK ("γ" == *content.pos); + CHECK (!content.currIsAttrib()); + CHECK (content.currIsChild()); CHECK ( isnil (mut)); CHECK (!isnil (content));