summaryrefslogtreecommitdiff
path: root/src/misc.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-06-26 19:30:28 -0400
committerAdam <Adam@anope.org>2014-06-26 19:30:28 -0400
commitd492923610d9c9146b2a2b63de38deab2cfd4ca7 (patch)
tree5a3663883bd8247e10eeae4f334c4c6a36ccef96 /src/misc.cpp
parentee3289029d61da12013e0f5a3e4faf2d07543a0e (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.cpp45
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)