Mercurial > minori
comparison src/core/json.cc @ 202:71832ffe425a
animia: re-add kvm fd source
this is all being merged from my wildly out-of-date laptop. SORRY!
in other news, I edited the CI file to install the wayland client
as well, so the linux CI build might finally get wayland stuff.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Tue, 02 Jan 2024 06:05:06 -0500 |
parents | 9b10175be389 |
children |
comparison
equal
deleted
inserted
replaced
201:8f6f8dd2eb23 | 202:71832ffe425a |
---|---|
1 #include "core/json.h" | 1 #include "core/json.h" |
2 #include "json/json.hpp" | |
2 | 3 |
3 namespace JSON { | 4 namespace JSON { |
4 | 5 |
5 std::string GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, std::string def) { | 6 nlohmann::json GetValue(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr) { |
6 if (json.contains(ptr) && json[ptr].is_string()) | 7 if (json.contains(ptr)) |
7 return json[ptr].get<std::string>(); | 8 return json.at(ptr); |
8 else | 9 else |
9 return def; | 10 return nlohmann::json(); |
10 } | |
11 | |
12 int GetInt(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, int def) { | |
13 if (json.contains(ptr) && json[ptr].is_number()) | |
14 return json[ptr].get<int>(); | |
15 else | |
16 return def; | |
17 } | 11 } |
18 | 12 |
19 bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def) { | 13 bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def) { |
20 if (json.contains(ptr) && json[ptr].is_boolean()) | 14 if (json.contains(ptr) && json[ptr].is_boolean()) |
21 return json[ptr].get<bool>(); | 15 return json[ptr].get<bool>(); |
22 else | 16 else |
23 return def; | 17 return def; |
24 } | 18 } |
25 | 19 |
26 double GetDouble(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, double def) { | |
27 if (json.contains(ptr) && json[ptr].is_number()) | |
28 return json[ptr].get<double>(); | |
29 else | |
30 return def; | |
31 } | |
32 | |
33 } // namespace JSON | 20 } // namespace JSON |