From 33a6294a9b5b591908dc00edd4a8ae17fbd1f577 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 28 Aug 2015 18:27:23 +0200 Subject: [PATCH] implement the remaining attribute handling functions for Record There is no generic implementation for these functions, since they are highly dependent on the payload used within Record Here we use Record, which turns the whole setup into an recursive data type; we especially rely on the fact that each GenNode has an embedded symbolic ID, and we use this ID to encode the 'key' for named attributes --- src/lib/diff/gen-node.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index 7edc88433..2279ba5cb 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -366,44 +366,46 @@ namespace diff{ template<> inline bool - Rec::isAttribute (GenNode const& v) + Rec::isAttribute (GenNode const& attrib) { - return false; ////TODO + return attrib.isNamed(); } template<> inline bool Rec::isTypeID (GenNode const& v) { - return false; ////TODO + return "type" == v.idi.getSym(); } template<> inline string Rec::extractTypeID (GenNode const& v) { - return "todo"; ////TODO + return isTypeID(v)? v.data.get() + : Rec::TYPE_NIL; } template<> inline string Rec::extractKey (GenNode const& v) { - return v.idi.getSym(); + return isAttribute(v)? v.idi.getSym() + : ""; } template<> inline GenNode const& Rec::extractVal (GenNode const& v) { - return GenNode(v); ///TODO + return v; } template<> inline string Rec::renderAttribute (GenNode const& a) { - return "notyet = todo"; ////TODO + return a.idi.getSym() +" = "+string(a.data); } template<>