aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/string.ccm
diff options
context:
space:
mode:
Diffstat (limited to 'nihil.config/string.ccm')
-rw-r--r--nihil.config/string.ccm56
1 files changed, 56 insertions, 0 deletions
diff --git a/nihil.config/string.ccm b/nihil.config/string.ccm
new file mode 100644
index 0000000..668bbc0
--- /dev/null
+++ b/nihil.config/string.ccm
@@ -0,0 +1,56 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+module;
+
+#include <expected>
+#include <format>
+#include <string>
+
+export module nihil.config:string;
+
+import nihil.ucl;
+import :option;
+
+namespace nihil::config {
+
+/*
+ * A string option. The backing type is std::string.
+ */
+export struct string final : option
+{
+ string(std::string &storage,
+ std::string_view name,
+ std::string_view description) noexcept;
+
+ ~string();
+
+ /*
+ * Get this option as a string; simply returns the storage.
+ */
+ [[nodiscard]] auto get_string() const -> std::string override;
+
+ /*
+ * Set this option to a string value; assigns to the storage.
+ */
+ [[nodiscard]] auto set_string(std::string_view new_value)
+ -> std::expected<void, error> override;
+
+ /*
+ * Convert this option to a UCL object.
+ */
+ [[nodiscard]] auto get_ucl() const
+ -> std::expected<ucl::object, error> override;
+
+ /*
+ * Set this option from a UCL object.
+ */
+ [[nodiscard]] auto set_ucl(ucl::object const &uclobj)
+ -> std::expected<void, error> override;
+
+private:
+ std::string &m_storage;
+};
+
+} // namespace nihil::config