1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 17:04:47 +02:00
Files
2026-01-01 18:07:12 +00:00

63 lines
1.9 KiB
C++

// Anope IRC Services <https://www.anope.org/>
//
// Copyright (C) 2003-2026 Anope Contributors
//
// Anope is free software. You can use, modify, and/or distribute it under the
// terms of version 2 of the GNU General Public License. See docs/LICENSE.txt
// for the complete terms of this license and docs/AUTHORS.txt for a list of
// contributors.
//
// Based on the original code of Epona by Lara
// Based on the original code of Services by Andy Church
//
// SPDX-License-Identifier: GPL-2.0-only
#pragma once
#include "services.h"
#include "anope.h"
/** 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
* 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 CoreExport NumberList
{
private:
bool is_valid = true;
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 Anope::string &list, bool descending);
/** Destructor, does nothing
*/
virtual ~NumberList() = default;
/** Should be called after the constructors are done running. This calls the callbacks.
*/
void Process();
/** Called with a number from the list
* @param number The number
*/
virtual void HandleNumber(unsigned number);
/** Called when there is an error with the numbered list
* Return false to immediately stop processing the list and return
* This is all done before we start calling HandleNumber, so no numbers will have been processed yet
* @param list The list
* @return false to stop processing
*/
virtual bool InvalidRange(const Anope::string &list);
};