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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "json.h"
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 namespace JSON {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 else return "";
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 else return 0;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 else return false;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 else return 0;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30