Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
json_utils.h
1//
2// Created by Manuel on 08.02.2021.
3//
4// Helper functions for rapidjson elements
5
6#ifndef WIZARD_JSON_UTILS_H
7#define WIZARD_JSON_UTILS_H
8
9#include <string>
10
11#include "../../rapidjson/include/rapidjson/writer.h"
12#include "../../rapidjson/include/rapidjson/document.h"
13#include "../../rapidjson/include/rapidjson/stringbuffer.h"
14
15
17public:
18 static std::string to_string(const rapidjson::Value* json) {
19 rapidjson::StringBuffer buffer;
20 buffer.Clear();
21 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
22 json->Accept(writer);
23 return buffer.GetString();
24 }
25
26 // In case you need to create a rapidjson::Document on the heap (pointer) based on a value extracted from a json.
27 static rapidjson::Document* clone_value(const rapidjson::Value& val) {
28 rapidjson::Document* state_json = new rapidjson::Document(rapidjson::kObjectType);
29 state_json->CopyFrom(val, state_json->GetAllocator());
30 return state_json;
31 }
32
33};
34
35#endif //WIZARD_JSON_UTILS_H
Definition json_utils.h:16