mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 23:40:57 +01:00
ircd::cmds: Minor cleanup of cmds:: related.
This commit is contained in:
parent
43b07d1180
commit
fde4626fce
2 changed files with 16 additions and 21 deletions
|
@ -34,16 +34,15 @@ struct cmd
|
|||
{
|
||||
std::string name;
|
||||
std::set<std::string> aliases;
|
||||
std::function<void (client &, line)> handler; // Used if not overloaded
|
||||
std::function<void (client &, line)> handler; // Not-overriding calls this by default
|
||||
|
||||
private:
|
||||
void emplace();
|
||||
|
||||
public:
|
||||
virtual void operator()(client &, line);
|
||||
virtual void operator()(client &, line); // Handle this command by overriding
|
||||
|
||||
cmd(const std::string &name);
|
||||
cmd(const std::string &name, const decltype(handler) &handler);
|
||||
cmd(const std::string &name, const decltype(handler) &handler = {});
|
||||
cmd(cmd &&) = delete;
|
||||
cmd(const cmd &) = delete;
|
||||
virtual ~cmd() noexcept;
|
||||
|
|
24
ircd/cmds.cc
24
ircd/cmds.cc
|
@ -27,13 +27,9 @@ std::map<std::string, cmd *, case_insensitive_less> cmds;
|
|||
} // namespace cmds
|
||||
} // namespace ircd
|
||||
|
||||
ircd::cmds::cmd::cmd(const std::string &name)
|
||||
:name{name}
|
||||
{
|
||||
emplace();
|
||||
}
|
||||
using namespace ircd;
|
||||
|
||||
ircd::cmds::cmd::cmd(const std::string &name,
|
||||
cmds::cmd::cmd(const std::string &name,
|
||||
const decltype(handler) &handler)
|
||||
:name{name}
|
||||
,handler{handler}
|
||||
|
@ -41,7 +37,7 @@ ircd::cmds::cmd::cmd(const std::string &name,
|
|||
emplace();
|
||||
}
|
||||
|
||||
ircd::cmds::cmd::~cmd()
|
||||
cmds::cmd::~cmd()
|
||||
noexcept
|
||||
{
|
||||
cmds.erase(name);
|
||||
|
@ -49,14 +45,14 @@ noexcept
|
|||
}
|
||||
|
||||
void
|
||||
ircd::cmds::cmd::operator()(client &client,
|
||||
cmds::cmd::operator()(client &client,
|
||||
line line)
|
||||
{
|
||||
handler(client, std::move(line));
|
||||
}
|
||||
|
||||
void
|
||||
ircd::cmds::cmd::emplace()
|
||||
cmds::cmd::emplace()
|
||||
{
|
||||
const auto iit(cmds.emplace(name, this));
|
||||
if(!iit.second)
|
||||
|
@ -65,8 +61,8 @@ ircd::cmds::cmd::emplace()
|
|||
log::info("Registered command \"%s\" to handler @ %p", name.c_str(), this);
|
||||
}
|
||||
|
||||
ircd::cmds::cmd &
|
||||
ircd::cmds::find(const std::string &name)
|
||||
cmds::cmd &
|
||||
cmds::find(const std::string &name)
|
||||
try
|
||||
{
|
||||
return *cmds.at(name);
|
||||
|
@ -76,8 +72,8 @@ catch(const std::out_of_range &e)
|
|||
throw not_found("%s", name.c_str());
|
||||
}
|
||||
|
||||
ircd::cmds::cmd *
|
||||
ircd::cmds::find(const std::string &name,
|
||||
cmds::cmd *
|
||||
cmds::find(const std::string &name,
|
||||
const std::nothrow_t &)
|
||||
{
|
||||
const auto it(cmds.find(name));
|
||||
|
@ -85,7 +81,7 @@ ircd::cmds::find(const std::string &name,
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::cmds::exists(const std::string &name)
|
||||
cmds::exists(const std::string &name)
|
||||
{
|
||||
return cmds.count(name);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue