// // json_common.h // json // // Created by Sam Jaffe on 4/22/16. // #pragma once #include "../variant/variant.hpp" #include #include #include #include #include #include namespace json { using string_jt = std::string; using double_jt = double; using int_jt = int32_t; using uint_jt = uint32_t; using bool_jt = bool; using numeric_jt = variant; class value; class malformed_json_exception : public std::domain_error { using std::domain_error::domain_error; }; } namespace json { namespace helper { const char get_next_element(char const*& data); /** * @throws json::malformed_json_exception */ void advance_to_boundary(char const endtok, char const *& data); /** * @throws json::malformed_json_exception */ std::string parse_string(char const * & data); template void parse_string(T& json, char const * & data) { json = parse_string(data); } template void parse_double(T& json, char const * & data) { json = atof(data); } template void parse_integer(T& json, char const * & data) { json = atoi(data); } } namespace parser { template void parse(T& json, std::string const& str) { parse(json, str.c_str()); } template void parse(T& json, std::istream & in) { in.seekg(0, std::ios_base::end); size_t end = in.tellg(); char data[end]; in.seekg(0); in.read(data, end); parse(json, data); } } }