]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/cull_list.h
Remove an O(log n) in favour of an O(1) operation, and tidy up culllist some more
[user/henk/code/inspircd.git] / include / cull_list.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __CULLLIST_H__
15 #define __CULLLIST_H__
16
17 /** The CullList class is used by the core to create lists of users
18  * prior to actually quitting (and deleting the objects) all at once.
19  * to quitting them all at once. This is faster than quitting
20  * them within the loop, as the loops become tighter with
21  * little or no comparisons within them. The CullList class
22  * operates by allowing the programmer to push users onto
23  * the list, each with a seperate quit reason, and then, once
24  * the list is complete, call a method to flush the list,
25  * quitting all the users upon it. A CullList may hold local
26  * or remote users, but it may only hold each user once. If
27  * you attempt to add the same user twice, then the second
28  * attempt will be ignored.
29  *
30  * NOTE: Don't use this outside core, use the QuitUser method like everyone else!
31  */
32 class CoreExport CullList : public classbase
33 {
34  private:
35         /** Creator of this CullList
36          */
37         InspIRCd* ServerInstance;
38
39         /** Holds a list of users being quit.
40          * See the information for CullItem for
41          * more information.
42          */
43         std::vector<User *> list;
44
45  public:
46         /** Constructor.
47          * @param Instance Creator of this CullList object
48          */
49         CullList(InspIRCd* Instance);
50
51         /** Adds a user to the cull list for later
52          * removal via QUIT.
53          * @param user The user to add
54          * @param reason The quit reason of the user being added
55          * @param o_reason The quit reason to show only to opers
56          */
57         void AddItem(User* user);
58
59         /* Turn an item into a silent item (don't send out QUIT for this user)
60          */
61         void MakeSilent(User* user);
62
63         /** Applies the cull list, quitting all the users
64          * on the list with their quit reasons all at once.
65          * This is a very fast operation compared to
66          * iterating the user list and comparing each one,
67          * especially if there are multiple comparisons
68          * to be done, or recursion.
69          * @returns The number of users removed from IRC.
70          */
71         int Apply();
72 };
73
74 #endif
75