blob: 45de35eb6e667f557edfe17262442ead91a295b6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// This source code is released into the public domain.
export module nihil.config:store;
// The configuration store. There should only be one of these.
import nihil.std;
import nihil.core;
namespace nihil::config {
export struct option;
struct store final {
/*
* Get the global config store.
*/
[[nodiscard]] static auto get() -> store &;
/*
* Register a new value with the config store.
*/
[[nodiscard]] auto register_option(this store &, option *object)
-> std::expected<void, error>;
/*
* Remove a value from the config store.
*/
[[nodiscard]] auto unregister_option(this store &, option *object)
-> std::expected<void, error>;
/*
* Fetch an existing value in the config store.
*/
[[nodiscard]] auto fetch(this store const &, std::string_view name)
-> std::expected<option const *, error>;
[[nodiscard]] auto fetch(this store &, std::string_view name)
-> std::expected<option *, error>;
/*
* Fetch all values in the configuration store.
*/
[[nodiscard]] auto all(this store const &self)
-> nihil::generator<option const *>;
[[nodiscard]] auto all(this store &self)
-> nihil::generator<option *>;
// Not movable or copyable.
store(store const &) = delete;
store(store &&) = delete;
auto operator=(store const &) -> store & = delete;
auto operator=(store &&) -> store & = delete;
private:
store();
std::map<std::string_view, option *> m_options;
};
/*
* The public API.
*/
export auto get_option(std::string_view option_name)
-> std::expected<option *, error>;
} // namespace nihil::config
|