uuid.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TORQUE_UUID_H_
  23. #define _TORQUE_UUID_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #include "console/engineTypeInfo.h"
  28. typedef unsigned int unsigned32;
  29. typedef unsigned short unsigned16;
  30. typedef unsigned char unsigned8;
  31. class xuuid_t
  32. {
  33. public:
  34. unsigned32 time_low;
  35. unsigned16 time_mid;
  36. unsigned16 time_hi_and_version;
  37. unsigned8 clock_seq_hi_and_reserved;
  38. unsigned8 clock_seq_low;
  39. unsigned8 node[6];
  40. };
  41. namespace Torque
  42. {
  43. /// A universally unique identifier.
  44. class UUID : public xuuid_t
  45. {
  46. friend class UUIDEngineExport;
  47. public:
  48. typedef void Parent;
  49. protected:
  50. U32 a;
  51. U16 b;
  52. U16 c;
  53. U8 d;
  54. U8 e;
  55. U8 f[ 6 ];
  56. static UUID smNull;
  57. public:
  58. UUID()
  59. {
  60. dMemset( this, 0, sizeof( UUID ) );
  61. }
  62. ///
  63. bool isNull() const { return ( *this == smNull ); }
  64. /// Generate a new universally unique identifier (UUID).
  65. void generate();
  66. /// Convert the given universally unique identifier to a printed string
  67. /// representation.
  68. String toString() const;
  69. /// Parse a text string generated by UUIDToString back into a
  70. /// universally unique identifier (UUID).
  71. bool fromString( const char* str );
  72. /// Return a hash value for this UUID.
  73. U32 getHash() const;
  74. bool operator ==( const UUID& uuid ) const
  75. {
  76. return ( dMemcmp( this, &uuid, sizeof( UUID ) ) == 0 );
  77. }
  78. bool operator !=( const UUID& uuid ) const
  79. {
  80. return !( *this == uuid );
  81. }
  82. };
  83. class UUIDEngineExport
  84. {
  85. public:
  86. static EngineFieldTable::Field getAField();
  87. static EngineFieldTable::Field getBField();
  88. static EngineFieldTable::Field getCField();
  89. static EngineFieldTable::Field getDField();
  90. static EngineFieldTable::Field getEField();
  91. static EngineFieldTable::Field getFField();
  92. };
  93. }
  94. namespace DictHash
  95. {
  96. inline U32 hash( const Torque::UUID& uuid )
  97. {
  98. return uuid.getHash();
  99. }
  100. }
  101. #endif // !_TORQUE_UUID_H_