anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

lists.h (2559B)

      1 /*
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #ifndef LISTS_H
     13 #define LISTS_H
     14 
     15 #include "services.h"
     16 #include "anope.h"
     17 
     18 /** A class to process numbered lists (passed to most DEL/LIST/VIEW commands).
     19  * The function HandleNumber is called for every number in the list. Note that
     20  * if descending is true it gets called in descending order. This is so deleting
     21  * the index passed to the function from an array will not cause the other indexes
     22  * passed to the function to be incorrect. This keeps us from having to have an
     23  * 'in use' flag on everything.
     24  */
     25 class CoreExport NumberList
     26 {
     27  private:
     28 	bool is_valid;
     29 
     30 	std::set<unsigned> numbers;
     31 
     32 	bool desc;
     33  public:
     34 	/** Processes a numbered list
     35 	 * @param list The list
     36 	 * @param descending True to make HandleNumber get called with numbers in descending order
     37 	 */
     38 	NumberList(const Anope::string &list, bool descending);
     39 
     40 	/** Destructor, does nothing
     41 	 */
     42 	virtual ~NumberList();
     43 
     44 	/** Should be called after the constructors are done running. This calls the callbacks.
     45 	 */
     46 	void Process();
     47 
     48 	/** Called with a number from the list
     49 	 * @param number The number
     50 	 */
     51 	virtual void HandleNumber(unsigned number);
     52 
     53 	/** Called when there is an error with the numbered list
     54 	 * Return false to immediately stop processing the list and return
     55 	 * This is all done before we start calling HandleNumber, so no numbers will have been processed yet
     56 	 * @param list The list
     57 	 * @return false to stop processing
     58 	 */
     59 	virtual bool InvalidRange(const Anope::string &list);
     60 };
     61 
     62 /** This class handles formatting LIST/VIEW replies.
     63  */
     64 class CoreExport ListFormatter
     65 {
     66  public:
     67 	typedef std::map<Anope::string, Anope::string> ListEntry;
     68  private:
     69 	NickCore *nc;
     70 	std::vector<Anope::string> columns;
     71 	std::vector<ListEntry> entries;
     72  public:
     73 	ListFormatter(NickCore *nc);
     74 	ListFormatter &AddColumn(const Anope::string &name);
     75 	void AddEntry(const ListEntry &entry);
     76 	bool IsEmpty() const;
     77 	void Process(std::vector<Anope::string> &);
     78 };
     79 
     80 /** This class handles formatting INFO replies
     81  */
     82 class CoreExport InfoFormatter
     83 {
     84 	NickCore *nc;
     85 	std::vector<std::pair<Anope::string, Anope::string> > replies;
     86 	unsigned longest;
     87  public:
     88 	InfoFormatter(NickCore *nc);
     89 	void Process(std::vector<Anope::string> &);
     90 	Anope::string &operator[](const Anope::string &key);
     91 	void AddOption(const Anope::string &opt);
     92 };
     93 
     94 #endif // LISTS_H