Euphoria
|
json.h File Reference
#include <optional>
#include <set>
#include "jsonh/jsonh.h"
#include "log/log.h"
#include "assert/assert.h"
#include "base/result.h"
Go to the source code of this file.
Classes | |
struct | eu::io::Json |
struct | eu::io::JsonError |
struct | eu::io::ObjectQuery |
Namespaces | |
eu | |
eu::io | |
Macros | |
#define | JSON_PARSE_FUNC(TYPE) bool parse(::eu::log::Logger* log, TYPE* owner, jsonh::Value root_val, const jsonh::Document* doc) |
#define | JSON_EXPECT(x, msg) |
#define | JSON_BEGIN_ENUM(TYPE) |
#define | JSON_ENUM_VAL(VAL) |
#define | JSON_END_ENUM() |
#define | JSON_BEGIN_OBJECT() |
#define | JSON_VAL_X(TYPE, PROP, REQUIRED) |
#define | JSON_VAL_OBJ_X(TYPE, PROP, REQUIRED, CON) |
#define | JSON_VAL_OBJ(TYPE, PROP) JSON_VAL_OBJ_X(TYPE, PROP, true, ) |
#define | JSON_VAL_OPT_OBJ(TYPE, PROP) JSON_VAL_OBJ_X(TYPE, PROP, false, ) |
#define | JSON_VAL_OPT_OBJ_CON(TYPE, PROP, CON) JSON_VAL_OBJ_X(TYPE, PROP, false, CON) |
#define | JSON_VAL(TYPE, PROP) JSON_VAL_X(TYPE, PROP, true) |
#define | JSON_OPT_VAL(TYPE, PROP) JSON_VAL_X(TYPE, PROP, false) |
#define | JSON_ARRAY(TYPE, PROP) |
#define | JSON_ARRAY_PROP_CON(TYPE, PROP, CON) |
#define | JSON_ARRAY_PROP(TYPE, PROP) JSON_ARRAY_PROP_CON(TYPE, PROP, ) |
#define | JSON_END_OBJECT() |
Typedefs | |
using | eu::io::JsonResult = Result< Json, JsonError > |
Enumerations | |
enum class | eu::io::JsonErrorType { eu::io::file_error , eu::io::parse_error } |
Functions | |
std::string | eu::io::get_string_from_path_for_debugging (FileSystem *fs, const FilePath &p) |
JsonResult | eu::io::read_json_file (FileSystem *fs, const FilePath &file_name) |
std::string | eu::io::could_be (const std::string &invalid_value, const std::vector< std::string > &possible_values) |
Macro Definition Documentation
◆ JSON_ARRAY
#define JSON_ARRAY | ( | TYPE, | |
PROP | |||
) |
Value:
do{\
auto dnu_val = object.get(#PROP);\
JSON_EXPECT(dnu_val, "missing property " #PROP);\
auto* dnu_array = dnu_val->AsArray(doc);\
JSON_EXPECT(dnu_array, #PROP " is not a array");\
for (const auto dnu_json : dnu_array->array)\
{\
TYPE dnu_prop;\
if (false == parse(log, &dnu_prop, dnu_json, doc))\
{\
return false;\
}\
owner->PROP.emplace_back(std::move(dnu_prop));\
}\
} while(false)
◆ JSON_ARRAY_PROP
#define JSON_ARRAY_PROP | ( | TYPE, | |
PROP | |||
) | JSON_ARRAY_PROP_CON(TYPE, PROP, ) |
◆ JSON_ARRAY_PROP_CON
#define JSON_ARRAY_PROP_CON | ( | TYPE, | |
PROP, | |||
CON | |||
) |
Value:
do{\
auto dnu_val = object.get(#PROP);\
JSON_EXPECT(dnu_val, "missing property " #PROP);\
auto* dnu_array = dnu_val->AsArray(doc);\
JSON_EXPECT(dnu_array, #PROP " is not a array");\
for (const auto dnu_json : dnu_array->array)\
{\
const auto* dnu_prop = dnu_json.As ## TYPE(doc);\
JSON_EXPECT(dnu_prop, #PROP " is not a " #TYPE);\
owner->PROP.emplace_back(CON(dnu_prop->value));\
}\
} while(false)
◆ JSON_BEGIN_ENUM
#define JSON_BEGIN_ENUM | ( | TYPE | ) |
◆ JSON_BEGIN_OBJECT
#define JSON_BEGIN_OBJECT | ( | ) |
Value:
const auto* root = root_val.AsObject(doc);\
JSON_EXPECT(root, "root is not a object");\
auto object = ::eu::io::ObjectQuery{ root }
Definition: json.h:38
◆ JSON_END_ENUM
#define JSON_END_ENUM | ( | ) |
Value:
log->error(fmt::format("{} was invalid for {}, could be {}",\
dnu_val->value, dnu_enum_name,\
eu::io::could_be(dnu_val->value, dnu_values)));\
return false
std::string could_be(const std::string &invalid_value, const std::vector< std::string > &possible_values)
Definition: json.cc:89
◆ JSON_END_OBJECT
#define JSON_END_OBJECT | ( | ) |
◆ JSON_ENUM_VAL
#define JSON_ENUM_VAL | ( | VAL | ) |
◆ JSON_EXPECT
#define JSON_EXPECT | ( | x, | |
msg | |||
) |
◆ JSON_OPT_VAL
#define JSON_OPT_VAL | ( | TYPE, | |
PROP | |||
) | JSON_VAL_X(TYPE, PROP, false) |
◆ JSON_PARSE_FUNC
#define JSON_PARSE_FUNC | ( | TYPE | ) | bool parse(::eu::log::Logger* log, TYPE* owner, jsonh::Value root_val, const jsonh::Document* doc) |
◆ JSON_VAL
#define JSON_VAL | ( | TYPE, | |
PROP | |||
) | JSON_VAL_X(TYPE, PROP, true) |
◆ JSON_VAL_OBJ
#define JSON_VAL_OBJ | ( | TYPE, | |
PROP | |||
) | JSON_VAL_OBJ_X(TYPE, PROP, true, ) |
◆ JSON_VAL_OBJ_X
#define JSON_VAL_OBJ_X | ( | TYPE, | |
PROP, | |||
REQUIRED, | |||
CON | |||
) |
Value:
do {\
auto dnu_json = object.get(#PROP);\
if (dnu_json)\
{\
TYPE dnu_prop = {};\
if (false == parse(log, &dnu_prop, *dnu_json, doc))\
{\
return false;\
}\
owner->PROP = CON(std::move(dnu_prop));\
}\
else if constexpr(REQUIRED)\
{\
object.required.emplace_back(#PROP);\
}\
} while(false)
◆ JSON_VAL_OPT_OBJ
#define JSON_VAL_OPT_OBJ | ( | TYPE, | |
PROP | |||
) | JSON_VAL_OBJ_X(TYPE, PROP, false, ) |
◆ JSON_VAL_OPT_OBJ_CON
#define JSON_VAL_OPT_OBJ_CON | ( | TYPE, | |
PROP, | |||
CON | |||
) | JSON_VAL_OBJ_X(TYPE, PROP, false, CON) |
◆ JSON_VAL_X
#define JSON_VAL_X | ( | TYPE, | |
PROP, | |||
REQUIRED | |||
) |
Value:
do {\
auto dnu_json = object.get(#PROP);\
if (dnu_json)\
{\
auto* dnu_prop = dnu_json->As ## TYPE(doc);\
JSON_EXPECT(dnu_prop, #PROP " is not a " #TYPE);\
owner->PROP = dnu_prop->value;\
}\
else if constexpr(REQUIRED)\
{\
object.required.emplace_back(#PROP);\
}\
} while(false)