mirror of
https://github.com/matrix-construct/construct
synced 2024-09-30 04:38:52 +02: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::string name;
|
||||||
std::set<std::string> aliases;
|
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:
|
private:
|
||||||
void emplace();
|
void emplace();
|
||||||
|
|
||||||
public:
|
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(cmd &&) = delete;
|
||||||
cmd(const cmd &) = delete;
|
cmd(const cmd &) = delete;
|
||||||
virtual ~cmd() noexcept;
|
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 cmds
|
||||||
} // namespace ircd
|
} // namespace ircd
|
||||||
|
|
||||||
ircd::cmds::cmd::cmd(const std::string &name)
|
using namespace ircd;
|
||||||
:name{name}
|
|
||||||
{
|
|
||||||
emplace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ircd::cmds::cmd::cmd(const std::string &name,
|
cmds::cmd::cmd(const std::string &name,
|
||||||
const decltype(handler) &handler)
|
const decltype(handler) &handler)
|
||||||
:name{name}
|
:name{name}
|
||||||
,handler{handler}
|
,handler{handler}
|
||||||
|
@ -41,7 +37,7 @@ ircd::cmds::cmd::cmd(const std::string &name,
|
||||||
emplace();
|
emplace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::cmds::cmd::~cmd()
|
cmds::cmd::~cmd()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
cmds.erase(name);
|
cmds.erase(name);
|
||||||
|
@ -49,14 +45,14 @@ noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::cmds::cmd::operator()(client &client,
|
cmds::cmd::operator()(client &client,
|
||||||
line line)
|
line line)
|
||||||
{
|
{
|
||||||
handler(client, std::move(line));
|
handler(client, std::move(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::cmds::cmd::emplace()
|
cmds::cmd::emplace()
|
||||||
{
|
{
|
||||||
const auto iit(cmds.emplace(name, this));
|
const auto iit(cmds.emplace(name, this));
|
||||||
if(!iit.second)
|
if(!iit.second)
|
||||||
|
@ -65,8 +61,8 @@ ircd::cmds::cmd::emplace()
|
||||||
log::info("Registered command \"%s\" to handler @ %p", name.c_str(), this);
|
log::info("Registered command \"%s\" to handler @ %p", name.c_str(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::cmds::cmd &
|
cmds::cmd &
|
||||||
ircd::cmds::find(const std::string &name)
|
cmds::find(const std::string &name)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return *cmds.at(name);
|
return *cmds.at(name);
|
||||||
|
@ -76,8 +72,8 @@ catch(const std::out_of_range &e)
|
||||||
throw not_found("%s", name.c_str());
|
throw not_found("%s", name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::cmds::cmd *
|
cmds::cmd *
|
||||||
ircd::cmds::find(const std::string &name,
|
cmds::find(const std::string &name,
|
||||||
const std::nothrow_t &)
|
const std::nothrow_t &)
|
||||||
{
|
{
|
||||||
const auto it(cmds.find(name));
|
const auto it(cmds.find(name));
|
||||||
|
@ -85,7 +81,7 @@ ircd::cmds::find(const std::string &name,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::cmds::exists(const std::string &name)
|
cmds::exists(const std::string &name)
|
||||||
{
|
{
|
||||||
return cmds.count(name);
|
return cmds.count(name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue