ManaPlus
guild.h
Go to the documentation of this file.
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-2019 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 
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:
42 
44  { return mGuild; }
45 
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 
65  int mPos;
66 };
67 
68 class Guild final : public AvatarListModel
69 {
70  public:
72 
73  ~Guild() override final;
74 
78  void setName(const std::string &name)
79  { mName = name; }
80 
84  GuildMember *addMember(const BeingId accountId,
85  const int charId,
86  const std::string &name);
87 
91  GuildMember *addMember(const std::string &name);
92 
98  GuildMember *getMember(const BeingId id) const;
99 
105  GuildMember *getMember(const BeingId accountId,
106  const int charId)
107  const A_WARN_UNUSED;
108 
114  GuildMember *getMemberByCharId(const int charId) const A_WARN_UNUSED;
115 
121  GuildMember *getMember(const std::string &name) const A_WARN_UNUSED;
122 
127  const std::string &getName() const noexcept2 A_WARN_UNUSED
128  { return mName; }
129 
134  int16_t getId() const noexcept2 A_WARN_UNUSED
135  { return mId; }
136 
140  void removeMember(const GuildMember *const member);
141 
145  void removeMember(const BeingId id);
146 
150  void removeMember(const std::string &name);
151 
152  void removeFromMembers();
153 
155  { delete_all(mMembers); mMembers.clear(); }
156 
162  { return CAST_S32(mMembers.size()); }
163 
164  Avatar *getAvatarAt(const int index) override final A_WARN_UNUSED;
165 
171  { return mCanInviteUsers; }
172 
173  void setRights(const int16_t rights);
174 
175  bool isMember(const GuildMember *const member) const A_WARN_UNUSED;
176 
177  bool isMember(const BeingId id) const A_WARN_UNUSED;
178 
179  bool isMember(const std::string &name) const A_WARN_UNUSED;
180 
181  void getNames(StringVect &names) const;
182 
183  void addPos(const int id, const std::string &name);
184 
185  void sort();
186 
187  std::string getPos(const int id) const A_WARN_UNUSED;
188 
189  static Guild *getGuild(const int16_t id) A_WARN_UNUSED;
190 
192  { return mPositions; }
193 
194  void setEmblemId(const int id)
195  { mEmblemId = id; }
196 
198  { return mEmblemId; }
199 
200  static void clearGuilds();
201 
202  void setServerGuild(const bool b)
203  { mServerGuild = b; }
204 
206  { return mServerGuild; }
207 
208  typedef STD_VECTOR<GuildMember*> MemberList;
209 
211  { return &mMembers; }
212 
213  private:
214  typedef std::map<int, Guild*> GuildMap;
215  static GuildMap guilds;
216 
220  explicit Guild(const int16_t id);
221 
224  std::string mName;
226  int16_t mId;
229 };
230 
231 #endif // GUILD_H
Guild::mName
std::string mName
Definition: guild.h:224
BeingId
int BeingId
Definition: beingid.h:29
Avatar::mName
std::string mName
Definition: avatar.h:188
cast.h
Guild::mCanInviteUsers
bool mCanInviteUsers
Definition: guild.h:227
GuildMember::getPos
int getPos() const
Definition: guild.h:46
avatarlistmodel.h
Guild::setName
void setName(const std::string &name)
Definition: guild.h:78
GuildMember
Definition: guild.h:38
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
Guild::mServerGuild
bool mServerGuild
Definition: guild.h:228
Guild::mPositions
PositionsMap mPositions
Definition: guild.h:223
StringVect
std::vector< std::string > StringVect
Definition: stringvector.h:28
Guild::mMembers
MemberList mMembers
Definition: guild.h:222
GuildMember::setPos
void setPos(const int pos)
Definition: guild.h:49
Guild::guilds
static GuildMap guilds
Definition: guild.h:215
GuildMember::getAdditionString
std::string getAdditionString() const
Definition: guild.cpp:84
Guild::getServerGuild
bool getServerGuild() const
Definition: guild.h:205
GuildMember::Guild
friend class Guild
Definition: guild.h:55
noexcept2
#define noexcept2
Definition: localconsts.h:49
Guild::clearMembers
void clearMembers()
Definition: guild.h:154
Guild::MemberList
std::vector< GuildMember * > MemberList
Definition: guild.h:208
Guild::getNumberOfElements
int getNumberOfElements()
Definition: guild.h:161
final
#define final
Definition: localconsts.h:45
Guild::GuildMap
std::map< int, Guild * > GuildMap
Definition: guild.h:214
AvatarListModel
Definition: avatarlistmodel.h:29
Avatar::mId
BeingId mId
Definition: avatar.h:186
Guild::getPositions
const PositionsMap & getPositions() const
Definition: guild.h:191
Guild::getInviteRights
bool getInviteRights() const
Definition: guild.h:170
Guild
Definition: guild.h:68
Guild::setEmblemId
void setEmblemId(const int id)
Definition: guild.h:194
RETURNS_NONNULL
#define RETURNS_NONNULL
Definition: localconsts.h:166
Guild::mEmblemId
int mEmblemId
Definition: guild.h:225
GuildMember::getGuild
const Guild * getGuild() const
Definition: guild.h:43
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
guild
uint32_t guild
Definition: maptypeproperty2.h:5
override
#define override
Definition: localconsts.h:46
std
Definition: mseprimitives.h:398
PositionsMap
std::map< unsigned, std::string > PositionsMap
Definition: guild.h:34
Avatar
Definition: avatar.h:39
CAST_S32
#define CAST_S32
Definition: cast.h:29
Guild::getMembers
const MemberList * getMembers() const
Definition: guild.h:210
Guild::getEmblemId
int getEmblemId() const
Definition: guild.h:197
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition: localconsts.h:160
stringvector.h
dtor.h
GuildMember::mPos
int mPos
Definition: guild.h:65
Guild::getName
const std::string & getName() const
Definition: guild.h:127
Guild::mId
int16_t mId
Definition: guild.h:226
Guild::getId
int16_t getId() const
Definition: guild.h:134
Guild::setServerGuild
void setServerGuild(const bool b)
Definition: guild.h:202
GuildMember::mGuild
Guild * mGuild
Definition: guild.h:64