HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
user_settings_intf.hpp
1
2
3#pragma once
4
5#include "../utility/utility.hpp"
6#include "../macros.hpp"
7#include <optional>
8#include <string>
9#include <string_view>
10#include <cstdlib>
11#include <expected>
12#include <system_error>
13
14hi_export_module(hikogui.settings.user_settings : intf);
15
16hi_export namespace hi { inline namespace v1 {
17
18[[nodiscard]] std::expected<std::string, std::error_code> get_user_setting_string(std::string_view key) noexcept;
19[[nodiscard]] std::expected<long long, std::error_code> get_user_setting_integral(std::string_view key) noexcept;
20
31template<typename T>
32[[nodiscard]] std::expected<T, std::error_code> get_user_setting(std::string_view key) noexcept = delete;
33
43std::error_code set_user_setting(std::string_view key, std::string_view value) noexcept;
44
54std::error_code set_user_setting(std::string_view key, long long value) noexcept;
55
64std::error_code delete_user_setting(std::string_view key) noexcept;
65
69
70template<>
71[[nodiscard]] inline std::expected<std::string, std::error_code> get_user_setting(std::string_view key) noexcept
72{
73 return get_user_setting_string(key);
74}
75
76template<std::integral T>
77[[nodiscard]] inline std::expected<T, std::error_code> get_user_setting(std::string_view key) noexcept
78{
79 if (auto const value = get_user_setting_integral(key)) {
80 if (can_narrow_cast<T>(*value)) {
81 return narrow_cast<T>(*value);
82 } else {
83 return std::unexpected{std::make_error_code(std::errc::result_out_of_range)};
84 }
85 } else {
86 return std::unexpected{std::error_code{value.error()}};
87 }
88}
89
90}} // namespace hi::v1
STL namespace.
The HikoGUI namespace.
Definition array_generic.hpp:20
std::error_code delete_user_settings() noexcept
Delete all user-setting for the application.
Definition user_settings_win32_impl.hpp:80
std::expected< T, std::error_code > get_user_setting(std::string_view key) noexcept=delete
Get a user-setting for the application.
Definition user_settings_intf.hpp:77
std::expected< std::string, std::error_code > get_user_setting_string(std::string_view key) noexcept
Definition user_settings_win32_impl.hpp:29
std::error_code delete_user_setting(std::string_view key) noexcept
Delete a user-setting for the application.
Definition user_settings_win32_impl.hpp:75
std::error_code set_user_setting(std::string_view key, std::string_view value) noexcept
Set a user-setting for the application.
Definition user_settings_win32_impl.hpp:65
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T unexpected(T... args)