view src/core/json.cpp @ 68:2417121d894e

*: normalize usage of layouts before, I used them two ways, once was by setting the layout later by using setLayout(QWidget), and the other was just using the constructor. I find the constructor to be easier to read, so I chose that one.
author Paper <mrpapersonic@gmail.com>
date Mon, 02 Oct 2023 21:33:25 -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