-
Notifications
You must be signed in to change notification settings - Fork 52
/
test_main.cpp
65 lines (56 loc) · 1.79 KB
/
test_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
#include "everything_atd.hpp"
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
#include <iostream>
#include <string>
const rapidjson::Document doc_from_json(const std::string &json)
{
rapidjson::Document doc;
doc.Parse(json.c_str());
if (doc.HasParseError())
{
}
return doc;
}
int main()
{
using namespace atd;
Root root;
root.id = "id long";
root.await = false;
root.integer = 43;
root.x___init__ = 3.14;
root.float_with_auto_default = 90.03;
root.float_with_default = 32.1;
root.items = {{1, 2}, {-1, -2}};
root.maybe = 422;
root.extras = {34, 12};
root.answer = 12;
root.aliased = {55, 44};
root.point = {4.4, 1.1};
root.kind = Kind::Types::Root();
root.kinds = {Kind::Types::Amaze({{"one", "two"}}), Kind::Types::Root(), Kind::Types::Root(), Kind::Types::Thing({1})};
root.assoc1 = {{4.12, 1},{2.2, 2}};
root.assoc2 = {{"first", 1}, {"second", 2}};
root.assoc3 = {{1.1, 1}, {2.2, 2}};
root.assoc4 = {{"firstt", 1}, {"secondd", 2}};
root.nullables = {1, std::nullopt, 3};
root.options = {1, 2, std::nullopt};
root.parametrized_record = {2, {1.0, 1.1}};
root.parametrized_tuple = {Kind::Types::Root(), Kind::Types::WOW(), 9};
root.wrapped = 1;
root.aaa = -90;
root.item = 45;
std::string json = root.to_json_string();
// now you turn json into pretty json string
rapidjson::Document doc;
doc.Parse(json.c_str());
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
doc.Accept(writer);
std::cout << "Root: " << buffer.GetString() << std::endl;
std::cout << "Root: " << json << std::endl;
}