mirror of
https://github.com/anope/anope.git
synced 2026-07-04 13:13:14 +02:00
Made NumberList take an arg to determin if it should pass numbers in descending order, fixes listing specific ranges being returned in descending order
This commit is contained in:
+9
-5
@@ -1130,19 +1130,23 @@ class ChanServTimer : public Timer
|
||||
|
||||
/** A class to process numbered lists (passed to most DEL/LIST/VIEW commands).
|
||||
* The function HandleNumber is called for every number in the list. Note that
|
||||
* it *always* gets called in descending order. This is so deleting the index passed
|
||||
* to the function from an array will not cause the other indexes passed to the function
|
||||
* to be incorrect. This keeps us from having to have an 'in use' flag on everything.
|
||||
* if descending is true it gets called in descending order. This is so deleting
|
||||
* the index passed to the function from an array will not cause the other indexes
|
||||
* passed to the function to be incorrect. This keeps us from having to have an
|
||||
* 'in use' flag on everything.
|
||||
*/
|
||||
class NumberList
|
||||
{
|
||||
private:
|
||||
std::set<unsigned> numbers;
|
||||
|
||||
bool desc;
|
||||
public:
|
||||
/** Processes a numbered list
|
||||
* @param list The list
|
||||
* @param descending True to make HandleNumber get called with numbers in descending order
|
||||
*/
|
||||
NumberList(const std::string &list);
|
||||
NumberList(const std::string &list, bool descending);
|
||||
|
||||
/** Destructor, does nothing
|
||||
*/
|
||||
@@ -1160,7 +1164,7 @@ class NumberList
|
||||
/** Called when there is an error with the numbered list
|
||||
* Return false to immediatly stop processing the list and return
|
||||
* This is all done before we start calling HandleNumber, so no numbers will have been processed yet
|
||||
* @param The list
|
||||
* @param list The list
|
||||
* @return false to stop processing
|
||||
*/
|
||||
virtual bool InvalidRange(const std::string &list);
|
||||
|
||||
@@ -20,7 +20,7 @@ class BadwordsListCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
bool SentHeader;
|
||||
public:
|
||||
BadwordsListCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list), u(_u), ci(_ci), SentHeader(false)
|
||||
BadwordsListCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class BadwordsDelCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
BadwordsDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list), u(_u), ci(_ci), Deleted(0)
|
||||
BadwordsDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class AccessListCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
bool SentHeader;
|
||||
public:
|
||||
AccessListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), SentHeader(false)
|
||||
AccessListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class AccessDelCallback : public NumberList
|
||||
std::string Nicks;
|
||||
bool Denied;
|
||||
public:
|
||||
AccessDelCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), Deleted(0), Denied(false)
|
||||
AccessDelCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), Deleted(0), Denied(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class AkickListCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
bool SentHeader;
|
||||
public:
|
||||
AkickListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), SentHeader(false)
|
||||
AkickListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class AkickDelCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
AkickDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list), u(_u), ci(_ci), Deleted(0)
|
||||
AkickDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -118,7 +118,7 @@ class XOPListCallback : public NumberList
|
||||
int *messages;
|
||||
bool SentHeader;
|
||||
public:
|
||||
XOPListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist, int _level, int *_messages) : NumberList(numlist), u(_u), ci(_ci), level(_level), messages(_messages), SentHeader(false)
|
||||
XOPListCallback(User *_u, ChannelInfo *_ci, const std::string &numlist, int _level, int *_messages) : NumberList(numlist, false), u(_u), ci(_ci), level(_level), messages(_messages), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ class XOPDelCallback : public NumberList
|
||||
unsigned Deleted;
|
||||
std::string Nicks;
|
||||
public:
|
||||
XOPDelCallback(User *_u, ChannelInfo *_ci, int *_messages, const std::string &numlist) : NumberList(numlist), u(_u), ci(_ci), messages(_messages), Deleted(0)
|
||||
XOPDelCallback(User *_u, ChannelInfo *_ci, int *_messages, const std::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), messages(_messages), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ class MemoDelCallback : public NumberList
|
||||
ChannelInfo *ci;
|
||||
MemoInfo *mi;
|
||||
public:
|
||||
MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list), u(_u), ci(_ci), mi(_mi)
|
||||
MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), mi(_mi)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class MemoListCallback : public NumberList
|
||||
MemoInfo *mi;
|
||||
bool SentHeader;
|
||||
public:
|
||||
MemoListCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list), u(_u), ci(_ci), mi(_mi), SentHeader(false)
|
||||
MemoListCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const std::string &list) : NumberList(list, false), u(_u), ci(_ci), mi(_mi), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class MemoListCallback : public NumberList
|
||||
User *u;
|
||||
MemoInfo *mi;
|
||||
public:
|
||||
MemoListCallback(User *_u, MemoInfo *_mi, const std::string &numlist) : NumberList(numlist), u(_u), mi(_mi)
|
||||
MemoListCallback(User *_u, MemoInfo *_mi, const std::string &numlist) : NumberList(numlist, false), u(_u), mi(_mi)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class AkillDelCallback : public NumberList
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
AkillDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
AkillDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class AkillListCallback : public NumberList
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
AkillListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
AkillListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class ExceptionDelCallback : public NumberList
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
ExceptionDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
ExceptionDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class ExceptionListCallback : public NumberList
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
ExceptionListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
ExceptionListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class SNLineDelCallback : public NumberList
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SNLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
SNLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class SNLineListCallback : public NumberList
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SNLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
SNLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class SNLineListCallback : public NumberList
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
DoList(u, x, Number - 1);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
@@ -110,7 +110,7 @@ class SNLineViewCallback : public SNLineListCallback
|
||||
notice_lang(Config.s_OperServ, u, OPER_SNLINE_VIEW_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
DoList(u, x, Number - 1);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
|
||||
@@ -19,7 +19,7 @@ class SQLineDelCallback : public NumberList
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SQLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
SQLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class SQLineDelCallback : public NumberList
|
||||
return;
|
||||
|
||||
++Deleted;
|
||||
DoDel(u, x);
|
||||
DoDel(u, x - 1);
|
||||
}
|
||||
|
||||
static void DoDel(User *u, XLine *x)
|
||||
@@ -56,7 +56,7 @@ class SQLineListCallback : public NumberList
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SQLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
SQLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class SQLineListCallback : public NumberList
|
||||
notice_lang(Config.s_OperServ, u, OPER_SQLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
DoList(u, x, Number - 1);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
|
||||
@@ -19,7 +19,7 @@ class SZLineDelCallback : public NumberList
|
||||
User *u;
|
||||
unsigned Deleted;
|
||||
public:
|
||||
SZLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), Deleted(0)
|
||||
SZLineDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class SZLineListCallback : public NumberList
|
||||
User *u;
|
||||
bool SentHeader;
|
||||
public:
|
||||
SZLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist), u(_u), SentHeader(false)
|
||||
SZLineListCallback(User *_u, const std::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class SZLineListCallback : public NumberList
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
DoList(u, x, Number - 1);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
@@ -108,7 +108,7 @@ class SZLineViewCallback : public SZLineListCallback
|
||||
notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, x, Number);
|
||||
DoList(u, x, Number - 1);
|
||||
}
|
||||
|
||||
static void DoList(User *u, XLine *x, unsigned Number)
|
||||
|
||||
+13
-3
@@ -224,7 +224,7 @@ const char *merge_args(int argc, char **argv)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
NumberList::NumberList(const std::string &list)
|
||||
NumberList::NumberList(const std::string &list, bool descending) : desc(descending)
|
||||
{
|
||||
char *error;
|
||||
commasepstream sep(list);
|
||||
@@ -284,9 +284,19 @@ NumberList::~NumberList()
|
||||
|
||||
void NumberList::Process()
|
||||
{
|
||||
for (std::set<unsigned>::reverse_iterator it = numbers.rbegin(); it != numbers.rend(); ++it)
|
||||
if (this->desc)
|
||||
{
|
||||
this->HandleNumber(*it);
|
||||
for (std::set<unsigned>::reverse_iterator it = numbers.rbegin(); it != numbers.rend(); ++it)
|
||||
{
|
||||
this->HandleNumber(*it);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (std::set<unsigned>::iterator it = numbers.begin(); it != numbers.end(); ++it)
|
||||
{
|
||||
this->HandleNumber(*it);
|
||||
}
|
||||
}
|
||||
|
||||
delete this;
|
||||
|
||||
Reference in New Issue
Block a user