RegisterCommand::Commands -> CommandMap
This name is vague. Change-Id: I255e2d94a72193ca1a10f2abf4a3011c75ec9ecf
This commit is contained in:
+10
-5
@@ -12,19 +12,24 @@ extern char * * environ __attribute__((weak));
|
||||
|
||||
namespace nix {
|
||||
|
||||
RegisterCommand::Commands * RegisterCommand::commands = nullptr;
|
||||
RegisterCommand::CommandMap * RegisterCommand::commands = nullptr;
|
||||
|
||||
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
|
||||
{
|
||||
nix::Commands res;
|
||||
for (auto & [name, command] : *RegisterCommand::commands)
|
||||
for (auto & [name, command] : *RegisterCommand::commands) {
|
||||
if (name.size() == prefix.size() + 1) {
|
||||
bool equal = true;
|
||||
for (size_t i = 0; i < prefix.size(); ++i)
|
||||
if (name[i] != prefix[i]) equal = false;
|
||||
if (equal)
|
||||
for (size_t i = 0; i < prefix.size(); ++i) {
|
||||
if (name[i] != prefix[i]) {
|
||||
equal = false;
|
||||
}
|
||||
}
|
||||
if (equal) {
|
||||
res.insert_or_assign(name[prefix.size()], command);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,16 +264,16 @@ struct StorePathCommand : public StorePathsCommand
|
||||
*/
|
||||
struct RegisterCommand
|
||||
{
|
||||
typedef std::map<
|
||||
using CommandMap = std::map<
|
||||
std::vector<std::string>,
|
||||
std::function<ref<Command>(AsyncIoRoot & aio)>
|
||||
> Commands;
|
||||
static Commands * commands;
|
||||
>;
|
||||
static CommandMap * commands;
|
||||
|
||||
RegisterCommand(std::vector<std::string> && name,
|
||||
std::function<ref<Command>(AsyncIoRoot & aio)> command)
|
||||
{
|
||||
if (!commands) commands = new Commands;
|
||||
if (!commands) commands = new CommandMap;
|
||||
commands->emplace(name, command);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
LegacyCommands::Commands * LegacyCommands::commands = 0;
|
||||
LegacyCommands::LegacyCommandMap * LegacyCommands::commands = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ typedef std::function<void(AsyncIoRoot &, std::string, std::list<std::string>)>
|
||||
|
||||
struct LegacyCommands
|
||||
{
|
||||
typedef std::map<std::string, MainFunction> Commands;
|
||||
static Commands * commands;
|
||||
using LegacyCommandMap = std::map<std::string, MainFunction>;
|
||||
static LegacyCommandMap * commands;
|
||||
|
||||
static void add(const std::string & name, MainFunction fun)
|
||||
{
|
||||
if (!commands) commands = new Commands;
|
||||
if (!commands) commands = new LegacyCommandMap;
|
||||
(*commands)[name] = fun;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user