From fde4626fce45875a140b5ad8f99d12dbf06fe60b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 10 Oct 2016 21:09:17 -0700 Subject: [PATCH] ircd::cmds: Minor cleanup of cmds:: related. --- include/ircd/cmds.h | 7 +++---- ircd/cmds.cc | 30 +++++++++++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/include/ircd/cmds.h b/include/ircd/cmds.h index 566e3212e..9645141d1 100644 --- a/include/ircd/cmds.h +++ b/include/ircd/cmds.h @@ -34,16 +34,15 @@ struct cmd { std::string name; std::set aliases; - std::function handler; // Used if not overloaded + std::function 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; diff --git a/ircd/cmds.cc b/ircd/cmds.cc index fc0c4f328..2cb0b34ab 100644 --- a/ircd/cmds.cc +++ b/ircd/cmds.cc @@ -27,21 +27,17 @@ std::map 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, - const decltype(handler) &handler) +cmds::cmd::cmd(const std::string &name, + const decltype(handler) &handler) :name{name} ,handler{handler} { emplace(); } -ircd::cmds::cmd::~cmd() +cmds::cmd::~cmd() noexcept { cmds.erase(name); @@ -49,14 +45,14 @@ noexcept } void -ircd::cmds::cmd::operator()(client &client, - line line) +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,16 +72,16 @@ catch(const std::out_of_range &e) throw not_found("%s", name.c_str()); } -ircd::cmds::cmd * -ircd::cmds::find(const std::string &name, - const std::nothrow_t &) +cmds::cmd * +cmds::find(const std::string &name, + const std::nothrow_t &) { const auto it(cmds.find(name)); return it != end(cmds)? it->second : nullptr; } bool -ircd::cmds::exists(const std::string &name) +cmds::exists(const std::string &name) { return cmds.count(name); }