/
main.cpp
83 lines (69 loc) · 2.3 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* The Doomsday Engine Project
*
* Copyright (c) 2009-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <de/TextApp>
#include <de/Record>
#include <de/Reader>
#include <de/Writer>
#include <de/TextValue>
#include <de/NumberValue>
#include <de/Variable>
#include <QDebug>
#include <QTextStream>
using namespace de;
int main(int argc, char **argv)
{
try
{
TextApp app(argc, argv);
app.initSubsystems(App::DisablePlugins);
Record rec;
LOG_MSG("Empty record:\n") << rec;
rec.add(new Variable("hello", new TextValue("World!")));
LOG_MSG("With one variable:\n") << rec;
rec.add(new Variable("size", new NumberValue(1024)));
LOG_MSG("With two variables:\n") << rec;
Record rec2;
Block b;
Writer(b) << rec;
LOG_MSG("Serialized record to ") << b.size() << " bytes.";
String str;
QTextStream os(&str);
for(duint i = 0; i < b.size(); ++i)
{
os << dint(b.data()[i]) << " ";
}
LOG_MSG(str);
Reader(b) >> rec2;
LOG_MSG("After being deserialized:\n") << rec2;
Record before;
before.addRecord("subrecord");
before.subrecord("subrecord").set("value", true);
DENG2_ASSERT(before.hasSubrecord("subrecord"));
LOG_MSG("Before copying:\n") << before;
Record copied = before;
DENG2_ASSERT(copied.hasSubrecord("subrecord"));
LOG_MSG("Copied:\n") << copied;
}
catch(Error const &err)
{
qWarning() << err.asText();
}
qDebug() << "Exiting main()...";
return 0;
}