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 /src/misc.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 'src/misc.cpp')
-rw-r--r-- | src/misc.cpp | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/src/misc.cpp b/src/misc.cpp index b6891d669..c347b76a4 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -28,11 +28,13 @@ #include <netdb.h> #endif -NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending) +NumberList::NumberList(const Anope::string &list, bool descending, std::function<void(unsigned int)> nf, std::function<void(void)> ef) : endf(ef) { Anope::string error; commasepstream sep(list); Anope::string token; + bool is_valid = true; + std::set<unsigned> numbers; sep.GetToken(token); if (token.empty()) @@ -56,11 +58,8 @@ NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(tr if (!error.empty()) { - if (!this->InvalidRange(list)) - { - is_valid = false; - return; - } + is_valid = false; + return; } } else @@ -81,44 +80,24 @@ NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(tr if (!error.empty() || !error2.empty()) { - if (!this->InvalidRange(list)) - { - is_valid = false; - return; - } + is_valid = false; + return; } } } while (sep.GetToken(token)); -} - -NumberList::~NumberList() -{ -} -void NumberList::Process() -{ if (!is_valid) return; - if (this->desc) - { - for (std::set<unsigned>::reverse_iterator it = numbers.rbegin(), it_end = numbers.rend(); it != it_end; ++it) - this->HandleNumber(*it); - } + if (descending) + std::for_each(numbers.rbegin(), numbers.rend(), nf); else - { - for (std::set<unsigned>::iterator it = numbers.begin(), it_end = numbers.end(); it != it_end; ++it) - this->HandleNumber(*it); - } + std::for_each(numbers.begin(), numbers.end(), nf); } -void NumberList::HandleNumber(unsigned) -{ -} - -bool NumberList::InvalidRange(const Anope::string &) +NumberList::~NumberList() { - return true; + endf(); } ListFormatter::ListFormatter(NickServ::Account *acc) : nc(acc) |