Mercurial > minori
annotate include/core/ini.h @ 239:cae61340cc86
configure: check pkg-config for qt
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Fri, 19 Jan 2024 12:29:53 -0500 |
| parents | 53211cb1e7f5 |
| children | 862d0d8619f6 |
| rev | line source |
|---|---|
| 102 | 1 #ifndef __core__ini_h |
| 2 #define __core__ini_h | |
| 3 | |
| 4 #define MINI_CASE_SENSITIVE | |
| 5 #include "mini/ini.h" | |
| 120 | 6 #include "core/strings.h" |
| 7 #include "gui/translate/anime.h" | |
| 8 #include "gui/translate/config.h" | |
| 9 #include <type_traits> | |
| 10 #include <string> | |
| 102 | 11 |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
12 namespace INI { |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
13 |
| 120 | 14 /* very simple tutorial on how to give anyone who reads |
| 15 your code an aneurysm */ | |
| 16 template <typename T, typename = void> | |
| 17 struct is_toutf8string_available : std::false_type {}; | |
| 18 | |
| 19 template<typename T> | |
| 20 struct is_toutf8string_available<T, | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
136
diff
changeset
|
21 std::void_t<decltype(Strings::ToUtf8String(std::declval<T>()))>> : std::true_type {}; |
| 120 | 22 |
| 23 template <typename T, typename = void> | |
| 24 struct is_translation_available : std::false_type {}; | |
| 25 | |
| 26 template<typename T> | |
| 27 struct is_translation_available<T, | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
136
diff
changeset
|
28 std::void_t<decltype(Translate::ToString(std::declval<T>()))>> : std::true_type {}; |
| 120 | 29 |
| 30 template<typename T> | |
| 31 T GetIniValue(const mINI::INIStructure& ini, const std::string& section, | |
| 32 const std::string& value, const T& def) { | |
| 33 if (!ini.has(section) || !ini.get(section).has(value)) | |
| 34 return def; | |
| 35 | |
| 36 const std::string val = ini.get(section).get(value); | |
| 37 | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
136
diff
changeset
|
38 if constexpr (std::is_integral<T>::value) { |
| 120 | 39 /* Integer? */ |
| 40 if constexpr (std::is_same<T, bool>::value) { | |
| 41 /* Boolean? */ | |
|
136
7d3ad9529c4c
ini: fix bool getters to provide default vals for bools and ints
Paper <mrpapersonic@gmail.com>
parents:
122
diff
changeset
|
42 return Strings::ToBool(val, def); |
| 120 | 43 } else { |
| 44 /* Always fall back to long long */ | |
|
136
7d3ad9529c4c
ini: fix bool getters to provide default vals for bools and ints
Paper <mrpapersonic@gmail.com>
parents:
122
diff
changeset
|
45 return Strings::ToInt<T>(val, def); |
| 120 | 46 } |
| 47 } else { | |
| 48 return val; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 /* this should be able to handle most of our custom types */ | |
| 53 template<typename T> | |
| 54 void SetIniValue(mINI::INIStructure& ini, const std::string& section, | |
| 55 const std::string& key, const T& value) { | |
| 56 auto& ini_key = ini[section][key]; | |
| 57 | |
| 58 if constexpr (is_translation_available<T>::value) { | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
136
diff
changeset
|
59 /* prioritize translation */ |
| 120 | 60 ini_key = Translate::ToString(value); |
| 61 } else if constexpr (std::is_same<T, std::string>::value) { | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
136
diff
changeset
|
62 /* lmfao */ |
| 120 | 63 ini_key = value; |
| 64 } else if constexpr (is_toutf8string_available<T>::value) { | |
| 65 ini_key = Strings::ToUtf8String(value); | |
| 66 } | |
| 67 } | |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
68 |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
69 } |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
70 |
| 120 | 71 #endif |
