diff options
| author | Adam <Adam@anope.org> | 2014-06-26 19:30:28 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-06-26 19:30:28 -0400 |
| commit | d492923610d9c9146b2a2b63de38deab2cfd4ca7 (patch) | |
| tree | 5a3663883bd8247e10eeae4f334c4c6a36ccef96 /modules/commands/os_sxline.cpp | |
| parent | ee3289029d61da12013e0f5a3e4faf2d07543a0e (diff) | |
Change NumberList to take std::function's and use lambda closures
instead of having to create full classes in order to process number
lists.
Diffstat (limited to 'modules/commands/os_sxline.cpp')
| -rw-r--r-- | modules/commands/os_sxline.cpp | 95 |
1 files changed, 30 insertions, 65 deletions
diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index e1c637a2e..b14820229 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -11,49 +11,6 @@ #include "module.h" -class SXLineDelCallback : public NumberList -{ - XLineManager *xlm; - Command *command; - CommandSource &source; - unsigned deleted; - public: - SXLineDelCallback(XLineManager *x, Command *c, CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), xlm(x), command(c), source(_source), deleted(0) - { - } - - ~SXLineDelCallback() - { - if (!deleted) - source.Reply(_("No matching entries on the {0} list."), source.command); - else if (deleted == 1) - source.Reply(_("Deleted \0021\002 entry from the {0} list."), source.command); - else - source.Reply(_("Deleted \002{0}\002 entries from the {1} list."), deleted, source.command); - } - - void HandleNumber(unsigned number) override - { - if (!number) - return; - - XLine *x = this->xlm->GetEntry(number - 1); - - if (!x) - return; - - Log(LOG_ADMIN, source, command) << "to remove " << x->mask << " from the list"; - - ++deleted; - DoDel(this->xlm, source, x); - } - - static void DoDel(XLineManager *xlm, CommandSource &source, XLine *x) - { - xlm->DelXLine(x); - } -}; - class CommandOSSXLineBase : public Command { private: @@ -80,8 +37,30 @@ class CommandOSSXLineBase : public Command if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SXLineDelCallback list(this->xlm(), this, source, mask); - list.Process(); + unsigned int deleted = 0; + + NumberList(mask, true, + [&](unsigned int number) + { + XLine *x = this->xlm()->GetEntry(number - 1); + + if (!x) + return; + + Log(LOG_ADMIN, source, this) << "to remove " << x->mask << " from the list"; + + ++deleted; + this->xlm()->DelXLine(x); + }, + [&]() + { + if (!deleted) + source.Reply(_("No matching entries on the {0} list."), source.command); + else if (deleted == 1) + source.Reply(_("Deleted \0021\002 entry from the {0} list."), source.command); + else + source.Reply(_("Deleted \002{0}\002 entries from the {1} list."), deleted, source.command); + }); } else { @@ -95,7 +74,7 @@ class CommandOSSXLineBase : public Command Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, this->xlm()); - SXLineDelCallback::DoDel(this->xlm(), source, x); + this->xlm()->DelXLine(x); source.Reply(_("\002{0}\002 deleted from the {1} list."), mask, source.command); Log(LOG_ADMIN, source, this) << "to remove " << mask << " from the list"; } @@ -116,22 +95,10 @@ class CommandOSSXLineBase : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - class SXLineListCallback : public NumberList - { - XLineManager *xlm; - CommandSource &source; - ListFormatter &list; - public: - SXLineListCallback(XLineManager *x, CommandSource &_source, ListFormatter &_list, const Anope::string &numlist) : NumberList(numlist, false), xlm(x), source(_source), list(_list) - { - } - - void HandleNumber(unsigned number) override + NumberList(mask, false, + [&](unsigned int number) { - if (!number) - return; - - const XLine *x = this->xlm->GetEntry(number - 1); + const XLine *x = this->xlm()->GetEntry(number - 1); if (!x) return; @@ -144,10 +111,8 @@ class CommandOSSXLineBase : public Command entry["Expires"] = Anope::Expires(x->expires, source.nc); entry["Reason"] = x->reason; list.AddEntry(entry); - } - } - sl_list(this->xlm(), source, list, mask); - sl_list.Process(); + }, + []{}); } else { |
