Mercurial > minori
annotate src/json.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children |
rev | line source |
---|---|
2 | 1 #include "json.h" |
2 | |
3 namespace JSON { | |
4 | |
7 | 5 std::string GetString(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, std::string def) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
6 if (json.contains(ptr) && json[ptr].is_string()) |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
7 return json[ptr].get<std::string>(); |
7 | 8 else return def; |
2 | 9 } |
10 | |
7 | 11 int GetInt(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, int def) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
12 if (json.contains(ptr) && json[ptr].is_number()) |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
13 return json[ptr].get<int>(); |
7 | 14 else return def; |
2 | 15 } |
16 | |
7 | 17 bool GetBoolean(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, bool def) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
18 if (json.contains(ptr) && json[ptr].is_boolean()) |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
19 return json[ptr].get<bool>(); |
7 | 20 else return def; |
2 | 21 } |
22 | |
7 | 23 double GetDouble(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr, double def) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
24 if (json.contains(ptr) && json[ptr].is_number()) |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
25 return json[ptr].get<double>(); |
7 | 26 else return def; |
2 | 27 } |
28 | |
29 } | |
30 |