tb_id.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_ID_H
  6. #define TB_ID_H
  7. #include "tb_types.h"
  8. #include "tb_hash.h"
  9. #include "tb_str.h"
  10. namespace tb {
  11. /** TBID is a wrapper for a uint32 to be used as ID.
  12. The uint32 can be set directly to any uint32, or it can be
  13. set from a string which will be hashed into the uint32. */
  14. class TBID
  15. {
  16. public:
  17. TBID(uint32 id = 0) { Set(id); }
  18. TBID(const char *string) { Set(string); }
  19. TBID(const TBID &id) { Set(id); }
  20. #ifdef TB_RUNTIME_DEBUG_INFO
  21. void Set(uint32 newid);
  22. void Set(const TBID &newid);
  23. void Set(const char *string);
  24. #else
  25. void Set(uint32 newid) { id = newid; }
  26. void Set(const TBID &newid) { id = newid; }
  27. void Set(const char *string) { id = TBGetHash(string); }
  28. #endif
  29. operator uint32 () const { return id; }
  30. const TBID& operator = (const TBID &id) { Set(id); return *this; }
  31. private:
  32. uint32 id;
  33. public:
  34. /** This string is here to aid debugging (Only in debug builds!)
  35. It should not to be used in your code! */
  36. #ifdef TB_RUNTIME_DEBUG_INFO
  37. friend class TBLanguage;
  38. TBStr debug_string;
  39. #endif
  40. };
  41. }; // namespace tb
  42. #endif // TB_ID_H