HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
user_settings.hpp
1
2
3#pragma once
4
5#include "../utility/module.hpp"
6#include <optional>
7#include <string>
8#include <string_view>
9#include <cstdlib>
10
11namespace hi { inline namespace v1 {
12
13[[nodiscard]] std::optional<std::string> get_user_setting_string(std::string_view key);
14[[nodiscard]] std::optional<long long> get_user_setting_integral(std::string_view key);
15
26template<typename T>
27[[nodiscard]] std::optional<T> get_user_setting(std::string_view key) = delete;
28
38void set_user_setting(std::string_view key, std::string_view value);
39
49void set_user_setting(std::string_view key, long long value);
50
59void delete_user_setting(std::string_view key);
60
64
65template<>
66[[nodiscard]] inline std::optional<std::string> get_user_setting(std::string_view key)
67{
68 return get_user_setting_string(key);
69}
70
71template<std::integral T>
72[[nodiscard]] inline std::optional<T> get_user_setting(std::string_view key)
73{
74 if (hilet value = get_user_setting_integral(key)) {
75 if (can_narrow_cast<T>(*value)) {
76 return narrow_cast<T>(*value);
77 } else {
78 throw std::out_of_range(std::format("Integer {} out of range", *value));
79 }
80 } else {
81 return std::nullopt;
82 }
83}
84
85}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
void delete_user_setting(std::string_view key)
Delete a user-setting for the application.
void set_user_setting(std::string_view key, std::string_view value)
Set a user-setting for the application.
void delete_user_settings()
Delete all user-setting for the application.
std::optional< T > get_user_setting(std::string_view key)=delete
Get a user-setting for the application.
Definition user_settings.hpp:72