Mercurial > minori
view include/core/json.h @ 179:9c4645100fec
osx: clean up includes, we do not need cocoa
what we *do* need is the very basics that animia already depends on anyway.
these are basically guaranteed to be on any macos system, making it fairly portable
now... I haven't tested this :) I don't have a macos machine right now...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 12:03:36 -0500 |
parents | 9b10175be389 |
children | bc1ae1810855 |
line wrap: on
line source
#ifndef __core__json_h #define __core__json_h #include "json/json.hpp" namespace JSON { template<typename T = std::string> T GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def) { if (json.contains(ptr) && json[ptr].is_string()) return json[ptr].get<T>(); else return def; } template<typename T = int> T GetNumber(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def = 0) { if (json.contains(ptr) && json[ptr].is_number()) return json[ptr].get<T>(); else return def; } template<typename T = std::vector<std::string>> T GetArray(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, T def = 0) { if (json.contains(ptr) && json[ptr].is_array()) return json[ptr].get<T>(); else return def; } nlohmann::json GetValue(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr); bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def = false); } // namespace JSON #endif // __core__json_h