GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/party.h Lines: 2 8 25.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

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