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  *
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 
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 class PartyMember final : public Avatar
37 {
38  public:
40 
42  { return mParty; }
43 
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 
58  bool mLeader;
59 };
60 
61 class Party final : public AvatarListModel
62 {
63  public:
65 
66 
69  void setName(const std::string &name)
70  { mName = name; }
71 
75  PartyMember *addMember(const BeingId id,
76  const std::string &name);
77 
83  PartyMember *getMember(const BeingId id) const A_WARN_UNUSED;
84 
90  PartyMember *getMember(const std::string &name) const A_WARN_UNUSED;
91 
96  const std::string &getName() const noexcept2 A_WARN_UNUSED
97  { return mName; }
98 
103  int16_t getId() const noexcept2 A_WARN_UNUSED
104  { return mId; }
105 
109  void removeMember(const PartyMember *const member);
110 
114  void removeMember(const BeingId id);
115 
119  void removeMember(const std::string &name);
120 
122  { delete_all(mMembers); mMembers.clear(); }
123 
124  void removeFromMembers();
125 
131  { return CAST_S32(mMembers.size()); }
132 
133  Avatar *getAvatarAt(const int index) override final A_WARN_UNUSED;
134 
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 
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;
168 
172  explicit Party(const int16_t id);
173 
175 
177  std::string mName;
178  int16_t mId;
180 };
181 
182 #endif // PARTY_H
Avatar::setDisplayBold
void setDisplayBold(const bool displayBold)
Definition: avatar.h:110
Party::getId
int16_t getId() const
Definition: party.h:103
BeingId
int BeingId
Definition: beingid.h:29
cast.h
PartyMember::PartyMember
PartyMember(Party *const party, const BeingId id, const std::string &name)
Definition: party.cpp:58
Party::mId
int16_t mId
Definition: party.h:178
Party::clearMembers
void clearMembers()
Definition: party.h:121
Party::getInviteRights
bool getInviteRights() const
Definition: party.h:139
avatarlistmodel.h
Party::mCanInviteUsers
bool mCanInviteUsers
Definition: party.h:179
PartyMember::getLeader
bool getLeader() const
Definition: party.h:44
Party::getAvatarAt
Avatar * getAvatarAt(const int index)
Definition: party.cpp:217
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
PartyMember::setLeader
void setLeader(const bool leader)
Definition: party.h:47
Party::getName
const std::string & getName() const
Definition: party.h:96
StringVect
std::vector< std::string > StringVect
Definition: stringvector.h:28
Party::getNamesSet
void getNamesSet(std::set< std::string > &names) const
Definition: party.cpp:298
Party::isMember
bool isMember(const PartyMember *const member) const
Definition: party.cpp:229
PartyMember
Definition: party.h:36
PartyMember::getParty
const Party * getParty() const
Definition: party.h:41
noexcept2
#define noexcept2
Definition: localconsts.h:49
Party::mMembers
MemberList mMembers
Definition: party.h:176
final
#define final
Definition: localconsts.h:45
Party::clearParties
static void clearParties()
Definition: party.cpp:327
AvatarListModel
Definition: avatarlistmodel.h:29
Party::MemberList
std::vector< PartyMember * > MemberList
Definition: party.h:156
Party::~Party
~Party()
Definition: party.cpp:79
Party::getParty
static Party * getParty(const int16_t id)
Definition: party.cpp:312
Party
Definition: party.h:61
Party::getMember
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:98
Party::parties
static PartyMap parties
Definition: party.h:167
Party::setName
void setName(const std::string &name)
Definition: party.h:69
Party::mName
std::string mName
Definition: party.h:177
RETURNS_NONNULL
#define RETURNS_NONNULL
Definition: localconsts.h:166
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
Party::getNumberOfElements
int getNumberOfElements()
Definition: party.h:130
Party::setRights
void setRights(const int16_t rights)
Definition: party.cpp:222
Party::getMembers
const MemberList * getMembers() const
Definition: party.h:158
override
#define override
Definition: localconsts.h:46
std
Definition: mseprimitives.h:398
Party::addMember
PartyMember * addMember(const BeingId id, const std::string &name)
Definition: party.cpp:84
Avatar
Definition: avatar.h:39
PartyMember::mParty
Party * mParty
Definition: party.h:57
Party::PartyMap
std::map< int, Party * > PartyMap
Definition: party.h:166
CAST_S32
#define CAST_S32
Definition: cast.h:29
party
uint32_t party
Definition: maptypeproperty2.h:4
Party::removeMember
void removeMember(const PartyMember *const member)
Definition: party.cpp:127
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition: localconsts.h:160
stringvector.h
PartyMember::mLeader
bool mLeader
Definition: party.h:58
dtor.h
Party::getNames
void getNames(StringVect &names) const
Definition: party.cpp:284
Party::sort
void sort()
Definition: party.cpp:322
Party::Party
Party(const int16_t id)
Definition: party.cpp:70
Party::removeFromMembers
void removeFromMembers()
Definition: party.cpp:200