Skip to content

Commit

Permalink
libdeng2: Cleaner text representation of Records
Browse files Browse the repository at this point in the history
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 ':'.
  • Loading branch information
skyjake committed Nov 30, 2012
1 parent e70b397 commit 06e0e59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
17 changes: 6 additions & 11 deletions doomsday/libdeng2/src/data/record.cpp
Expand Up @@ -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<RecordValue &>(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 "";
}
Expand All @@ -373,15 +368,15 @@ 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)
{
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;
Expand Down
7 changes: 5 additions & 2 deletions doomsday/libdeng2/src/data/recordvalue.cpp
Expand Up @@ -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();
}

Expand All @@ -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();
}
Expand Down

0 comments on commit 06e0e59

Please sign in to comment.