diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-12 18:05:18 +1100 |
| commit | 1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (patch) | |
| tree | 222dfcd07a1e40716127a347bbfd7119ce3d0984 /src/client/settings.hh | |
initial commit
Diffstat (limited to 'src/client/settings.hh')
| -rw-r--r-- | src/client/settings.hh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/client/settings.hh b/src/client/settings.hh new file mode 100644 index 0000000..d65022b --- /dev/null +++ b/src/client/settings.hh @@ -0,0 +1,52 @@ +#ifndef CLIENT_SETTINGS_HH_ +#define CLIENT_SETTINGS_HH_ + +#include <filesystem> +#include <fstream> +#include <optional> +#include <stdlib.h> +#include <string> + +#include <boost/lexical_cast.hpp> + +#include "client/shared.hh" +#include "shared/shared.hh" + +// This settings file just provides functionality for persistent variables, +// it has nothing to do with rendering or our window manager. + +namespace client { +namespace settings { + +void set_setting_str( + const std::pair<const std::string&, const std::string&> loc, + const std::string& value) noexcept; + +std::string +get_setting_str(const std::pair<const std::string&, const std::string&> loc, + const std::string default_value) noexcept; + +// Attempts to read the setting in the file, returning it if it exists. +// If either name or category does not exist, writes the default value in +// the file under the expected headings. +template <typename T> +T get(const std::pair<const std::string, const std::string>& loc, + const T& default_value) noexcept { + const std::string value = + get_setting_str(loc, boost::lexical_cast<std::string>(default_value)); + return boost::lexical_cast<T>(value); +} + +// Attempts to set the setting in the file, overwriting the pre-existing +// value or writing a new entry. +template <typename T> +void set(const std::pair<const std::string, const std::string>& loc, + const T& value) noexcept { + set_setting_str(loc, boost::lexical_cast<std::string>(value)); +} + +void save() noexcept; +} // namespace settings +} // namespace client + +#endif |
