Mercurial > minori
view src/core/json.cpp @ 11:fc1bf97c528b
*: use C++11 standard
I've been meaning to do this for a while, but I didn't want to reimplement
the filesystem code. Now we are on C++11 and most compilers from the past 5 centuries should support this now
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 17 Sep 2023 06:14:30 -0400 |
parents | 5c0397762b53 |
children |
line wrap: on
line source
#include "core/json.h" namespace JSON { std::string GetString(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, std::string def) { if (json.contains(ptr) && json[ptr].is_string()) return json[ptr].get<std::string>(); else return def; } int GetInt(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, int def) { if (json.contains(ptr) && json[ptr].is_number()) return json[ptr].get<int>(); else return def; } bool GetBoolean(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, bool def) { if (json.contains(ptr) && json[ptr].is_boolean()) return json[ptr].get<bool>(); else return def; } double GetDouble(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, double def) { if (json.contains(ptr) && json[ptr].is_number()) return json[ptr].get<double>(); else return def; } } // namespace JSON