-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializable.cpp
More file actions
60 lines (51 loc) · 1.78 KB
/
Serializable.cpp
File metadata and controls
60 lines (51 loc) · 1.78 KB
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
#include "Serializable.h"
namespace RTE {
int Serializable::CreateSerializable(Reader& reader, bool checkType, bool doCreate, bool skipStartingObject) {
if (checkType && reader.ReadPropValue() != GetClassName()) {
reader.ReportError("Wrong type in Reader when passed to Serializable::Create()");
return -1;
}
if (!skipStartingObject) {
reader.StartObject();
}
while (reader.NextProperty()) {
SetFormattedReaderPosition("in file " + reader.GetCurrentFilePath() + " on line " + reader.GetCurrentFileLine());
std::string propName = reader.ReadPropName();
// We need to check if !propName.empty() because ReadPropName may return "" when it reads an IncludeFile without any properties in case they are all commented out or it's the last line in file.
// Also ReadModuleProperty may return "" when it skips IncludeFile till the end of file.
if (!propName.empty() && ReadProperty(propName, reader) < 0) {
// TODO: Could not match property. Log here!
}
}
return doCreate ? Create() : 0;
}
int Serializable::ReadProperty(const std::string_view& propName, Reader& reader) {
reader.ReadPropValue();
reader.ReportError("Could not match property '" + std::string(propName) + "'!");
return -1;
}
Reader& operator>>(Reader& reader, Serializable& operand) {
operand.Create(reader);
return reader;
}
Reader& operator>>(Reader& reader, Serializable* operand) {
if (operand) {
operand->Create(reader);
}
return reader;
}
Writer& operator<<(Writer& writer, const Serializable& operand) {
operand.Save(writer);
writer.ObjectEnd();
return writer;
}
Writer& operator<<(Writer& writer, const Serializable* operand) {
if (operand) {
operand->Save(writer);
writer.ObjectEnd();
} else {
writer.NoObject();
}
return writer;
}
} // namespace RTE