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/option.ccm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'nihil.config/option.ccm') diff --git a/nihil.config/option.ccm b/nihil.config/option.ccm index 207eb65..1be542e 100644 --- a/nihil.config/option.ccm +++ b/nihil.config/option.ccm @@ -4,13 +4,14 @@ module; +#include #include #include export module nihil.config:option; -import nihil; +import nihil.ucl; import :error; namespace nihil::config { @@ -52,10 +53,16 @@ export struct option } /* - * Add this option to a UCL object. This is used when writing the + * Return this object as a UCL object. This is used when writing the * configuration file. */ - virtual void add_to_ucl(ucl_object_t *) const = 0; + virtual auto to_ucl() const -> ucl::object = 0; + + /* + * Set this object from a UCL object. This is used when reading the + * configuration file. + */ + virtual auto from_ucl(ucl::object const &) -> void = 0; // Not copyable or movable. option(option const &) = delete; @@ -69,6 +76,11 @@ protected: { } + auto is_default(bool b) -> void + { + _is_default = b; + } + /* * Get or set this option as a string. */ @@ -81,4 +93,12 @@ private: bool _is_default = true; }; +/* + * Make options printable. This is mostly useful for testing. + */ +export auto operator<<(std::ostream &strm, option const &opt) -> std::ostream & +{ + return strm << "<" << opt.name() << "=" << opt.string() << ">"; +} + } // namespace nihil -- cgit v1.2.3