1#define RAPIDJSON_HAS_STDSTRING 1
4#include "rapidjson/document.h"
5#include "rapidjson/istreamwrapper.h"
6#include "rapidjson/prettywriter.h"
52 std::cout <<
value << std::endl;
83 v.SetString(
value.c_str(), d.GetAllocator());
91 value = v.GetString();
101 v.AddMember(
"TypeId",
GetName(d), d.GetAllocator());
103 for (
auto& element : p) {
105 n.SetString(element.name, d.GetAllocator());
106 if (element.value !=
nullptr)
107 v.AddMember(n, element.value->ToDom(d), d.GetAllocator());
117 for (
auto& element : p) {
118 element.value->FromDom(v[element.name], d);
128 for (
auto& element :
value) {
131 a.PushBack(v, d.GetAllocator());
139 for (rapidjson::SizeType i = 0; i < v.Size();
141 value.push_back(v[i].GetInt());
150 for (
auto& element :
value) {
153 a.PushBack(v, d.GetAllocator());
161 for (rapidjson::SizeType i = 0; i < v.Size();
163 value.push_back(v[i].GetFloat());
172 for (
auto& element :
value) {
174 v.SetDouble(element);
175 a.PushBack(v, d.GetAllocator());
183 for (rapidjson::SizeType i = 0; i < v.Size();
185 value.push_back(v[i].GetDouble());
208 rapidjson::Document document;
209 document.SetObject();
213 document.AddMember(
"TypeId", top->
GetName(document),
214 document.GetAllocator());
216 for (
auto& element : p) {
218 n.SetString(element.name, document.GetAllocator());
219 if (element.value !=
nullptr)
220 document.AddMember(n, element.value->ToDom(document),
221 document.GetAllocator());
224 rapidjson::StringBuffer sb;
226 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
229 std::fstream jsonout(filename, std::ios_base::out);
230 jsonout << sb.GetString() << std::endl;
237 rapidjson::Document document;
239 std::ifstream ifs(filename);
240 rapidjson::IStreamWrapper isw(ifs);
242 document.ParseStream(isw);
244 if (document.IsObject()) {
245 for (
auto& element : p) {
246 element.value->FromDom(document[element.name], document);
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
int AddConstructor(std::string name, ISValuePtr(*creator)())
ISValuePtr GetObject(std::string name)
std::map< std::string, Json::ISValuePtr(*)()> m_TheRegistry
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
std::vector< double > & value
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
std::vector< float > & value
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
std::vector< int > & value
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
Rflection is made possible by the help of the ISValue class and the type classes.
virtual rapidjson::Value ToDom(rapidjson::Document &d)
ToDom is the function that enables the serializer to take data from the application to the JSON file.
virtual ISProperties GetProperty()
GetProperty enables the serializer to deal with composite type like objects and members.
virtual void FromDom(rapidjson::Value &v, rapidjson::Document &d)
FromDom is the function that enables the serializer to get data out of the JSON file and put it in th...
virtual rapidjson::Value GetName(rapidjson::Document &d)
For future expansion.
void deserialize(std::string filename, ISValue *p)
Function to start deserializing a file.
void serialize(std::string filename, ISValue *p)
Function to start serializing an onbject.
std::vector< ISProperty > ISProperties
ISProperties is a vector with ISProperty.
std::shared_ptr< ISValue > ISValuePtr