57 #include <initializer_list> 60 #if _MSC_VER <= 1800 // VS 2013 62 #define noexcept throw() 66 #define snprintf _snprintf_s 83 NUL, NUMBER, BOOL, STRING, ARRAY, OBJECT
87 typedef std::vector<Json> array;
88 typedef std::map<std::string, Json> object;
92 Json(std::nullptr_t) noexcept;
96 Json(
const std::string &value);
97 Json(std::string &&value);
98 Json(
const char * value);
99 Json(
const array &values);
100 Json(array &&values);
101 Json(
const object &values);
102 Json(
object &&values);
105 template <
class T,
class = decltype(&T::to_json)>
106 Json(
const T & t) :
Json(t.to_json()) {}
109 template <
class M,
typename std::enable_if<
110 std::is_constructible<std::string, typename M::key_type>::value
111 && std::is_constructible<Json, typename M::mapped_type>::value,
113 Json(
const M & m) :
Json(
object(m.begin(), m.end())) {}
116 template <
class V,
typename std::enable_if<
117 std::is_constructible<Json, typename V::value_type>::value,
119 Json(
const V & v) :
Json(array(v.begin(), v.end())) {}
123 Json(
void *) =
delete;
128 bool is_null()
const {
return type() == NUL; }
129 bool is_number()
const {
return type() == NUMBER; }
130 bool is_bool()
const {
return type() == BOOL; }
131 bool is_string()
const {
return type() == STRING; }
132 bool is_array()
const {
return type() == ARRAY; }
133 bool is_object()
const {
return type() == OBJECT; }
138 double number_value()
const;
139 int int_value()
const;
142 bool bool_value()
const;
144 const std::string &string_value()
const;
146 const array &array_items()
const;
148 const object &object_items()
const;
151 const Json & operator[](
size_t i)
const;
153 const Json & operator[](
const std::string &key)
const;
156 void dump(std::string &out)
const;
157 std::string dump()
const {
164 static Json parse(
const std::string & in,
166 JsonParse strategy = JsonParse::STANDARD);
167 static Json parse(
const char * in,
169 JsonParse strategy = JsonParse::STANDARD) {
171 return parse(std::string(in), err, strategy);
178 static std::vector<Json> parse_multi(
179 const std::string & in,
180 std::string::size_type & parser_stop_pos,
182 JsonParse strategy = JsonParse::STANDARD);
184 static inline std::vector<Json> parse_multi(
185 const std::string & in,
187 JsonParse strategy = JsonParse::STANDARD) {
188 std::string::size_type parser_stop_pos;
189 return parse_multi(in, parser_stop_pos, err, strategy);
192 bool operator== (
const Json &rhs)
const;
193 bool operator< (
const Json &rhs)
const;
194 bool operator!= (
const Json &rhs)
const {
return !(*
this == rhs); }
195 bool operator<= (
const Json &rhs)
const {
return !(rhs < *
this); }
196 bool operator> (
const Json &rhs)
const {
return (rhs < *
this); }
197 bool operator>= (
const Json &rhs)
const {
return !(*
this < rhs); }
204 typedef std::initializer_list<std::pair<std::string, Type>> shape;
205 bool has_shape(
const shape & types, std::string & err)
const;
208 std::shared_ptr<JsonValue> m_ptr;
217 virtual Json::Type type()
const = 0;
218 virtual bool equals(
const JsonValue * other)
const = 0;
219 virtual bool less(
const JsonValue * other)
const = 0;
220 virtual void dump(std::string &out)
const = 0;
221 virtual double number_value()
const;
222 virtual int int_value()
const;
223 virtual bool bool_value()
const;
224 virtual const std::string &string_value()
const;
225 virtual const Json::array &array_items()
const;
226 virtual const Json &operator[](
size_t i)
const;
227 virtual const Json::object &object_items()
const;
228 virtual const Json &operator[](
const std::string &key)
const;
Definition: json11.cpp:173
Definition: json11.hpp:79
Definition: json11.hpp:212
Definition: json11.cpp:29
Definition: json11.cpp:182