-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCSerializable.cpp
More file actions
executable file
·85 lines (63 loc) · 2.72 KB
/
CSerializable.cpp
File metadata and controls
executable file
·85 lines (63 loc) · 2.72 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// CSerializable.cpp
// Fifth
//
// Created by Didrik Munther on 23/11/15.
// Copyright © 2015 Didrik Munther. All rights reserved.
//
#include "CSerializable.h"
#include <iostream>
void CSerializable::removeDuplicates(rapidjson::Value* value, const rapidjson::Value* valueBefore) {
for(rapidjson::Value::ConstMemberIterator i = value->MemberBegin(); i != value->MemberEnd(); i++) {
const rapidjson::Value* v = &i->value;
std::string n = i->name.GetString();
std::cout << (valueBefore == nullptr) << "\n";
if(!valueBefore->HasMember(n.c_str()))
continue;
if(v->IsObject()) {
if((*valueBefore)[n.c_str()].IsObject()) {
const rapidjson::Value* tempValue = &(*valueBefore)[n.c_str()];
std::remove_const<rapidjson::Value*>::type v;
removeDuplicates(v, tempValue);
}
continue;
}
if(v->IsString()) {
if((*valueBefore)[n.c_str()].IsString()) {
if(v->GetString() == (*valueBefore)[n.c_str()].GetString())
value->RemoveMember(n.c_str());
}
continue;
}
if(v->IsInt()) {
if((*valueBefore)[n.c_str()].IsInt()) {
if(v->GetInt() == (*valueBefore)[n.c_str()].GetInt())
value->RemoveMember(n.c_str());
}
continue;
}
if(v->IsDouble()) {
if((*valueBefore)[n.c_str()].IsDouble()) {
if(v->GetDouble() == (*valueBefore)[n.c_str()].GetDouble())
value->RemoveMember(n.c_str());
}
continue;
}
}
}
void CSerializable::assignString(const rapidjson::Value* value, std::string key, std::string* toAssign) {
if(!value->HasMember(key.c_str()) && !value->IsString())
return;
*toAssign = (*value)[key.c_str()].GetString();
}
void CSerializable::assignFloat(const rapidjson::Value* value, std::string key, float* toAssign) {
if(!value->HasMember(key.c_str()) && (!value->IsDouble() || !value->IsInt()))
return;
*toAssign = (*value)[key.c_str()].GetDouble();
}
void CSerializable::addString(rapidjson::Value* value, rapidjson::Document::AllocatorType* alloc, std::string key, std::string toAdd) {
value->AddMember(rapidjson::Value(key.c_str(), *alloc), rapidjson::Value(toAdd.c_str(), *alloc), *alloc);
}
void CSerializable::addValue(rapidjson::Value* value, rapidjson::Document::AllocatorType* alloc, std::string key, rapidjson::Value* toAdd) {
value->AddMember(rapidjson::Value(key.c_str(), *alloc), *toAdd, *alloc);
}