aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/string.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-23 16:28:11 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-23 16:28:11 +0100
commitd5963532328ce5f1c9f266bf7e760b7d18a60c15 (patch)
tree28e8d4b98f2f3adbd2f02bcc656ad74e626677c9 /nihil.config/string.ccm
parent0fa623093366351ad47583f47add6e51f56a56d8 (diff)
downloadnihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.gz
nihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.bz2
various updates
Diffstat (limited to 'nihil.config/string.ccm')
-rw-r--r--nihil.config/string.ccm31
1 files changed, 21 insertions, 10 deletions
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 <stdexcept>
+#include <format>
#include <string>
-#include <ucl++.h>
-
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<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())));
+ }
}
private: