diff --git a/src/lib/diff/record.hpp b/src/lib/diff/record.hpp index b074569e7..d3729fd10 100644 --- a/src/lib/diff/record.hpp +++ b/src/lib/diff/record.hpp @@ -104,6 +104,7 @@ namespace diff{ namespace error = lumiera::error; + using util::isnil; using std::string; template @@ -141,13 +142,15 @@ namespace diff{ Storage children_; public: + static const string TYPE_NIL; + Record() - : type_("NIL") + : type_(TYPE_NIL) { } template Record(Symbol typeID, A&& att, C&& chi) - : type_(typeID) + : type_(isnil(typeID)? TYPE_NIL:string(typeID)) , attribs_(std::forward (att)) , children_(std::forward (chi)) { } @@ -155,7 +158,7 @@ namespace diff{ template Record(Symbol typeID, std::initializer_list const&& att , std::initializer_list const&& chi) - : type_(typeID) + : type_(isnil(typeID)? TYPE_NIL:string(typeID)) , attribs_(att) , children_(chi) { } @@ -163,7 +166,7 @@ namespace diff{ template explicit Record (SEQ const& con) - : type_("NIL") + : type_(TYPE_NIL) { auto p = std::begin(con); auto e = std::end(con); @@ -259,7 +262,7 @@ namespace diff{ using valIter = TransformIter; /** default iteration exposes all data within this "object", starting with the attributes */ - iterator begin () const { return iterator(this, attribs_.begin()); } + iterator begin () const { return iterator(this, attribs_.empty()? children_.begin() : attribs_.begin()); } iterator end () const { return iterator(); } scopeIter attribs() const { return iter_stl::eachElm(attribs_); } @@ -271,9 +274,8 @@ namespace diff{ protected: /* ==== API for the IterAdapter ==== */ /** Implementation of Iteration-logic: pull next element. */ - template friend void - iterNext (const Record* src, ITER& pos) + iterNext (const Record* src, ElmIter& pos) { ++pos; checkPoint (src,pos); @@ -284,22 +286,22 @@ namespace diff{ * the end of the attribute collection. In this implementation, * we use the default constructed \c ITER() to mark iteration end. */ - template friend bool - checkPoint (const Record* src, ITER& pos) + checkPoint (const Record* src, ElmIter& pos) { REQUIRE (src); - if ((pos != ITER()) && (pos == src->attribs_.end()) && !src->children_.empty()) + static const ElmIter END; + if (pos != END && pos == src->attribs_.end() && !src->children_.empty()) { pos = src->children_.begin(); return true; } else - if (pos != ITER() && (pos != src->children_.end())) + if (pos != END && (pos != src->children_.end())) return true; else { - pos = ITER(); + pos = END; return false; } } @@ -340,6 +342,9 @@ namespace diff{ } }; + template + const string Record::TYPE_NIL = "NIL"; + template @@ -620,6 +625,7 @@ namespace diff{ using lib::transformIterator; return "Rec(" + + (TYPE_NIL==type_? "" : type_+"| ") + join (transformIterator (this->attribs(), renderAttribute)) + " |{" + join (this->scope()) diff --git a/tests/15library.tests b/tests/15library.tests index 6c1b9e292..5c8bc91e6 100644 --- a/tests/15library.tests +++ b/tests/15library.tests @@ -215,7 +215,7 @@ END TEST "Generic Object Record" GenericRecordRepresentation_test <" << join (enterprise.keys(), "<->")<" << join (enterprise.vals(), "<->")<" << join (enterprise.scope()," | ")<