annotate src/core/json.cpp @ 37:9ae9365dd4ea

window.cpp: fix sidebar on Linux
author Paper <mrpapersonic@gmail.com>
date Thu, 21 Sep 2023 17:15:43 -0400
parents 5c0397762b53
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
1 #include "core/json.h"
2
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>();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
8 else
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
9 return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
12 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
13 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
14 return json[ptr].get<int>();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
15 else
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
16 return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
19 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
20 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
21 return json[ptr].get<bool>();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
22 else
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
23 return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25
7
Paper <mrpapersonic@gmail.com>
parents: 6
diff changeset
26 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
27 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
28 return json[ptr].get<double>();
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
29 else
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
30 return def;
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 7
diff changeset
33 } // namespace JSON