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
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
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
8 else return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
14 else return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
20 else return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
26 else return def;
2
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