aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/string.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-21 17:18:57 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-21 17:18:57 +0100
commitd27d1302d1fa1b96bf8f53f17fce947f19d21330 (patch)
treef56ef29d7816c3b574b3359c746355a44e3b0819 /nihil.config/string.ccm
parent75c6b5fee029ec95e7e45e18525e3e78b9616f48 (diff)
downloadnihil-d27d1302d1fa1b96bf8f53f17fce947f19d21330.tar.gz
nihil-d27d1302d1fa1b96bf8f53f17fce947f19d21330.tar.bz2
add nihil.config (incomplete)
Diffstat (limited to 'nihil.config/string.ccm')
-rw-r--r--nihil.config/string.ccm54
1 files changed, 54 insertions, 0 deletions
diff --git a/nihil.config/string.ccm b/nihil.config/string.ccm
new file mode 100644
index 0000000..f3273c3
--- /dev/null
+++ b/nihil.config/string.ccm
@@ -0,0 +1,54 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+module;
+
+#include <stdexcept>
+#include <string>
+
+#include <ucl++.h>
+
+export module nihil.config:string;
+
+import nihil;
+import :option;
+import :store;
+
+namespace nihil::config {
+
+struct string final : option
+{
+ string(std::string &storage,
+ std::string_view name,
+ std::string_view description) noexcept
+ : option(name, description)
+ , _storage(storage)
+ {
+ store::get().register_option(this);
+ }
+
+ auto get_string() const -> std::string override
+ {
+ return _storage;
+ };
+
+ auto set_string(std::string_view new_value) -> void override
+ {
+ _storage = new_value;
+ }
+
+ auto add_to_ucl(ucl_object_t *ucl) const -> 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);
+ }
+
+private:
+ std::string &_storage;
+};
+
+} // namespace nihil::config