blob: 5e311953eb07900b336b36d2d86a5211851262e7 (
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
|
// This source code is released into the public domain.
export module nihil.cli:registry;
import nihil.std;
namespace nihil {
export struct command;
///////////////////////////////////////////////////////////////////////
// Command registry storage. This is where command::command() registers
// itself when the global command objects are constructed at startup.
//
// Because we sometimes create stub commands dynamically, the registry
// storage is a list of shared_ptr<command>. The "real" commands (which
// refer to global objects) will be created with a null deleter so they
// are never deleted. This allows real and stub commands to mix in the
// same command_tree.
// Get the current registry.
auto get_registry() -> std::vector<std::shared_ptr<command>> &
{
static auto commands = std::vector<std::shared_ptr<command>>();
return commands;
}
// Register a new command.
auto register_command(command *cmd) noexcept -> void
{
auto constexpr null_deleter = [] (command const *) -> void {};
get_registry().emplace_back(cmd, null_deleter);
}
} // namespace nihil
|