Atlas-C++
Entity.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU Lesser General Public License (See COPYING for details).
3 // Copyright 2000-2001 Stefanus Du Toit and Aloril.
4 // Copyright 2001-2005 Alistair Riddoch.
5 // Copyright 2011 Erik Ogenvik.
6 // Automatically generated using gen_cpp.py.
7 
8 #ifndef ATLAS_OBJECTS_ENTITY_ENTITY_H
9 #define ATLAS_OBJECTS_ENTITY_ENTITY_H
10 
11 #include <Atlas/Objects/RootEntity.h>
12 #include <Atlas/Objects/Anonymous.h>
13 
14 
15 namespace Atlas { namespace Objects { namespace Entity {
16 
23 class AdminEntityData;
24 typedef SmartPtr<AdminEntityData> AdminEntity;
25 
26 static const int ADMIN_ENTITY_NO = 3;
27 
30 
33 {
34 protected:
36  AdminEntityData(AdminEntityData *defaults = nullptr) :
37  RootEntityData((RootEntityData*)defaults)
38  {
39  m_class_no = ADMIN_ENTITY_NO;
40  }
42  ~AdminEntityData() override = default;
43 
44 public:
46  AdminEntityData * copy() const override;
47 
49  bool instanceOf(int classNo) const override;
50 
51 
52  void iterate(int& current_class, std::string& attr) const override
53  {if(current_class == ADMIN_ENTITY_NO) current_class = -1; RootEntityData::iterate(current_class, attr);}
54 
55 public:
56  template <typename>
57  friend class ::Atlas::Objects::Allocator;
58  static Allocator<AdminEntityData> allocator;
59 
60 protected:
62  void reset() override;
63  void free() override;
64 
65 private:
66 
67  static void fillDefaultObjectInstance(AdminEntityData& data, std::map<std::string, int32_t>& attr_data);
68 };
69 
70 
77 class AccountData;
79 
80 static const int ACCOUNT_NO = 4;
81 
84 
87 {
88 protected:
90  AccountData(AccountData *defaults = nullptr) :
92  {
93  m_class_no = ACCOUNT_NO;
94  }
96  ~AccountData() override = default;
97 
98 public:
100  AccountData * copy() const override;
101 
103  bool instanceOf(int classNo) const override;
104 
107  int copyAttr(const std::string& name, Atlas::Message::Element & attr) const override;
109  void setAttr(const std::string& name,
110  const Atlas::Message::Element& attr) override;
112  void removeAttr(const std::string& name) override;
113 
115  void sendContents(Atlas::Bridge & b) const override;
116 
118  void addToMessage(Atlas::Message::MapType &) const override;
119 
121  void setUsername(const std::string& val);
123  void setPassword(const std::string& val);
125  void setCharacters(const std::list<std::string>& val);
127  void setCharactersAsList(const Atlas::Message::ListType& val);
128 
130  const std::string& getUsername() const;
132  std::string& modifyUsername();
134  const std::string& getPassword() const;
136  std::string& modifyPassword();
138  const std::list<std::string>& getCharacters() const;
140  std::list<std::string>& modifyCharacters();
142  const Atlas::Message::ListType getCharactersAsList() const;
143 
145  bool isDefaultUsername() const;
147  bool isDefaultPassword() const;
149  bool isDefaultCharacters() const;
150 
151 protected:
153  int getAttrClass(const std::string& name)const override;
155  int32_t getAttrFlag(const std::string& name)const override;
157  std::string attr_username;
159  std::string attr_password;
161  std::list<std::string> attr_characters;
162 
164  void sendUsername(Atlas::Bridge&) const;
166  void sendPassword(Atlas::Bridge&) const;
168  void sendCharacters(Atlas::Bridge&) const;
169 
170  void iterate(int& current_class, std::string& attr) const override;
171 
172 public:
173  template <typename>
174  friend class ::Atlas::Objects::Allocator;
175  static Allocator<AccountData> allocator;
176 
177 protected:
179  void reset() override;
180  void free() override;
181 
182 private:
183 
184  static void fillDefaultObjectInstance(AccountData& data, std::map<std::string, int32_t>& attr_data);
185 };
186 
187 //
188 // Attribute name strings follow.
189 //
190 
191 extern const std::string USERNAME_ATTR;
192 extern const std::string PASSWORD_ATTR;
193 extern const std::string CHARACTERS_ATTR;
194 
195 //
196 // Inlined member functions follow.
197 //
198 
199 const int32_t USERNAME_FLAG = 1 << 11;
200 
201 inline void AccountData::setUsername(const std::string& val)
202 {
203  attr_username = val;
204  m_attrFlags |= USERNAME_FLAG;
205 }
206 
207 const int32_t PASSWORD_FLAG = 1 << 12;
208 
209 inline void AccountData::setPassword(const std::string& val)
210 {
211  attr_password = val;
212  m_attrFlags |= PASSWORD_FLAG;
213 }
214 
215 const int32_t CHARACTERS_FLAG = 1 << 13;
216 
217 inline void AccountData::setCharacters(const std::list<std::string>& val)
218 {
219  attr_characters = val;
220  m_attrFlags |= CHARACTERS_FLAG;
221 }
222 
223 inline void AccountData::setCharactersAsList(const Atlas::Message::ListType& val)
224 {
225  m_attrFlags |= CHARACTERS_FLAG;
226  attr_characters.resize(0);
227  for (const auto& entry : val) {
228  if(entry.isString()) {
229  attr_characters.push_back(entry.asString());
230  }
231  }
232 }
233 
234 inline const std::string& AccountData::getUsername() const
235 {
236  if(m_attrFlags & USERNAME_FLAG)
237  return attr_username;
238  else
239  return ((AccountData*)m_defaults)->attr_username;
240 }
241 
242 inline std::string& AccountData::modifyUsername()
243 {
244  if(!(m_attrFlags & USERNAME_FLAG))
245  setUsername(((AccountData*)m_defaults)->attr_username);
246  return attr_username;
247 }
248 
249 inline const std::string& AccountData::getPassword() const
250 {
251  if(m_attrFlags & PASSWORD_FLAG)
252  return attr_password;
253  else
254  return ((AccountData*)m_defaults)->attr_password;
255 }
256 
257 inline std::string& AccountData::modifyPassword()
258 {
259  if(!(m_attrFlags & PASSWORD_FLAG))
260  setPassword(((AccountData*)m_defaults)->attr_password);
261  return attr_password;
262 }
263 
264 inline const std::list<std::string>& AccountData::getCharacters() const
265 {
266  if(m_attrFlags & CHARACTERS_FLAG)
267  return attr_characters;
268  else
269  return ((AccountData*)m_defaults)->attr_characters;
270 }
271 
272 inline std::list<std::string>& AccountData::modifyCharacters()
273 {
274  if(!(m_attrFlags & CHARACTERS_FLAG))
275  setCharacters(((AccountData*)m_defaults)->attr_characters);
276  return attr_characters;
277 }
278 
279 inline const Atlas::Message::ListType AccountData::getCharactersAsList() const
280 {
281  const std::list<std::string>& lst_in = getCharacters();
282  Atlas::Message::ListType lst_out;
283  for (const auto& entry : lst_in) {
284  lst_out.push_back(std::string(entry));
285  }
286  return lst_out;
287 }
288 
290 {
291  return (m_attrFlags & USERNAME_FLAG) == 0;
292 }
293 
295 {
296  return (m_attrFlags & PASSWORD_FLAG) == 0;
297 }
298 
300 {
301  return (m_attrFlags & CHARACTERS_FLAG) == 0;
302 }
303 
304 
305 
312 class PlayerData;
314 
315 static const int PLAYER_NO = 5;
316 
319 
321 class PlayerData : public AccountData
322 {
323 protected:
325  PlayerData(PlayerData *defaults = nullptr) :
326  AccountData((AccountData*)defaults)
327  {
328  m_class_no = PLAYER_NO;
329  }
331  ~PlayerData() override = default;
332 
333 public:
335  PlayerData * copy() const override;
336 
338  bool instanceOf(int classNo) const override;
339 
340 
341  void iterate(int& current_class, std::string& attr) const override
342  {if(current_class == PLAYER_NO) current_class = -1; AccountData::iterate(current_class, attr);}
343 
344 public:
345  template <typename>
346  friend class ::Atlas::Objects::Allocator;
347  static Allocator<PlayerData> allocator;
348 
349 protected:
351  void reset() override;
352  void free() override;
353 
354 private:
355 
356  static void fillDefaultObjectInstance(PlayerData& data, std::map<std::string, int32_t>& attr_data);
357 };
358 
359 
366 class AdminData;
367 typedef SmartPtr<AdminData> Admin;
368 
369 static const int ADMIN_NO = 6;
370 
373 
375 class AdminData : public AccountData
376 {
377 protected:
379  AdminData(AdminData *defaults = nullptr) :
380  AccountData((AccountData*)defaults)
381  {
382  m_class_no = ADMIN_NO;
383  }
385  ~AdminData() override = default;
386 
387 public:
389  AdminData * copy() const override;
390 
392  bool instanceOf(int classNo) const override;
393 
394 
395  void iterate(int& current_class, std::string& attr) const override
396  {if(current_class == ADMIN_NO) current_class = -1; AccountData::iterate(current_class, attr);}
397 
398 public:
399  template <typename>
400  friend class ::Atlas::Objects::Allocator;
401  static Allocator<AdminData> allocator;
402 
403 protected:
405  void reset() override;
406  void free() override;
407 
408 private:
409 
410  static void fillDefaultObjectInstance(AdminData& data, std::map<std::string, int32_t>& attr_data);
411 };
412 
413 
420 class GameData;
421 typedef SmartPtr<GameData> Game;
422 
423 static const int GAME_NO = 7;
424 
427 
429 class GameData : public AdminEntityData
430 {
431 protected:
433  GameData(GameData *defaults = nullptr) :
434  AdminEntityData((AdminEntityData*)defaults)
435  {
436  m_class_no = GAME_NO;
437  }
439  ~GameData() override = default;
440 
441 public:
443  GameData * copy() const override;
444 
446  bool instanceOf(int classNo) const override;
447 
448 
449  void iterate(int& current_class, std::string& attr) const override
450  {if(current_class == GAME_NO) current_class = -1; AdminEntityData::iterate(current_class, attr);}
451 
452 public:
453  template <typename>
454  friend class ::Atlas::Objects::Allocator;
455  static Allocator<GameData> allocator;
456 
457 protected:
459  void reset() override;
460  void free() override;
461 
462 private:
463 
464  static void fillDefaultObjectInstance(GameData& data, std::map<std::string, int32_t>& attr_data);
465 };
466 
467 
474 class GameEntityData;
476 
477 static const int GAME_ENTITY_NO = 8;
478 
481 
484 {
485 protected:
487  GameEntityData(GameEntityData *defaults = nullptr) :
488  RootEntityData((RootEntityData*)defaults)
489  {
490  m_class_no = GAME_ENTITY_NO;
491  }
493  ~GameEntityData() override = default;
494 
495 public:
497  GameEntityData * copy() const override;
498 
500  bool instanceOf(int classNo) const override;
501 
502 
503  void iterate(int& current_class, std::string& attr) const override
504  {if(current_class == GAME_ENTITY_NO) current_class = -1; RootEntityData::iterate(current_class, attr);}
505 
506 public:
507  template <typename>
508  friend class ::Atlas::Objects::Allocator;
509  static Allocator<GameEntityData> allocator;
510 
511 protected:
513  void reset() override;
514  void free() override;
515 
516 private:
517 
518  static void fillDefaultObjectInstance(GameEntityData& data, std::map<std::string, int32_t>& attr_data);
519 };
520 
521 } } } // namespace Atlas::Objects::Entity
522 
523 #endif // ATLAS_OBJECTS_ENTITY_ENTITY_H
std::list< std::string > & modifyCharacters()
Retrieve the "characters" attribute as a non-const reference.
Definition: Entity.h:272
AdminEntityData(AdminEntityData *defaults=nullptr)
Construct a AdminEntityData class definition.
Definition: Entity.h:36
GameData(GameData *defaults=nullptr)
Construct a GameData class definition.
Definition: Entity.h:433
AccountData(AccountData *defaults=nullptr)
Construct a AccountData class definition.
Definition: Entity.h:90
void setCharactersAsList(const Atlas::Message::ListType &val)
Set the "characters" attribute AsList.
Definition: Entity.h:223
void setCharacters(const std::list< std::string > &val)
Set the "characters" attribute.
Definition: Entity.h:217
bool isDefaultPassword() const
Is "password" value default?
Definition: Entity.h:294
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
Retrieve the attribute "name".
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
Definition: Entity.h:395
Atlas stream bridge.
Definition: Bridge.h:35
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
AdminEntityData * copy() const override
Copy this object.
void setPassword(const std::string &val)
Set the "password" attribute.
Definition: Entity.h:209
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
Definition: Entity.h:341
std::string attr_username
Username for account usually.
Definition: Entity.h:157
const std::string & getPassword() const
Retrieve the "password" attribute.
Definition: Entity.h:249
std::list< std::string > attr_characters
List of characters account can control.
Definition: Entity.h:161
BaseObjectData * m_defaults
The default instance, acting as a prototype for all other instances.
Definition: BaseObject.h:440
Multi-type container.
Definition: Element.h:60
All In Game classes and objects.
Definition: Entity.h:483
void free() override
Free an instance of this class, returning it to the memory pool.
The Atlas namespace.
Definition: Bridge.h:20
void removeAttr(const std::string &name) override
Remove the attribute "name". This will not work for static attributes.
int32_t getAttrFlag(const std::string &name) const override
Find the flag for the attribute "name".
All classes and objects used for adminitrativive purposes.
Definition: Entity.h:32
void reset() override
Resets the object as it&#39;s returned to the pool.
Games this server hosts.
Definition: Entity.h:429
~AdminEntityData() override=default
Default destructor.
Player accounts.
Definition: Entity.h:321
PlayerData(PlayerData *defaults=nullptr)
Construct a PlayerData class definition.
Definition: Entity.h:325
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
bool isDefaultUsername() const
Is "username" value default?
Definition: Entity.h:289
void setUsername(const std::string &val)
Set the "username" attribute.
Definition: Entity.h:201
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
Definition: Entity.h:449
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
AdminData(AdminData *defaults=nullptr)
Construct a AdminData class definition.
Definition: Entity.h:379
const std::string & getUsername() const
Retrieve the "username" attribute.
Definition: Entity.h:234
Starting point for entity hierarchy.
Definition: RootEntity.h:31
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
Definition: Entity.h:503
Definition: Decoder.h:16
Trait which handles allocation of instances of BaseObject.
Definition: BaseObject.h:63
const std::list< std::string > & getCharacters() const
Retrieve the "characters" attribute.
Definition: Entity.h:264
Privileged accounts.
Definition: Entity.h:375
std::string attr_password
Password for account usually.
Definition: Entity.h:159
std::string & modifyPassword()
Retrieve the "password" attribute as a non-const reference.
Definition: Entity.h:257
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
GameEntityData(GameEntityData *defaults=nullptr)
Construct a GameEntityData class definition.
Definition: Entity.h:487
Base class for accounts.
Definition: Entity.h:86
bool isDefaultCharacters() const
Is "characters" value default?
Definition: Entity.h:299
bool instanceOf(int classNo) const override
Is this instance of some class?
std::string & modifyUsername()
Retrieve the "username" attribute as a non-const reference.
Definition: Entity.h:242
void iterate(int &current_class, std::string &attr) const override
Iterate over the attributes of this instance.
Definition: Entity.h:52
void setAttr(const std::string &name, const Atlas::Message::Element &attr) override
Set the attribute "name" to the value given by"attr".
const Atlas::Message::ListType getCharactersAsList() const
Retrieve the "characters" attribute AsList.
Definition: Entity.h:279

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.