Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1#pragma once
2#include <memory>
3#include <string>
4#include <initializer_list>
5#include "NlohmannJsonImpl.h"
6
7namespace Framework {
8
9class IJsonImpl;
10
11class json {
12public:
13 json(); // default is null
14 json(const json&);
15 json(json&&) noexcept;
16 json& operator=(const json&);
17 json& operator=(json&&) noexcept;
18
19 // Primitive constructors
20 json(bool b);
21 json(int i);
22 json(double d);
23 json(const char* s);
24 json(const std::string& s);
25
26 ~json();
27
28 static json object();
29 static json array();
30
31 std::string dump(int indent = -1) const;
32
33 // Access
34 json operator[](const std::string& key) const;
35 json& operator[](const std::string& key);
36
37 // Utilities
38 size_t size() const;
39 bool empty() const;
40
41 bool is_null() const;
42 bool is_object() const;
43 bool is_array() const;
44 bool is_string() const;
45 bool is_boolean() const;
46 bool is_number() const;
47
48
49 template<typename T>
50 T get() const {
51 auto* backend = static_cast<NlohmannJsonImpl*>(impl.get());
52 return backend->raw().get<T>();
53 }
54
55 template<typename T>
56 void get_to(T& out) const {
57 auto* backend = static_cast<NlohmannJsonImpl*>(impl.get());
58 backend->raw().get_to(out);
59 }
60
61 template<typename T>
62 T value(const std::string& key, const T& default_val) const {
63 auto* backend = static_cast<NlohmannJsonImpl*>(impl.get());
64 return backend->raw().value(key, default_val);
65 }
66
67 void push_back(const json& value);
68
69 auto begin() const -> nlohmann::json::const_iterator;
70 auto end() const -> nlohmann::json::const_iterator;
71
72 nlohmann::json& raw();
73 const nlohmann::json& raw() const;
74
75 json(std::initializer_list<std::pair<std::string, json>> init);
76 json& operator=(std::initializer_list<std::pair<std::string, json>> init);
77
78
79
80
81private:
82 explicit json(std::shared_ptr<IJsonImpl> impl);
83 std::shared_ptr<IJsonImpl> impl;
84
85 friend class NlohmannJsonImpl;
86};
87
88} // namespace Framework
const nlohmann::json & raw() const
bool empty() const
json(const json &)
bool is_object() const
bool is_number() const
void get_to(T &out) const
Definition json.h:56
bool is_boolean() const
bool is_array() const
nlohmann::json & raw()
json(json &&) noexcept
size_t size() const
std::string dump(int indent=-1) const
bool is_null() const
static json array()
std::shared_ptr< IJsonImpl > impl
Definition json.h:83
T value(const std::string &key, const T &default_val) const
Definition json.h:62
void push_back(const json &value)
bool is_string() const
T get() const
Definition json.h:50
auto begin() const -> nlohmann::json::const_iterator
auto end() const -> nlohmann::json::const_iterator