Mercurial > minori
annotate src/json.cpp @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 16 Aug 2023 00:49:17 -0400 |
| parents | 23d0d9319a00 |
| children | 07a9095eaeed |
| rev | line source |
|---|---|
| 2 | 1 #include "json.h" |
| 2 | |
| 3 namespace JSON { | |
| 4 | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
5 std::string GetString(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr) { |
|
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>(); |
| 2 | 8 else return ""; |
| 9 } | |
| 10 | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
11 int GetInt(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr) { |
|
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>(); |
| 2 | 14 else return 0; |
| 15 } | |
| 16 | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
17 bool GetBoolean(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr) { |
|
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>(); |
| 2 | 20 else return false; |
| 21 } | |
| 22 | |
|
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
2
diff
changeset
|
23 double GetDouble(nlohmann::json const& json, nlohmann::json::json_pointer const& ptr) { |
|
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>(); |
| 2 | 26 else return 0; |
| 27 } | |
| 28 | |
| 29 } | |
| 30 |
