file
Json.h
Namespaces
Typedefs
- using JsonDocument = rapidjson::Document
Functions
-
auto writeJsonToFile(const JsonDocument& document,
const std::
string& file, bool usePrettyWriter = true, int maxDecimalPlaces = -1) -> bool - Write a Json doc to file.
-
auto parseJsonFile(const std::
string& file) -> JsonDocument - Parse JSON file and return as JsonDocument object.
-
auto parseJsonString(const std::
string& jsonString) -> JsonDocument - Parse JSON string and return as JsonDocument object.
-
auto jsonToString(const JsonDocument& d,
int maxDecimalPlaces = -1) -> std::
string - Return string representation of given JsonDocument.
- auto jsonToVec3f(const JsonGenericValue& jsonArray) -> esp::vec3f
- Return Vec3f coordinates representation of given JsonObject of array type.
-
template<typename T>auto jsonIntoSetter(const JsonGenericValue& d, const char* tag, std::
function<void(T)> setter) -> bool - Check passed json doc for existence of passed jsonTag as value of type T. If present, populate passed setter with value. Returns whether tag is found and successfully populated, or not. Logs an error if
tag
is found but is inappropriate type. -
template<typename T>auto jsonIntoConstSetter(const JsonGenericValue& d, const char* tag, std::
function<void(const T)> setter) -> bool - Check passed json doc for existence of passed jsonTag as value of type T, where the consuming setter will treat the value as const. If present, populate passed setter with value. Returns whether
tag
is found and successfully populated, or not. Logs an error if tag is found but is inappropriate type. -
template<typename GV, typename T>void toVector(const GV& arr, std::
vector<T>* vec, const std:: function<T(const GV&)>& conv) -
template<typename GV>void toIntVector(const GV& value, std::
vector<int>* vec) -
template<typename GV>void toInt64Vector(const GV& value, std::
vector<int64_ t>* vec) -
template<typename GV>void toFloatVector(const GV& value, std::
vector<float>* vec) -
template<typename GV>void toDoubleVector(const GV& value, std::
vector<double>* vec)
Defines
- #define RAPIDJSON_NO_INT64DEFINE
Function documentation
bool writeJsonToFile(const JsonDocument& document,
const std:: string& file,
bool usePrettyWriter = true,
int maxDecimalPlaces = -1)
Write a Json doc to file.
Parameters | |
---|---|
document | an already-populated document object |
file | |
usePrettyWriter | The pretty writer does nice indenting and spacing but leads to larger filesize. |
maxDecimalPlaces | Set this to a positive integer to shorten how floats/doubles are written. Beware loss of precision in your saved data. |
Returns | whether successful or not |
template<typename T>
bool jsonIntoSetter(const JsonGenericValue& d,
const char* tag,
std:: function<void(T)> setter)
Check passed json doc for existence of passed jsonTag as value of type T. If present, populate passed setter with value. Returns whether tag is found and successfully populated, or not. Logs an error if tag
is found but is inappropriate type.
Template parameters | |
---|---|
T | type of destination variable - must be supported type. |
Parameters | |
d | json document to parse |
tag | string tag to look for in json doc |
setter | value setter in some object to populate with the data from json. |
Returns | whether successful or not |
template<typename T>
bool jsonIntoConstSetter(const JsonGenericValue& d,
const char* tag,
std:: function<void(const T)> setter)
Check passed json doc for existence of passed jsonTag as value of type T, where the consuming setter will treat the value as const. If present, populate passed setter with value. Returns whether tag
is found and successfully populated, or not. Logs an error if tag is found but is inappropriate type.
Template parameters | |
---|---|
T | type of destination variable - must be supported type. |
Parameters | |
d | json document to parse |
tag | string tag to look for in json doc |
setter | value setter in some object to populate with the data from json. |
Returns | whether successful or not |