]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/membership.h
Convert InviteBase::invites to an intrusively linked list
[user/henk/code/inspircd.git] / include / membership.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #pragma once
22
23 class CoreExport Membership : public Extensible, public intrusive_list_node<Membership>
24 {
25  public:
26         User* const user;
27         Channel* const chan;
28         // mode list, sorted by prefix rank, higest first
29         std::string modes;
30         Membership(User* u, Channel* c) : user(u), chan(c) {}
31         inline bool hasMode(char m) const
32         {
33                 return modes.find(m) != std::string::npos;
34         }
35         unsigned int getRank();
36
37         /** Add a prefix character to a user.
38          * Only the core should call this method, usually from
39          * within the mode parser or when the first user joins
40          * the channel (to grant the default privs to them)
41          * @param mh The mode handler of the prefix mode to associate
42          * @param adding True if adding the prefix, false when removing
43          * @return True if a change was made
44          */
45         bool SetPrefix(PrefixMode* mh, bool adding);
46 };
47
48 template <typename T>
49 class InviteBase
50 {
51  protected:
52         intrusive_list<Invitation, T> invites;
53
54  public:
55         void ClearInvites();
56
57         friend class Invitation;
58 };
59
60 class CoreExport Invitation : public intrusive_list_node<Invitation, Channel>, public intrusive_list_node<Invitation, LocalUser>
61 {
62         Invitation(Channel* c, LocalUser* u, time_t timeout) : user(u), chan(c), expiry(timeout) {}
63
64  public:
65         LocalUser* const user;
66         Channel* const chan;
67         time_t expiry;
68
69         ~Invitation();
70         static void Create(Channel* c, LocalUser* u, time_t timeout);
71         static Invitation* Find(Channel* c, LocalUser* u, bool check_expired = true);
72 };
73
74 typedef intrusive_list<Invitation, LocalUser> InviteList;
75
76 template<typename T>
77 inline void InviteBase<T>::ClearInvites()
78 {
79         for (typename intrusive_list<Invitation, T>::iterator i = invites.begin(); i != invites.end(); )
80         {
81                 Invitation* inv = *i;
82                 ++i;
83                 delete inv;
84         }
85 }