| 4 | #include <type_traits> |
| 5 | |
| 6 | struct Settings |
| 7 | { |
| 8 | /*Keys for settings*/ |
| 9 | constexpr static auto Notify = L"Notify"; |
| 10 | constexpr static auto MultipleWindowBehavior = L"MultipleWindowBehavior"; |
| 11 | constexpr static auto ThemeSelection = L"ThemeSelection"; |
| 12 | constexpr static auto BackgroundSelection = L"BackSelection"; |
| 13 | |
| 14 | /** |
| 15 | * @brief Get settings value of a specific type, will throw if the key is not found |
| 16 | * @tparam T value type of the setting |
| 17 | * @param key name of the setting |
| 18 | */ |
| 19 | template<typename T> |
| 20 | auto Get(wchar_t const* key) const |
| 21 | { |
| 22 | if constexpr (std::is_base_of_v<winrt::Windows::Foundation::IInspectable, std::remove_cvref_t<T>>) |
| 23 | return m_map.Lookup(key); |
| 24 | else |
| 25 | return winrt::unbox_value<T>(m_map.Lookup(key)); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @brief Get settings value of a specific type, return a default value if not found |
| 30 | * @tparam T value type of the setting |
| 31 | * @param key name of the setting |
| 32 | * @param defaultValue that will be returned if the setting is not set |
| 33 | */ |
| 34 | template<typename T> |
| 35 | auto Get(wchar_t const* key, T&& defaultValue) const |
| 36 | { |
| 37 | if constexpr (std::is_base_of_v<winrt::Windows::Foundation::IInspectable, std::remove_cvref_t<T>>) |
| 38 | return m_map.TryLookup(key); |
| 39 | else |
| 40 | return winrt::unbox_value_or<T>(m_map.TryLookup(key), defaultValue); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @brief |
| 45 | * |
| 46 | * @param key |
| 47 | * @param value |
| 48 | */ |
| 49 | template<typename T> |
| 50 | void Set(wchar_t const* key, T&& value) |
| 51 | { |
| 52 | if constexpr (std::is_base_of_v<winrt::Windows::Foundation::IInspectable, std::remove_cvref_t<T>>) |
| 53 | m_map.Insert(key, value); |
| 54 | else |
| 55 | m_map.Insert(key, winrt::box_value(value)); |
| 56 | } |
| 57 | private: |
| 58 | winrt::Windows::Foundation::Collections::IPropertySet m_map = winrt::Windows::Storage::ApplicationData::Current().LocalSettings().Values(); |
| 59 | }; |
| 60 |
nothing calls this directly
no outgoing calls
no test coverage detected