51 #ifndef JSON11_HPP_INCLUDE
52 #define JSON11_HPP_INCLUDE
59 #include <initializer_list>
64 #define noexcept throw()
68 #define snprintf _snprintf_s
85 NUL, NUMBER, BOOL, STRING, ARRAY, OBJECT
89 typedef std::vector<Json> array;
90 typedef std::map<std::string, Json> object;
94 Json(std::nullptr_t) noexcept;
98 Json(const std::
string &value);
99 Json(std::
string &&value);
100 Json(const
char * value);
101 Json(const array &values);
102 Json(array &&values);
103 Json(const
object &values);
104 Json(
object &&values);
107 template <class T, class = decltype(&T::to_json)>
108 Json(const T & t) : Json(t.to_json()) {}
111 template <
class M,
typename std::enable_if<
112 std::is_constructible<std::string, decltype(std::declval<M>().begin()->first)>::value
113 && std::is_constructible<Json, decltype(std::declval<M>().begin()->second)>::value,
115 Json(
const M & m) : Json(
object(m.begin(), m.end())) {}
118 template <
class V,
typename std::enable_if<
119 std::is_constructible<Json, decltype(*std::declval<V>().begin())>::value,
121 Json(
const V & v) : Json(array(v.begin(), v.end())) {}
125 Json(
void *) =
delete;
130 bool is_null()
const {
return type() == NUL; }
131 bool is_number()
const {
return type() == NUMBER; }
132 bool is_bool()
const {
return type() == BOOL; }
133 bool is_string()
const {
return type() == STRING; }
134 bool is_array()
const {
return type() == ARRAY; }
135 bool is_object()
const {
return type() == OBJECT; }
140 double number_value()
const;
141 int int_value()
const;
144 bool bool_value()
const;
146 const std::string &string_value()
const;
148 const array &array_items()
const;
150 const object &object_items()
const;
153 const Json & operator[](
size_t i)
const;
155 const Json & operator[](
const std::string &key)
const;
158 void dump(std::string &out)
const;
159 std::string dump()
const {
166 static Json parse(
const std::string & in,
169 static Json parse(
const char * in,
173 return parse(std::string(in), err, strategy);
180 static std::vector<Json> parse_multi(
181 const std::string & in,
182 std::string::size_type & parser_stop_pos,
186 static inline std::vector<Json> parse_multi(
187 const std::string & in,
190 std::string::size_type parser_stop_pos;
191 return parse_multi(in, parser_stop_pos, err, strategy);
194 bool operator== (
const Json &rhs)
const;
195 bool operator< (
const Json &rhs)
const;
196 bool operator!= (
const Json &rhs)
const {
return !(*
this == rhs); }
197 bool operator<= (
const Json &rhs)
const {
return !(rhs < *
this); }
198 bool operator> (
const Json &rhs)
const {
return (rhs < *
this); }
199 bool operator>= (
const Json &rhs)
const {
return !(*
this < rhs); }
206 typedef std::initializer_list<std::pair<std::string, Type>> shape;
207 bool has_shape(
const shape & types, std::string & err)
const;
210 std::shared_ptr<JsonValue> m_ptr;
219 virtual Json::Type
type()
const = 0;
222 virtual void dump(std::string &out)
const = 0;
230 virtual const Json &
operator[](
const std::string &key)
const;
Definition: json11.hpp:214
virtual bool less(const JsonValue *other) const =0
virtual bool equals(const JsonValue *other) const =0
virtual bool bool_value() const
friend class JsonInt
Definition: json11.hpp:217
virtual void dump(std::string &out) const =0
virtual const Json::array & array_items() const
friend class JsonDouble
Definition: json11.hpp:218
friend class Json
Definition: json11.hpp:216
virtual ~JsonValue()
Definition: json11.hpp:231
virtual int int_value() const
virtual const std::string & string_value() const
virtual Json::Type type() const =0
virtual const Json & operator[](const std::string &key) const
virtual const Json & operator[](size_t i) const
virtual double number_value() const
virtual const Json::object & object_items() const
Definition: json11.hpp:73
JsonParse
Definition: json11.hpp:75
@ STANDARD
Definition: json11.hpp:76
@ COMMENTS
Definition: json11.hpp:76
class __attribute__((visibility("default"))) Json final
Definition: json11.hpp:81