aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.config/store.ccm
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-23 18:34:18 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-23 18:34:18 +0100
commit32b4443ba2ec5c3f7c09221ab9b21911a3126ef9 (patch)
treecb6346997078626dc512e5e46e95796e375690ee /nihil.config/store.ccm
parentd5963532328ce5f1c9f266bf7e760b7d18a60c15 (diff)
downloadnihil-32b4443ba2ec5c3f7c09221ab9b21911a3126ef9.tar.gz
nihil-32b4443ba2ec5c3f7c09221ab9b21911a3126ef9.tar.bz2
add separate module implementation files
Diffstat (limited to 'nihil.config/store.ccm')
-rw-r--r--nihil.config/store.ccm68
1 files changed, 10 insertions, 58 deletions
diff --git a/nihil.config/store.ccm b/nihil.config/store.ccm
index e0eebc0..77b44b5 100644
--- a/nihil.config/store.ccm
+++ b/nihil.config/store.ccm
@@ -9,12 +9,12 @@ module;
*/
#include <coroutine>
-#include <filesystem>
-#include <format>
+#include <string>
#include <map>
export module nihil.config:store;
+import nihil;
import :error;
import :option;
@@ -22,16 +22,8 @@ namespace nihil::config {
// Exception thrown on an attempt to fetch an undefined option.
export struct unknown_option final : error {
- unknown_option(std::string_view option_name)
- : error(std::format("unknown configuration variable '{}'",
- option_name))
- , _option_name(option_name)
- {}
-
- auto option_name(this unknown_option const &self) -> std::string_view
- {
- return self._option_name;
- }
+ unknown_option(std::string_view option_name);
+ auto option_name(this unknown_option const &self) -> std::string_view;
private:
std::string _option_name;
@@ -41,64 +33,27 @@ struct store final {
/*
* Get the global config store.
*/
- static auto get() -> store& {
- if (instance == nullptr)
- instance = new store;
-
- return *instance;
- }
-
+ static auto get() -> store &;
/*
* Register a new value with the config store.
*/
- auto register_option(this store &self, option *object) -> void
- {
- auto [it, okay] = self.options.insert(
- std::pair{object->name(), object});
-
- if (!okay)
- throw error(std::format(
- "INTERNAL ERROR: attempt to register "
- "duplicate config value '{0}'",
- object->name()));
- }
+ auto register_option(this store &self, option *object) -> void;
/*
* Remove a value from the config store.
*/
- auto unregister_option(this store &self, option *object) -> void
- {
- auto it = self.options.find(object->name());
- if (it == self.options.end())
- throw error(std::format(
- "INTERNAL ERROR: attempt to unregister "
- "non-existent config value '{}'",
- object->name()));
-
- self.options.erase(it);
- }
+ auto unregister_option(this store &self, option *object) -> void;
/*
* Fetch an existing value in the config store.
*/
- auto fetch(this store const &self, std::string_view name)
- -> option &
- {
- if (auto it = self.options.find(name); it != self.options.end())
- return *it->second;
-
- throw unknown_option(name);
- }
+ auto fetch(this store const &self, std::string_view name) -> option &;
/*
* Fetch all values in the configuration store.
*/
- auto all(this auto &&self) -> nihil::generator<option const &>
- {
- for (auto &&it : self.options)
- co_yield *it.second;
- }
+ auto all(this store const &self) -> nihil::generator<option const &>;
// Not movable or copyable.
store(store const &) = delete;
@@ -120,9 +75,6 @@ private:
/*
* The public API.
*/
-export auto get_option(std::string_view option_name) -> option &
-{
- return store::get().fetch(option_name);
-}
+export auto get_option(std::string_view option_name) -> option &;
} // namespace nihil::config