Switched to a new coding style, which plays nicely with the Reader/Writer. This new style allows REFLECT to be used instead of REFLECT_N in most places.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@15 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-11 22:26:55 +00:00
parent 33abea6221
commit 9de743030e
51 changed files with 1041 additions and 767 deletions
+10 -8
View File
@@ -16,7 +16,7 @@ Writer::Writer(const OutputStreamP& output)
: output(output)
, stream(*output)
, indentation(0)
, justOpened(false)
, just_opened(false)
{
stream.WriteString(BYTE_ORDER_MARK);
}
@@ -24,25 +24,27 @@ Writer::Writer(const OutputStreamP& output)
void Writer::enterBlock(const Char* name) {
// indenting into a sub-block?
if (justOpened) {
if (just_opened) {
writeKey();
stream.WriteString(_(":\n"));
}
// don't write the key yet
indentation += 1;
openedKey = name;
justOpened = true;
opened_key = name;
just_opened = true;
}
void Writer::exitBlock() {
assert(indentation > 0);
indentation -= 1;
justOpened = false;
just_opened = false;
}
void Writer::writeKey() {
writeIndentation();
writeUTF8(stream, openedKey);
// Use ' ' instead of '_' because it is more human readable
FOR_EACH(c, opened_key) if (c == _('_')) c = _(' ');
writeUTF8(stream, opened_key);
}
void Writer::writeIndentation() {
for(int i = 1 ; i < indentation ; ++i) {
@@ -53,7 +55,7 @@ void Writer::writeIndentation() {
// ----------------------------------------------------------------------------- : Handling basic types
void Writer::handle(const String& value) {
if (!justOpened) {
if (!just_opened) {
throw InternalError(_("Can only write a value in a key that was just opened"));
}
// write indentation and key
@@ -86,7 +88,7 @@ void Writer::handle(const String& value) {
writeUTF8(stream, value);
}
stream.PutChar(_('\n'));
justOpened = false;
just_opened = false;
}
template <> void Writer::handle(const int& value) {