diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-23 16:28:11 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-23 16:28:11 +0100 |
| commit | d5963532328ce5f1c9f266bf7e760b7d18a60c15 (patch) | |
| tree | 28e8d4b98f2f3adbd2f02bcc656ad74e626677c9 /nihil.config/option.ccm | |
| parent | 0fa623093366351ad47583f47add6e51f56a56d8 (diff) | |
| download | nihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.gz nihil-d5963532328ce5f1c9f266bf7e760b7d18a60c15.tar.bz2 | |
various updates
Diffstat (limited to 'nihil.config/option.ccm')
| -rw-r--r-- | nihil.config/option.ccm | 26 |
1 files changed, 23 insertions, 3 deletions
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 <iostream> #include <string> #include <ucl++.h> 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 |
