From 0e769601b7d421a1450bccef470c982b44a8f140 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 30 Oct 2015 05:10:16 +0100 Subject: [PATCH] add explicit handling to change the typeID the type is the only meta attribute supported by now, thus the decision was to handle this manually, instead of introducing a full scope for meta attributes. Unfortunately this leads to an assymetry: while it is possible to send an attribute named "type", which will be intercepted and used as a new type ID, the type will not show up when iterating or searching through attributes. When applying a diff, the only possibility is to *insert* a new type attribute, and we need to check and handle this likewise manually. --- src/lib/diff/gen-node.hpp | 10 ++++++++-- src/lib/diff/tree-diff-application.hpp | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index 95c90c6bd..d4edb64be 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -276,6 +276,12 @@ namespace diff{ return not util::startsWith (idi.getSym(), "_CHILD_"); } + bool + isTypeID() const + { + return "type" == idi.getSym(); + } + template bool contains (X const& elm) const; @@ -624,9 +630,9 @@ namespace diff{ template<> inline bool - Rec::isTypeID (GenNode const& v) + Rec::isTypeID (GenNode const& attrib) { - return "type" == v.idi.getSym(); + return attrib.isTypeID(); } template<> diff --git a/src/lib/diff/tree-diff-application.hpp b/src/lib/diff/tree-diff-application.hpp index 00c24fb35..564b4419e 100644 --- a/src/lib/diff/tree-diff-application.hpp +++ b/src/lib/diff/tree-diff-application.hpp @@ -168,7 +168,7 @@ namespace diff{ void __expect_end_of_scope (GenNode::ID const& idi) { - if (!endOfData()) + if (not endOfData()) throw error::State(_Fmt("Incomplete diff: when about to leave scope %s, " "not all previously existing elements have been confirmed by the diff. " "At least one spurious element %s was left over") % idi.getSym() % *srcPos() @@ -213,7 +213,10 @@ namespace diff{ ins (GenNode const& n) override { if (n.isNamed()) - out().appendAttrib(n); + if (n.isTypeID()) + out().setType (n.data.get()); + else + out().appendAttrib(n); else { out().appendChild(n);