ManaPlus
party.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2010 The Mana Developers
4  * Copyright (C) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2019-2021 Andrei Karas
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 PARTY_H
24 #define PARTY_H
25 
27 
28 #include "utils/cast.h"
29 #include "utils/dtor.h"
30 #include "utils/stringvector.h"
31 
32 #include <map>
33 #include <set>
34 
35 class Party;
36 
37 class PartyMember final : public Avatar
38 {
39  public:
41 
43  { return mParty; }
44 
46  { return mLeader; }
47 
48  void setLeader(const bool leader)
49  { mLeader = leader; setDisplayBold(leader); }
50 
51  protected:
52  friend class Party;
53 
54  PartyMember(Party *const party,
55  const BeingId id,
56  const std::string &name);
57 
59  bool mLeader;
60 };
61 
62 class Party final : public AvatarListModel
63 {
64  public:
66 
67 
70  void setName(const std::string &name)
71  { mName = name; }
72 
76  PartyMember *addMember(const BeingId id,
77  const std::string &name);
78 
84  PartyMember *getMember(const BeingId id) const A_WARN_UNUSED;
85 
91  PartyMember *getMember(const std::string &name) const A_WARN_UNUSED;
92 
97  const std::string &getName() const noexcept2 A_WARN_UNUSED
98  { return mName; }
99 
104  int16_t getId() const noexcept2 A_WARN_UNUSED
105  { return mId; }
106 
110  void removeMember(const PartyMember *const member);
111 
115  void removeMember(const BeingId id);
116 
120  void removeMember(const std::string &name);
121 
123  { delete_all(mMembers); mMembers.clear(); }
124 
125  void removeFromMembers();
126 
132  { return CAST_S32(mMembers.size()); }
133 
134  Avatar *getAvatarAt(const int index) override final A_WARN_UNUSED;
135 
141  { return mCanInviteUsers; }
142 
143  void setRights(const int16_t rights);
144 
145  bool isMember(const PartyMember *const member) const A_WARN_UNUSED;
146 
147  bool isMember(const BeingId id) const A_WARN_UNUSED;
148 
149  bool isMember(const std::string &name) const A_WARN_UNUSED;
150 
151  void getNames(StringVect &names) const;
152 
153  void getNamesSet(std::set<std::string> &names) const;
154 
155  void sort();
156 
157  typedef STD_VECTOR<PartyMember*> MemberList;
158 
160  { return &mMembers; }
161 
162  static Party *getParty(const int16_t id) A_WARN_UNUSED;
163 
164  static void clearParties();
165 
166  private:
167  typedef std::map<int, Party*> PartyMap;
169 
173  explicit Party(const int16_t id);
174 
176 
178  std::string mName;
179  int16_t mId;
181 };
182 
183 #endif // PARTY_H
int BeingId
Definition: beingid.h:30
#define CAST_S32
Definition: cast.h:30
Definition: avatar.h:41
void setDisplayBold(const bool displayBold)
Definition: avatar.h:111
PartyMember(Party *const party, const BeingId id, const std::string &name)
Definition: party.cpp:59
const Party * getParty() const
Definition: party.h:42
bool mLeader
Definition: party.h:59
void setLeader(const bool leader)
Definition: party.h:48
bool getLeader() const
Definition: party.h:45
Party * mParty
Definition: party.h:58
Definition: party.h:63
static PartyMap parties
Definition: party.h:168
bool getInviteRights() const
Definition: party.h:140
bool isMember(const PartyMember *const member) const
Definition: party.cpp:230
std::string mName
Definition: party.h:178
std::map< int, Party * > PartyMap
Definition: party.h:167
std::vector< PartyMember * > MemberList
Definition: party.h:157
void setRights(const int16_t rights)
Definition: party.cpp:223
int getNumberOfElements()
Definition: party.h:131
Avatar * getAvatarAt(const int index)
Definition: party.cpp:218
const MemberList * getMembers() const
Definition: party.h:159
const std::string & getName() const
Definition: party.h:97
Party(const int16_t id)
Definition: party.cpp:71
int16_t getId() const
Definition: party.h:104
void setName(const std::string &name)
Definition: party.h:70
void removeFromMembers()
Definition: party.cpp:201
~Party()
Definition: party.cpp:80
void removeMember(const PartyMember *const member)
Definition: party.cpp:128
PartyMember * addMember(const BeingId id, const std::string &name)
Definition: party.cpp:85
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:99
void getNamesSet(std::set< std::string > &names) const
Definition: party.cpp:299
static Party * getParty(const int16_t id)
Definition: party.cpp:313
void getNames(StringVect &names) const
Definition: party.cpp:285
MemberList mMembers
Definition: party.h:177
void clearMembers()
Definition: party.h:122
void sort()
Definition: party.cpp:323
int16_t mId
Definition: party.h:179
bool mCanInviteUsers
Definition: party.h:180
static void clearParties()
Definition: party.cpp:328
void delete_all(Container &c)
Definition: dtor.h:56
#define override
Definition: localconsts.h:47
#define RETURNS_NONNULL
Definition: localconsts.h:167
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t party
std::vector< std::string > StringVect
Definition: stringvector.h:29