From d5963532328ce5f1c9f266bf7e760b7d18a60c15 Mon Sep 17 00:00:00 2001 From: Lexi Winter Date: Mon, 23 Jun 2025 16:28:11 +0100 Subject: various updates --- nihil.config/string.ccm | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'nihil.config/string.ccm') diff --git a/nihil.config/string.ccm b/nihil.config/string.ccm index f3273c3..57770ae 100644 --- a/nihil.config/string.ccm +++ b/nihil.config/string.ccm @@ -4,20 +4,19 @@ module; -#include +#include #include -#include - export module nihil.config:string; import nihil; +import nihil.ucl; import :option; import :store; namespace nihil::config { -struct string final : option +export struct string final : option { string(std::string &storage, std::string_view name, @@ -28,6 +27,11 @@ struct string final : option store::get().register_option(this); } + ~string() + { + store::get().unregister_option(this); + } + auto get_string() const -> std::string override { return _storage; @@ -38,13 +42,20 @@ struct string final : option _storage = new_value; } - auto add_to_ucl(ucl_object_t *ucl) const -> void override + auto to_ucl() const -> ucl::object override + { + return ucl::string(_storage); + } + + auto from_ucl(ucl::object const &uclobj) -> void override { - auto ucl_value = ucl_object_fromstring_common( - _storage.data(), _storage.size(), - UCL_STRING_RAW); - ucl_object_insert_key(ucl, ucl_value, - name().data(), name().size(), true); + try { + _storage = object_cast(uclobj).value(); + is_default(false); + } catch (ucl::type_mismatch const &exc) { + throw error(std::format("'{}': expected string, not {}", + name(), str(exc.actual_type()))); + } } private: -- cgit v1.2.3