uuid.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. namespace Torque
  29. {
  30. /// A universally unique identifier.
  31. class UUID
  32. {
  33. friend class UUIDEngineExport;
  34. public:
  35. typedef void Parent;
  36. protected:
  37. U32 a;
  38. U16 b;
  39. U16 c;
  40. U8 d;
  41. U8 e;
  42. U8 f[ 6 ];
  43. static UUID smNull;
  44. public:
  45. UUID()
  46. {
  47. dMemset( this, 0, sizeof( UUID ) );
  48. }
  49. ///
  50. bool isNull() const { return ( *this == smNull ); }
  51. /// Generate a new universally unique identifier (UUID).
  52. void generate();
  53. /// Convert the given universally unique identifier to a printed string
  54. /// representation.
  55. String toString() const;
  56. /// Parse a text string generated by UUIDToString back into a
  57. /// universally unique identifier (UUID).
  58. bool fromString( const char* str );
  59. /// Return a hash value for this UUID.
  60. U32 getHash() const;
  61. bool operator ==( const UUID& uuid ) const
  62. {
  63. return ( dMemcmp( this, &uuid, sizeof( UUID ) ) == 0 );
  64. }
  65. bool operator !=( const UUID& uuid ) const
  66. {
  67. return !( *this == uuid );
  68. }
  69. };
  70. class UUIDEngineExport
  71. {
  72. public:
  73. static EngineFieldTable::Field getAField();
  74. static EngineFieldTable::Field getBField();
  75. static EngineFieldTable::Field getCField();
  76. static EngineFieldTable::Field getDField();
  77. static EngineFieldTable::Field getEField();
  78. static EngineFieldTable::Field getFField();
  79. };
  80. }
  81. namespace DictHash
  82. {
  83. inline U32 hash( const Torque::UUID& uuid )
  84. {
  85. return uuid.getHash();
  86. }
  87. }
  88. #endif // !_TORQUE_UUID_H_