diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 18:34:18 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 18:34:18 +0100 |
| commit | 32b4443ba2ec5c3f7c09221ab9b21911a3126ef9 (patch) | |
| tree | cb6346997078626dc512e5e46e95796e375690ee /nihil.config/string.cc | |
| parent | d5963532328ce5f1c9f266bf7e760b7d18a60c15 (diff) | |
| download | nihil-32b4443ba2ec5c3f7c09221ab9b21911a3126ef9.tar.gz nihil-32b4443ba2ec5c3f7c09221ab9b21911a3126ef9.tar.bz2 | |
add separate module implementation files
Diffstat (limited to 'nihil.config/string.cc')
| -rw-r--r-- | nihil.config/string.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/nihil.config/string.cc b/nihil.config/string.cc new file mode 100644 index 0000000..6b201ae --- /dev/null +++ b/nihil.config/string.cc @@ -0,0 +1,57 @@ +/* + * This source code is released into the public domain. + */ + +module; + +#include <format> +#include <string> + +module nihil.config; + +import nihil.ucl; + +namespace nihil::config { + +string::string( + std::string &storage, + std::string_view name, + std::string_view description) noexcept + : option(name, description) + , _storage(storage) +{ + store::get().register_option(this); +} + +string::~string() +{ + store::get().unregister_option(this); +} + +auto string::get_string() const -> std::string +{ + return _storage; +} + +auto string::set_string(std::string_view new_value) -> void +{ + _storage = new_value; +} + +auto string::to_ucl() const -> ucl::object +{ + return ucl::string(_storage); +} + +auto string::from_ucl(ucl::object const &uclobj) -> void +{ + try { + _storage = object_cast<ucl::string>(uclobj).value(); + is_default(false); + } catch (ucl::type_mismatch const &exc) { + throw error(std::format("'{}': expected string, not {}", + name(), str(exc.actual_type()))); + } +} + +} // namespace nihil::config |
