OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
json.hpp
1#pragma once
2#include <ossia/detail/config.hpp>
3
4#include <ossia/detail/string_view.hpp>
5#if defined(_WIN32)
6#include <windows.h>
7
8#ifdef GetObject
9#undef GetObject
10#endif
11
12// Yay for windows defining uuid_t macro
13#ifdef uuid_t
14#undef uuid_t
15#endif
16
17#endif
18#include <rapidjson/document.h>
19#include <rapidjson/writer.h>
20
21#include <cstring>
22
23namespace ossia
24{
25using json_writer = rapidjson::Writer<
26 rapidjson::StringBuffer, rapidjson::UTF8<>, rapidjson::UTF8<>,
27 rapidjson::CrtAllocator, rapidjson::WriteFlag::kWriteNanAndInfFlag>;
28}
29inline std::string get_string(const rapidjson::Value& val)
30{
31 return std::string{val.GetString(), val.GetStringLength()};
32}
33inline std::string_view get_string_view(const rapidjson::Value& val)
34{
35 return std::string_view{val.GetString(), val.GetStringLength()};
36}
37
38inline void write_json_key(ossia::json_writer& writer, std::string_view k)
39{
40 writer.Key(k.data(), k.size());
41}
42
43inline void write_json(ossia::json_writer& writer, std::string_view k)
44{
45 writer.String(k.data(), k.size());
46}
47
48inline void write_json(ossia::json_writer& writer, char c)
49{
50 writer.String(&c, 1);
51}
52
53inline std::string json_to_str(const rapidjson::StringBuffer& other)
54{
55 return {other.GetString(), other.GetSize()};
56}
Definition git_info.h:7