view src/core/json.cc @ 81:9b2b41f83a5e

boring: mass rename to cc because this is a very unix-y project, it makes more sense to use the 'cc' extension
author Paper <mrpapersonic@gmail.com>
date Mon, 23 Oct 2023 12:07:27 -0400
parents src/core/json.cpp@5c0397762b53
children d02fdf1d6708
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