Atlas  0.7.0
Networking protocol for the Worldforge system.
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-2020 Erik Ogenvik.
6 // Automatically generated using gen_cpp.py. Don't edit directly.
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  explicit AdminEntityData(AdminEntityData *defaults = nullptr) :
37  RootEntityData((RootEntityData*)defaults)
38  {
39  m_class_no = ADMIN_ENTITY_NO;
40  }
42  ~AdminEntityData() override = default;
43 
44 public:
45  // The parent type for this object's superclass
46  static constexpr const char* super_parent = "root_entity";
47  // The default parent type for this object
48  static constexpr const char* default_parent = "admin_entity";
49  // The default objtype for this object
50  static constexpr const char* default_objtype = "obj";
52  AdminEntityData * copy() const override;
53 
55  bool instanceOf(int classNo) const override;
56 
57 
58 public:
59  template <typename>
60  friend class ::Atlas::Objects::Allocator;
61  static Allocator<AdminEntityData> allocator;
62 
63 protected:
65  void reset() override;
66  void free() override;
67 
68 private:
69 
70  static void fillDefaultObjectInstance(AdminEntityData& data, std::map<std::string, uint32_t>& attr_data);
71 };
72 
73 
80 class AccountData;
82 
83 static const int ACCOUNT_NO = 4;
84 
87 
90 {
91 protected:
93  explicit AccountData(AccountData *defaults = nullptr) :
95  {
96  m_class_no = ACCOUNT_NO;
97  }
99  ~AccountData() override = default;
100 
101 public:
102  // The parent type for this object's superclass
103  static constexpr const char* super_parent = "admin_entity";
104  // The default parent type for this object
105  static constexpr const char* default_parent = "account";
106  // The default objtype for this object
107  static constexpr const char* default_objtype = "obj";
109  AccountData * copy() const override;
110 
112  bool instanceOf(int classNo) const override;
113 
116  int copyAttr(const std::string& name, Atlas::Message::Element & attr) const override;
118  void setAttr(std::string name,
119  Atlas::Message::Element attr, const Atlas::Objects::Factories* factories = nullptr) override;
121  void removeAttr(const std::string& name) override;
122 
124  void sendContents(Atlas::Bridge & b) const override;
125 
127  void addToMessage(Atlas::Message::MapType &) const override;
128 
130  void setUsername(std::string val);
132  void setPassword(std::string val);
134  void setCharacters(std::vector<std::string> val);
136  void setCharactersAsList(const Atlas::Message::ListType& val);
137 
139  const std::string& getUsername() const;
141  std::string& modifyUsername();
143  const std::string& getPassword() const;
145  std::string& modifyPassword();
147  const std::vector<std::string>& getCharacters() const;
149  std::vector<std::string>& modifyCharacters();
151  Atlas::Message::ListType getCharactersAsList() const;
152 
154  bool isDefaultUsername() const;
156  bool isDefaultPassword() const;
158  bool isDefaultCharacters() const;
159 
160 protected:
162  int getAttrClass(const std::string& name)const override;
164  bool getAttrFlag(const std::string& name, uint32_t& flag)const override;
166  std::string attr_username;
168  std::string attr_password;
170  std::vector<std::string> attr_characters;
171 
173  void sendUsername(Atlas::Bridge&) const;
175  void sendPassword(Atlas::Bridge&) const;
177  void sendCharacters(Atlas::Bridge&) const;
178 
179 public:
180  template <typename>
181  friend class ::Atlas::Objects::Allocator;
182  static Allocator<AccountData> allocator;
183 
184 protected:
186  void reset() override;
187  void free() override;
188 
189 private:
190 
191  static void fillDefaultObjectInstance(AccountData& data, std::map<std::string, uint32_t>& attr_data);
192 };
193 
194 //
195 // Attribute name strings follow.
196 //
197 
198 extern const std::string USERNAME_ATTR;
199 extern const std::string PASSWORD_ATTR;
200 extern const std::string CHARACTERS_ATTR;
201 
202 //
203 // Inlined member functions follow.
204 //
205 
206 const uint32_t USERNAME_FLAG = 1u << 11u;
207 
208 inline void AccountData::setUsername(std::string val)
209 {
210  attr_username = std::move(val);
211  m_attrFlags |= USERNAME_FLAG;
212 }
213 
214 const uint32_t PASSWORD_FLAG = 1u << 12u;
215 
216 inline void AccountData::setPassword(std::string val)
217 {
218  attr_password = std::move(val);
219  m_attrFlags |= PASSWORD_FLAG;
220 }
221 
222 const uint32_t CHARACTERS_FLAG = 1u << 13u;
223 
224 inline void AccountData::setCharacters(std::vector<std::string> val)
225 {
226  attr_characters = std::move(val);
227  m_attrFlags |= CHARACTERS_FLAG;
228 }
229 
230 inline void AccountData::setCharactersAsList(const Atlas::Message::ListType& val)
231 {
232  m_attrFlags |= CHARACTERS_FLAG;
233  attr_characters.resize(0);
234  for (const auto& entry : val) {
235  if(entry.isString()) {
236  attr_characters.push_back(entry.asString());
237  }
238  }
239 }
240 
241 inline const std::string& AccountData::getUsername() const
242 {
243  if(m_attrFlags & USERNAME_FLAG)
244  return attr_username;
245  else
246  return ((AccountData*)m_defaults)->attr_username;
247 }
248 
249 inline std::string& AccountData::modifyUsername()
250 {
251  if(!(m_attrFlags & USERNAME_FLAG))
253  return attr_username;
254 }
255 
256 inline const std::string& AccountData::getPassword() const
257 {
258  if(m_attrFlags & PASSWORD_FLAG)
259  return attr_password;
260  else
261  return ((AccountData*)m_defaults)->attr_password;
262 }
263 
264 inline std::string& AccountData::modifyPassword()
265 {
266  if(!(m_attrFlags & PASSWORD_FLAG))
268  return attr_password;
269 }
270 
271 inline const std::vector<std::string>& AccountData::getCharacters() const
272 {
273  if(m_attrFlags & CHARACTERS_FLAG)
274  return attr_characters;
275  else
276  return ((AccountData*)m_defaults)->attr_characters;
277 }
278 
279 inline std::vector<std::string>& AccountData::modifyCharacters()
280 {
281  if(!(m_attrFlags & CHARACTERS_FLAG))
283  return attr_characters;
284 }
285 
286 inline Atlas::Message::ListType AccountData::getCharactersAsList() const
287 {
288  const std::vector<std::string>& lst_in = getCharacters();
289  Atlas::Message::ListType lst_out;
290  for (const auto& entry : lst_in) {
291  lst_out.push_back(std::string(entry));
292  }
293  return lst_out;
294 }
295 
297 {
298  return (m_attrFlags & USERNAME_FLAG) == 0;
299 }
300 
302 {
303  return (m_attrFlags & PASSWORD_FLAG) == 0;
304 }
305 
307 {
308  return (m_attrFlags & CHARACTERS_FLAG) == 0;
309 }
310 
311 
312 
319 class PlayerData;
321 
322 static const int PLAYER_NO = 5;
323 
326 
328 class PlayerData : public AccountData
329 {
330 protected:
332  explicit PlayerData(PlayerData *defaults = nullptr) :
333  AccountData((AccountData*)defaults)
334  {
335  m_class_no = PLAYER_NO;
336  }
338  ~PlayerData() override = default;
339 
340 public:
341  // The parent type for this object's superclass
342  static constexpr const char* super_parent = "account";
343  // The default parent type for this object
344  static constexpr const char* default_parent = "player";
345  // The default objtype for this object
346  static constexpr const char* default_objtype = "obj";
348  PlayerData * copy() const override;
349 
351  bool instanceOf(int classNo) const override;
352 
353 
354 public:
355  template <typename>
356  friend class ::Atlas::Objects::Allocator;
357  static Allocator<PlayerData> allocator;
358 
359 protected:
361  void reset() override;
362  void free() override;
363 
364 private:
365 
366  static void fillDefaultObjectInstance(PlayerData& data, std::map<std::string, uint32_t>& attr_data);
367 };
368 
369 
376 class AdminData;
377 typedef SmartPtr<AdminData> Admin;
378 
379 static const int ADMIN_NO = 6;
380 
383 
385 class AdminData : public AccountData
386 {
387 protected:
389  explicit AdminData(AdminData *defaults = nullptr) :
390  AccountData((AccountData*)defaults)
391  {
392  m_class_no = ADMIN_NO;
393  }
395  ~AdminData() override = default;
396 
397 public:
398  // The parent type for this object's superclass
399  static constexpr const char* super_parent = "account";
400  // The default parent type for this object
401  static constexpr const char* default_parent = "admin";
402  // The default objtype for this object
403  static constexpr const char* default_objtype = "obj";
405  AdminData * copy() const override;
406 
408  bool instanceOf(int classNo) const override;
409 
410 
411 public:
412  template <typename>
413  friend class ::Atlas::Objects::Allocator;
414  static Allocator<AdminData> allocator;
415 
416 protected:
418  void reset() override;
419  void free() override;
420 
421 private:
422 
423  static void fillDefaultObjectInstance(AdminData& data, std::map<std::string, uint32_t>& attr_data);
424 };
425 
426 
433 class GameData;
434 typedef SmartPtr<GameData> Game;
435 
436 static const int GAME_NO = 7;
437 
440 
442 class GameData : public AdminEntityData
443 {
444 protected:
446  explicit GameData(GameData *defaults = nullptr) :
447  AdminEntityData((AdminEntityData*)defaults)
448  {
449  m_class_no = GAME_NO;
450  }
452  ~GameData() override = default;
453 
454 public:
455  // The parent type for this object's superclass
456  static constexpr const char* super_parent = "admin_entity";
457  // The default parent type for this object
458  static constexpr const char* default_parent = "game";
459  // The default objtype for this object
460  static constexpr const char* default_objtype = "obj";
462  GameData * copy() const override;
463 
465  bool instanceOf(int classNo) const override;
466 
467 
468 public:
469  template <typename>
470  friend class ::Atlas::Objects::Allocator;
471  static Allocator<GameData> allocator;
472 
473 protected:
475  void reset() override;
476  void free() override;
477 
478 private:
479 
480  static void fillDefaultObjectInstance(GameData& data, std::map<std::string, uint32_t>& attr_data);
481 };
482 
483 
490 class GameEntityData;
492 
493 static const int GAME_ENTITY_NO = 8;
494 
497 
500 {
501 protected:
503  explicit GameEntityData(GameEntityData *defaults = nullptr) :
504  RootEntityData((RootEntityData*)defaults)
505  {
506  m_class_no = GAME_ENTITY_NO;
507  }
509  ~GameEntityData() override = default;
510 
511 public:
512  // The parent type for this object's superclass
513  static constexpr const char* super_parent = "root_entity";
514  // The default parent type for this object
515  static constexpr const char* default_parent = "game_entity";
516  // The default objtype for this object
517  static constexpr const char* default_objtype = "obj";
519  GameEntityData * copy() const override;
520 
522  bool instanceOf(int classNo) const override;
523 
524 
525 public:
526  template <typename>
527  friend class ::Atlas::Objects::Allocator;
528  static Allocator<GameEntityData> allocator;
529 
530 protected:
532  void reset() override;
533  void free() override;
534 
535 private:
536 
537  static void fillDefaultObjectInstance(GameEntityData& data, std::map<std::string, uint32_t>& attr_data);
538 };
539 
540 } } } // namespace Atlas::Objects::Entity
541 
542 #endif // ATLAS_OBJECTS_ENTITY_ENTITY_H
BaseObjectData * m_defaults
Definition: BaseObject.h:330
Base class for accounts.
Definition: Entity.h:90
AccountData(AccountData *defaults=nullptr)
Construct a AccountData class definition.
Definition: Entity.h:93
bool getAttrFlag(const std::string &name, uint32_t &flag) const override
Find the flag for the attribute "name".
bool isDefaultCharacters() const
Is "characters" value default?
Definition: Entity.h:306
const std::string & getPassword() const
Retrieve the "password" attribute.
Definition: Entity.h:256
bool isDefaultUsername() const
Is "username" value default?
Definition: Entity.h:296
void sendUsername(Atlas::Bridge &) const
Send the "username" attribute to an Atlas::Bridge.
void free() override
Free an instance of this class, returning it to the memory pool.
void sendCharacters(Atlas::Bridge &) const
Send the "characters" attribute to an Atlas::Bridge.
std::string & modifyPassword()
Retrieve the "password" attribute as a non-const reference.
Definition: Entity.h:264
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
void setCharactersAsList(const Atlas::Message::ListType &val)
Set the "characters" attribute AsList.
Definition: Entity.h:230
void reset() override
Resets the object as it's returned to the pool.
bool isDefaultPassword() const
Is "password" value default?
Definition: Entity.h:301
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
Atlas::Message::ListType getCharactersAsList() const
Retrieve the "characters" attribute AsList.
Definition: Entity.h:286
void removeAttr(const std::string &name) override
Remove the attribute "name". This will not work for static attributes.
std::string attr_password
Password for account usually.
Definition: Entity.h:168
std::string & modifyUsername()
Retrieve the "username" attribute as a non-const reference.
Definition: Entity.h:249
~AccountData() override=default
Default destructor.
std::string attr_username
Username for account usually.
Definition: Entity.h:166
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
std::vector< std::string > attr_characters
List of characters account can control.
Definition: Entity.h:170
std::vector< std::string > & modifyCharacters()
Retrieve the "characters" attribute as a non-const reference.
Definition: Entity.h:279
void setUsername(std::string val)
Set the "username" attribute.
Definition: Entity.h:208
bool instanceOf(int classNo) const override
Is this instance of some class?
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
const std::string & getUsername() const
Retrieve the "username" attribute.
Definition: Entity.h:241
void setCharacters(std::vector< std::string > val)
Set the "characters" attribute.
Definition: Entity.h:224
void setPassword(std::string val)
Set the "password" attribute.
Definition: Entity.h:216
void setAttr(std::string name, Atlas::Message::Element attr, const Atlas::Objects::Factories *factories=nullptr) override
Set the attribute "name" to the value given by"attr".
void sendPassword(Atlas::Bridge &) const
Send the "password" attribute to an Atlas::Bridge.
AccountData * copy() const override
Copy this object.
const std::vector< std::string > & getCharacters() const
Retrieve the "characters" attribute.
Definition: Entity.h:271
Privileged accounts.
Definition: Entity.h:386
void free() override
Free an instance of this class, returning it to the memory pool.
void reset() override
Resets the object as it's returned to the pool.
~AdminData() override=default
Default destructor.
AdminData * copy() const override
Copy this object.
bool instanceOf(int classNo) const override
Is this instance of some class?
AdminData(AdminData *defaults=nullptr)
Construct a AdminData class definition.
Definition: Entity.h:389
All classes and objects used for administrative purposes.
Definition: Entity.h:33
void reset() override
Resets the object as it's returned to the pool.
~AdminEntityData() override=default
Default destructor.
void free() override
Free an instance of this class, returning it to the memory pool.
AdminEntityData * copy() const override
Copy this object.
AdminEntityData(AdminEntityData *defaults=nullptr)
Construct a AdminEntityData class definition.
Definition: Entity.h:36
bool instanceOf(int classNo) const override
Is this instance of some class?
Games this server hosts.
Definition: Entity.h:443
~GameData() override=default
Default destructor.
bool instanceOf(int classNo) const override
Is this instance of some class?
GameData * copy() const override
Copy this object.
void reset() override
Resets the object as it's returned to the pool.
void free() override
Free an instance of this class, returning it to the memory pool.
GameData(GameData *defaults=nullptr)
Construct a GameData class definition.
Definition: Entity.h:446
All In Game classes and objects.
Definition: Entity.h:500
void reset() override
Resets the object as it's returned to the pool.
GameEntityData * copy() const override
Copy this object.
GameEntityData(GameEntityData *defaults=nullptr)
Construct a GameEntityData class definition.
Definition: Entity.h:503
~GameEntityData() override=default
Default destructor.
bool instanceOf(int classNo) const override
Is this instance of some class?
void free() override
Free an instance of this class, returning it to the memory pool.
PlayerData(PlayerData *defaults=nullptr)
Construct a PlayerData class definition.
Definition: Entity.h:332
~PlayerData() override=default
Default destructor.
void free() override
Free an instance of this class, returning it to the memory pool.
bool instanceOf(int classNo) const override
Is this instance of some class?
void reset() override
Resets the object as it's returned to the pool.
PlayerData * copy() const override
Copy this object.
Starting point for entity hierarchy.
Definition: RootEntity.h:32
Definition: Bridge.h:20