GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/guild.h Lines: 0 13 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUILD_H
24
#define GUILD_H
25
26
#include "gui/models/avatarlistmodel.h"
27
28
#include "utils/cast.h"
29
#include "utils/dtor.h"
30
#include "utils/stringvector.h"
31
32
#include <map>
33
34
class Guild;
35
36
typedef std::map<unsigned, std::string> PositionsMap;
37
38
class GuildMember final : public Avatar
39
{
40
    public:
41
        A_DELETE_COPY(GuildMember)
42
43
        const Guild *getGuild() const noexcept2 A_WARN_UNUSED
44
        { return mGuild; }
45
46
        int getPos() const noexcept2 A_WARN_UNUSED
47
        { return mPos; }
48
49
        void setPos(const int pos)
50
        { mPos = pos; }
51
52
        std::string getAdditionString() const override final A_WARN_UNUSED;
53
54
    protected:
55
        friend class Guild;
56
57
        GuildMember(Guild *const guild,
58
                    const BeingId accountId,
59
                    const int charId,
60
                    const std::string &name);
61
62
        GuildMember(Guild *const guild, const std::string &name);
63
64
        Guild *mGuild;
65
        int mPos;
66
};
67
68
class Guild final : public AvatarListModel
69
{
70
    public:
71
        A_DELETE_COPY(Guild)
72
73
        ~Guild();
74
75
        /**
76
         * Set the guild's name.
77
         */
78
        void setName(const std::string &name)
79
        { mName = name; }
80
81
        /**
82
         * Adds member to the list.
83
         */
84
        GuildMember *addMember(const BeingId accountId,
85
                               const int charId,
86
                               const std::string &name);
87
88
        /**
89
         * Adds member to the list.
90
         */
91
        GuildMember *addMember(const std::string &name);
92
93
        /**
94
         * Find a member by ID.
95
         *
96
         * @return the member with the given ID, or NULL if they don't exist.
97
         */
98
        GuildMember *getMember(const BeingId id) const;
99
100
        /**
101
         * Find a member by account ID and char ID.
102
         *
103
         * @return the member with the given ID, or NULL if they don't exist.
104
         */
105
        GuildMember *getMember(const BeingId accountId,
106
                               const int charId)
107
                               const A_WARN_UNUSED;
108
109
        /**
110
         * Find a member by name.
111
         *
112
         * @return the member with the given name, or NULL if they don't exist.
113
         */
114
        GuildMember *getMember(const std::string &name) const A_WARN_UNUSED;
115
116
        /**
117
         * Get the name of the guild.
118
         * @return returns name of the guild
119
         */
120
        const std::string &getName() const noexcept2 A_WARN_UNUSED
121
        { return mName; }
122
123
        /**
124
         * Get the id of the guild.
125
         * @return Returns the id of the guild
126
         */
127
        int16_t getId() const noexcept2 A_WARN_UNUSED
128
        { return mId; }
129
130
        /**
131
         * Removes a member from the guild.
132
         */
133
        void removeMember(const GuildMember *const member);
134
135
        /**
136
         * Removes a member from the guild.
137
         */
138
        void removeMember(const BeingId id);
139
140
        /**
141
         * Removes a member from the guild.
142
         */
143
        void removeMember(const std::string &name);
144
145
        void removeFromMembers();
146
147
        void clearMembers()
148
        { delete_all(mMembers); mMembers.clear(); }
149
150
        /**
151
         * Get size of members list.
152
         * @return Returns the number of members in the guild.
153
         */
154
        int getNumberOfElements() override final A_WARN_UNUSED
155
        { return CAST_S32(mMembers.size()); }
156
157
        Avatar *getAvatarAt(const int index) override final A_WARN_UNUSED;
158
159
        /**
160
         * Get whether user can invite users to this guild.
161
         * @return Returns true if user can invite users
162
         */
163
        bool getInviteRights() const noexcept2 A_WARN_UNUSED
164
        { return mCanInviteUsers; }
165
166
        void setRights(const int16_t rights);
167
168
        bool isMember(const GuildMember *const member) const A_WARN_UNUSED;
169
170
        bool isMember(const BeingId id) const A_WARN_UNUSED;
171
172
        bool isMember(const std::string &name) const A_WARN_UNUSED;
173
174
        void getNames(StringVect &names) const;
175
176
        void addPos(const int id, const std::string &name);
177
178
        void sort();
179
180
        std::string getPos(const int id) const A_WARN_UNUSED;
181
182
        static Guild *getGuild(const int16_t id) A_WARN_UNUSED;
183
184
        const PositionsMap &getPositions() const noexcept2 A_WARN_UNUSED
185
        { return mPositions; }
186
187
        void setEmblemId(const int id)
188
        { mEmblemId = id; }
189
190
        int getEmblemId() const noexcept2 A_WARN_UNUSED
191
        { return mEmblemId; }
192
193
        static void clearGuilds();
194
195
        void setServerGuild(const bool b)
196
        { mServerGuild = b; }
197
198
        bool getServerGuild() const noexcept2 A_WARN_UNUSED
199
        { return mServerGuild; }
200
201
        typedef STD_VECTOR<GuildMember*> MemberList;
202
203
        const MemberList *getMembers() const RETURNS_NONNULL A_WARN_UNUSED
204
        { return &mMembers; }
205
206
    private:
207
        typedef std::map<int, Guild*> GuildMap;
208
        static GuildMap guilds;
209
210
        /**
211
         * Constructor with guild id passed to it.
212
         */
213
        explicit Guild(const int16_t id);
214
215
        MemberList mMembers;
216
        PositionsMap mPositions;
217
        std::string mName;
218
        int mEmblemId;
219
        int16_t mId;
220
        bool mCanInviteUsers;
221
        bool mServerGuild;
222
};
223
224
#endif  // GUILD_H