From 06e0e59ea5616531919b9387b4affeab5d46a36e Mon Sep 17 00:00:00 2001 From: skyjake Date: Fri, 30 Nov 2012 11:47:59 +0200 Subject: [PATCH] libdeng2: Cleaner text representation of Records Records are converted to text in a way that retains the structure of the record more clearly: both subrecords and referenced records are printed as an indented block. Furthermore, a subrecord uses '.' as the separator in the output while referenced records (and other values) use ':'. --- doomsday/libdeng2/src/data/record.cpp | 17 ++++++----------- doomsday/libdeng2/src/data/recordvalue.cpp | 7 +++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/doomsday/libdeng2/src/data/record.cpp b/doomsday/libdeng2/src/data/record.cpp index ac1ae534bf..8818c352bf 100644 --- a/doomsday/libdeng2/src/data/record.cpp +++ b/doomsday/libdeng2/src/data/record.cpp @@ -340,15 +340,10 @@ String Record::asText(String const &prefix, List *lines) const // Collect lines from this record. for(Members::const_iterator i = d->members.begin(); i != d->members.end(); ++i) { - if(d->isSubrecord(*i->second)) - { - static_cast(i->second->value()).record()->asText(i->first.concatenateMember(""), lines); - } - else - { - KeyValue kv(prefix + i->first, i->second->value().asText()); - lines->push_back(kv); - } + String separator = (d->isSubrecord(*i->second)? "." : ":"); + + KeyValue kv(prefix + i->first + separator, i->second->value().asText()); + lines->push_back(kv); } return ""; } @@ -373,7 +368,7 @@ String Record::asText(String const &prefix, List *lines) const for(List::iterator i = allLines.begin(); i != allLines.end(); ++i) { if(i != allLines.begin()) os << "\n"; - os << qSetFieldWidth(maxLength.x) << i->first << qSetFieldWidth(0) << ": "; + os << qSetFieldWidth(maxLength.x) << i->first << qSetFieldWidth(0) << " "; // Print the value line by line. int pos = 0; while(pos >= 0) @@ -381,7 +376,7 @@ String Record::asText(String const &prefix, List *lines) const int next = i->second.indexOf('\n', pos); if(pos > 0) { - os << qSetFieldWidth(maxLength.x) << "" << qSetFieldWidth(0) << " "; + os << qSetFieldWidth(maxLength.x) << "" << qSetFieldWidth(0) << " "; } os << i->second.substr(pos, next != String::npos? next - pos + 1 : next); pos = next; diff --git a/doomsday/libdeng2/src/data/recordvalue.cpp b/doomsday/libdeng2/src/data/recordvalue.cpp index fc78a8ab8b..bcdf0b6ea2 100644 --- a/doomsday/libdeng2/src/data/recordvalue.cpp +++ b/doomsday/libdeng2/src/data/recordvalue.cpp @@ -178,10 +178,13 @@ dint RecordValue::compare(Value const &value) const return cmp(recValue->_record, _record); } +// Flags for serialization: +static duint8 const OWNS_RECORD = 0x1; + void RecordValue::operator >> (Writer &to) const { duint8 flags = 0; - if(hasOwnership()) flags |= OwnsRecord; + if(hasOwnership()) flags |= OWNS_RECORD; to << SerialId(RECORD) << flags << dereference(); } @@ -199,7 +202,7 @@ void RecordValue::operator << (Reader &from) // Old flags. duint8 flags = 0; from >> flags; - _oldOwnership = OwnershipFlags(flags & OwnsRecord? OwnsRecord : 0); + _oldOwnership = OwnershipFlags(flags & OWNS_RECORD? OwnsRecord : 0); from >> dereference(); }