id_string.inl - エンジンの C API リファレンス

id_string.inl
  1. #include <stdint.h>
  2. #include "hash_function.h"
  3. #include "array.h"
  4. namespace stingray_plugin_foundation {
  5. inline IdString64::IdString64() : _id(0)
  6. {
  7. }
  8. inline IdString64::IdString64(uint64_t id) : _id(id)
  9. {
  10. }
  11. inline IdString64::IdString64(const char *s)
  12. {
  13. _id = murmur_hash_64(s, (unsigned)strlen(s), 0);
  14. }
  15. inline IdString64::IdString64(unsigned len, const char *s)
  16. {
  17. _id = murmur_hash_64(s, len, 0);
  18. }
  19. inline IdString64::IdString64(const char *s, uint64_t id)
  20. {
  21. _id = id;
  22. #if defined(_DEBUG) && defined(XASSERT)
  23. XASSERT(_id == murmur_hash_64(s, (unsigned)strlen(s), 0), "Bad static idstring `%s`", s);
  24. #endif
  25. }
  26. inline const char *IdString64::to_id_hex() const
  27. {
  28. static char buffer[200];
  29. static char *p = &buffer[0];
  30. if (p + HEX_BUFFER_SIZE + 10 > &buffer[200])
  31. p = &buffer[0];
  32. char hex[HEX_BUFFER_SIZE];
  33. to_hex(hex);
  34. sprintf(p, "#ID[%s]", hex);
  35. char *s = p;
  36. p += strlen(p) + 1;
  37. return s;
  38. }
  39. inline IdString32::IdString32() : _id(0) {}
  40. inline IdString32::IdString32(unsigned id) : _id(id) {}
  41. inline IdString32::IdString32(const char *s)
  42. {
  43. uint64_t id64 = murmur_hash_64(s, (unsigned)strlen(s), 0);
  44. _id = (id64 >> 32);
  45. }
  46. inline IdString32::IdString32(unsigned len, const char *s)
  47. {
  48. uint64_t id64 = murmur_hash_64(s, len, 0);
  49. _id = (id64 >> 32);
  50. }
  51. inline const char *IdString32::to_id_hex() const
  52. {
  53. static char buffer[200];
  54. static char *p = &buffer[0];
  55. if (p + HEX_BUFFER_SIZE + 10 > &buffer[200])
  56. p = &buffer[0];
  57. char hex[HEX_BUFFER_SIZE];
  58. to_hex(hex);
  59. sprintf(p, "#ID[%s]", hex);
  60. char *s = p;
  61. p += strlen(p) + 1;
  62. return s;
  63. }
  64. template <>
  65. template <class STREAM> void Array<IdString64>::serialize(STREAM &stream) {
  66. raw_array_serialize(stream, *this);
  67. }
  68. template <>
  69. template <class STREAM> void Array<IdString32>::serialize(STREAM &stream) {
  70. raw_array_serialize(stream, *this);
  71. }
  72. }