Mercurial > minori
comparison src/core/json.cc @ 83:d02fdf1d6708
*: huuuge update
1. make the now playing page function correctly
2. de-constructorfy many of our custom widgets,
allowing them to be changed on-the-fly from
the Now Playing page
3. ... :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 24 Oct 2023 22:01:02 -0400 |
| parents | 9b2b41f83a5e |
| children | f88eda79c60a |
comparison
equal
deleted
inserted
replaced
| 82:8b65c417c225 | 83:d02fdf1d6708 |
|---|---|
| 1 #include "core/json.h" | 1 #include "core/json.h" |
| 2 | 2 |
| 3 namespace JSON { | 3 namespace JSON { |
| 4 | 4 |
| 5 std::string GetString(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, std::string def) { | 5 std::string GetString(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, std::string def) { |
| 6 if (json.contains(ptr) && json[ptr].is_string()) | 6 if (json.contains(ptr) && json[ptr].is_string()) |
| 7 return json[ptr].get<std::string>(); | 7 return json[ptr].get<std::string>(); |
| 8 else | 8 else |
| 9 return def; | 9 return def; |
| 10 } | 10 } |
| 11 | 11 |
| 12 int GetInt(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, int def) { | 12 int GetInt(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, int def) { |
| 13 if (json.contains(ptr) && json[ptr].is_number()) | 13 if (json.contains(ptr) && json[ptr].is_number()) |
| 14 return json[ptr].get<int>(); | 14 return json[ptr].get<int>(); |
| 15 else | 15 else |
| 16 return def; | 16 return def; |
| 17 } | 17 } |
| 18 | 18 |
| 19 bool GetBoolean(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, bool def) { | 19 bool GetBoolean(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, bool def) { |
| 20 if (json.contains(ptr) && json[ptr].is_boolean()) | 20 if (json.contains(ptr) && json[ptr].is_boolean()) |
| 21 return json[ptr].get<bool>(); | 21 return json[ptr].get<bool>(); |
| 22 else | 22 else |
| 23 return def; | 23 return def; |
| 24 } | 24 } |
| 25 | 25 |
| 26 double GetDouble(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, double def) { | 26 double GetDouble(const nlohmann::json& json, const nlohmann::json::json_pointer& ptr, double def) { |
| 27 if (json.contains(ptr) && json[ptr].is_number()) | 27 if (json.contains(ptr) && json[ptr].is_number()) |
| 28 return json[ptr].get<double>(); | 28 return json[ptr].get<double>(); |
| 29 else | 29 else |
| 30 return def; | 30 return def; |
| 31 } | 31 } |
