view src/core/json.cc @ 102:b315f3759c56

*: big patch 1. use a wrapper for mINI that enables case sensitivity (personal preference) 2. rename dark_theme.cc to theme.cc and change it to be a class 3. include the "dep" folder so we don't have stupidity in json.h or ini.h 4. I think the graph was also tweaked a lot in this, nothing is constexpr and size is found at runtime...
author Paper <mrpapersonic@gmail.com>
date Fri, 03 Nov 2023 21:32:52 -0400
parents d02fdf1d6708
children f88eda79c60a
line wrap: on
line source

#include "core/json.h"

namespace JSON {

std::string GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, std::string def) {
	if (json.contains(ptr) && json[ptr].is_string())
		return json[ptr].get<std::string>();
	else
		return def;
}

int GetInt(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, int def) {
	if (json.contains(ptr) && json[ptr].is_number())
		return json[ptr].get<int>();
	else
		return def;
}

bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def) {
	if (json.contains(ptr) && json[ptr].is_boolean())
		return json[ptr].get<bool>();
	else
		return def;
}

double GetDouble(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, double def) {
	if (json.contains(ptr) && json[ptr].is_number())
		return json[ptr].get<double>();
	else
		return def;
}

} // namespace JSON