Mercurial > minori
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 80:825506f0e221 | 81:9b2b41f83a5e | 
|---|---|
| 1 #include "core/json.h" | |
| 2 | |
| 3 namespace JSON { | |
| 4 | |
| 5 std::string GetString(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, std::string def) { | |
| 6 if (json.contains(ptr) && json[ptr].is_string()) | |
| 7 return json[ptr].get<std::string>(); | |
| 8 else | |
| 9 return def; | |
| 10 } | |
| 11 | |
| 12 int GetInt(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, int def) { | |
| 13 if (json.contains(ptr) && json[ptr].is_number()) | |
| 14 return json[ptr].get<int>(); | |
| 15 else | |
| 16 return def; | |
| 17 } | |
| 18 | |
| 19 bool GetBoolean(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, bool def) { | |
| 20 if (json.contains(ptr) && json[ptr].is_boolean()) | |
| 21 return json[ptr].get<bool>(); | |
| 22 else | |
| 23 return def; | |
| 24 } | |
| 25 | |
| 26 double GetDouble(nlohmann::json const& json, nlohmann::json::json_pointer const& 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 | 
