UUID.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using libsecondlife;
  3. namespace OpenSim.Framework.Types
  4. {
  5. class UUID
  6. {
  7. public LLUUID llUUID;
  8. public UUID(string uuid)
  9. {
  10. llUUID = new LLUUID(uuid);
  11. }
  12. public UUID(byte[] uuid)
  13. {
  14. llUUID = new LLUUID(uuid, 0);
  15. }
  16. public UUID(byte[] uuid, int offset)
  17. {
  18. llUUID = new LLUUID(uuid, offset);
  19. }
  20. public UUID()
  21. {
  22. llUUID = LLUUID.Zero;
  23. }
  24. public UUID(ulong uuid)
  25. {
  26. llUUID = new LLUUID(uuid);
  27. }
  28. public UUID(UInt32 first, UInt32 second, UInt32 third, UInt32 fourth)
  29. {
  30. byte[] uuid = new byte[16];
  31. byte[] n = BitConverter.GetBytes(first);
  32. n.CopyTo(uuid, 0);
  33. n = BitConverter.GetBytes(second);
  34. n.CopyTo(uuid, 4);
  35. n = BitConverter.GetBytes(third);
  36. n.CopyTo(uuid, 8);
  37. n = BitConverter.GetBytes(fourth);
  38. n.CopyTo(uuid, 12);
  39. llUUID = new LLUUID(uuid,0);
  40. }
  41. public override string ToString()
  42. {
  43. return llUUID.ToString();
  44. }
  45. public string ToStringHyphenated()
  46. {
  47. return llUUID.ToStringHyphenated();
  48. }
  49. public byte[] GetBytes()
  50. {
  51. return llUUID.GetBytes();
  52. }
  53. public UInt32[] GetInts()
  54. {
  55. UInt32[] ints = new UInt32[4];
  56. ints[0] = BitConverter.ToUInt32(llUUID.Data, 0);
  57. ints[1] = BitConverter.ToUInt32(llUUID.Data, 4);
  58. ints[2] = BitConverter.ToUInt32(llUUID.Data, 8);
  59. ints[3] = BitConverter.ToUInt32(llUUID.Data, 12);
  60. return ints;
  61. }
  62. public LLUUID GetLLUUID()
  63. {
  64. return llUUID;
  65. }
  66. public uint CRC()
  67. {
  68. return llUUID.CRC();
  69. }
  70. public override int GetHashCode()
  71. {
  72. return llUUID.GetHashCode();
  73. }
  74. public void Combine(UUID other)
  75. {
  76. llUUID.Combine(other.GetLLUUID());
  77. }
  78. public void Combine(LLUUID other)
  79. {
  80. llUUID.Combine(other);
  81. }
  82. public override bool Equals(Object other)
  83. {
  84. return llUUID.Equals(other);
  85. }
  86. public static bool operator ==(UUID a, UUID b)
  87. {
  88. return a.llUUID.Equals(b.GetLLUUID());
  89. }
  90. public static bool operator !=(UUID a, UUID b)
  91. {
  92. return !a.llUUID.Equals(b.GetLLUUID());
  93. }
  94. public static bool operator ==(UUID a, LLUUID b)
  95. {
  96. return a.Equals(b);
  97. }
  98. public static bool operator !=(UUID a, LLUUID b)
  99. {
  100. return !a.Equals(b);
  101. }
  102. }
  103. }