Mercurial > minori
comparison include/core/ini.h @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 01 Apr 2024 02:43:44 -0400 |
parents | 53211cb1e7f5 |
children | 3ec7804abf17 |
comparison
equal
deleted
inserted
replaced
257:699a20c57dc8 | 258:862d0d8619f6 |
---|---|
1 #ifndef __core__ini_h | 1 #ifndef __core__ini_h |
2 #define __core__ini_h | 2 #define __core__ini_h |
3 | 3 |
4 #define MINI_CASE_SENSITIVE | 4 #define MINI_CASE_SENSITIVE |
5 #include "mini/ini.h" | |
6 #include "core/strings.h" | 5 #include "core/strings.h" |
7 #include "gui/translate/anime.h" | 6 #include "gui/translate/anime.h" |
8 #include "gui/translate/config.h" | 7 #include "gui/translate/config.h" |
8 #include "mini/ini.h" | |
9 #include <string> | |
9 #include <type_traits> | 10 #include <type_traits> |
10 #include <string> | |
11 | 11 |
12 namespace INI { | 12 namespace INI { |
13 | 13 |
14 /* very simple tutorial on how to give anyone who reads | 14 /* very simple tutorial on how to give anyone who reads |
15 your code an aneurysm */ | 15 your code an aneurysm */ |
16 template <typename T, typename = void> | 16 template<typename T, typename = void> |
17 struct is_toutf8string_available : std::false_type {}; | 17 struct is_toutf8string_available : std::false_type {}; |
18 | 18 |
19 template<typename T> | 19 template<typename T> |
20 struct is_toutf8string_available<T, | 20 struct is_toutf8string_available<T, std::void_t<decltype(Strings::ToUtf8String(std::declval<T>()))>> : std::true_type { |
21 std::void_t<decltype(Strings::ToUtf8String(std::declval<T>()))>> : std::true_type {}; | 21 }; |
22 | 22 |
23 template <typename T, typename = void> | 23 template<typename T, typename = void> |
24 struct is_translation_available : std::false_type {}; | 24 struct is_translation_available : std::false_type {}; |
25 | 25 |
26 template<typename T> | 26 template<typename T> |
27 struct is_translation_available<T, | 27 struct is_translation_available<T, std::void_t<decltype(Translate::ToString(std::declval<T>()))>> : std::true_type {}; |
28 std::void_t<decltype(Translate::ToString(std::declval<T>()))>> : std::true_type {}; | |
29 | 28 |
30 template<typename T> | 29 template<typename T> |
31 T GetIniValue(const mINI::INIStructure& ini, const std::string& section, | 30 T GetIniValue(const mINI::INIStructure& ini, const std::string& section, const std::string& value, const T& def) { |
32 const std::string& value, const T& def) { | |
33 if (!ini.has(section) || !ini.get(section).has(value)) | 31 if (!ini.has(section) || !ini.get(section).has(value)) |
34 return def; | 32 return def; |
35 | 33 |
36 const std::string val = ini.get(section).get(value); | 34 const std::string val = ini.get(section).get(value); |
37 | 35 |
49 } | 47 } |
50 } | 48 } |
51 | 49 |
52 /* this should be able to handle most of our custom types */ | 50 /* this should be able to handle most of our custom types */ |
53 template<typename T> | 51 template<typename T> |
54 void SetIniValue(mINI::INIStructure& ini, const std::string& section, | 52 void SetIniValue(mINI::INIStructure& ini, const std::string& section, const std::string& key, const T& value) { |
55 const std::string& key, const T& value) { | |
56 auto& ini_key = ini[section][key]; | 53 auto& ini_key = ini[section][key]; |
57 | 54 |
58 if constexpr (is_translation_available<T>::value) { | 55 if constexpr (is_translation_available<T>::value) { |
59 /* prioritize translation */ | 56 /* prioritize translation */ |
60 ini_key = Translate::ToString(value); | 57 ini_key = Translate::ToString(value); |
64 } else if constexpr (is_toutf8string_available<T>::value) { | 61 } else if constexpr (is_toutf8string_available<T>::value) { |
65 ini_key = Strings::ToUtf8String(value); | 62 ini_key = Strings::ToUtf8String(value); |
66 } | 63 } |
67 } | 64 } |
68 | 65 |
69 } | 66 } // namespace INI |
70 | 67 |
71 #endif | 68 #endif |