Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.2 KiB

  1. // Uuid.h -- Universally Unique IDentifier functor wrapper implementation to
  2. // create and manage UUIDs
  3. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  4. // 1999. This computer program includes Confidential, Proprietary
  5. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  6. // use, disclosure, and/or reproduction is prohibited unless authorized
  7. // in writing. All Rights Reserved.
  8. #if defined(_UNICODE)
  9. #if !defined(UNICODE)
  10. #define UNICODE
  11. #endif //!UNICODE
  12. #endif //_UNICODE
  13. #if defined(UNICODE)
  14. #if !defined(_UNICODE)
  15. #define _UNICODE
  16. #endif //!_UNICODE
  17. #endif //UNICODE
  18. #include <scuOsExc.h>
  19. #include "Uuid.h"
  20. using namespace std;
  21. /////////////////////////// HELPER /////////////////////////////////
  22. typedef LPTSTR *SLB_PLPTSTR;
  23. struct RpcString // to help manage deallocation
  24. {
  25. public:
  26. RpcString()
  27. : m_psz(0)
  28. {};
  29. ~RpcString()
  30. {
  31. if (m_psz)
  32. #if defined(UNICODE)
  33. RpcStringFree((SLB_PLPTSTR)&m_psz);
  34. #else
  35. RpcStringFree(&m_psz);
  36. #endif
  37. };
  38. unsigned char *m_psz;
  39. };
  40. /////////////////////////// PUBLIC /////////////////////////////////
  41. // Types
  42. // C'tors/D'tors
  43. Uuid::Uuid(bool fNilValued)
  44. {
  45. RPC_STATUS rpcstatus;
  46. if (fNilValued)
  47. rpcstatus = UuidCreateNil(&m_uuid);
  48. else
  49. {
  50. rpcstatus = UuidCreate(&m_uuid);
  51. if (RPC_S_UUID_LOCAL_ONLY == rpcstatus)
  52. rpcstatus = RPC_S_OK;
  53. }
  54. if (RPC_S_OK != rpcstatus)
  55. throw scu::OsException(rpcstatus);
  56. }
  57. Uuid::Uuid(basic_string<unsigned char> const &rusUuid)
  58. {
  59. RPC_STATUS rpcstatus =
  60. #if defined(UNICODE)
  61. UuidFromString((LPTSTR)rusUuid.c_str(), &m_uuid);
  62. #else
  63. UuidFromString(const_cast<unsigned char *>(rusUuid.c_str()), &m_uuid);
  64. #endif
  65. if (RPC_S_OK != rpcstatus)
  66. throw scu::OsException(rpcstatus);
  67. }
  68. Uuid::Uuid(UUID const *puuid)
  69. {
  70. m_uuid = *puuid;
  71. }
  72. // Operators
  73. Uuid::operator==(Uuid &ruuid)
  74. {
  75. RPC_STATUS rpcstatus;
  76. int fResult = UuidEqual(&m_uuid, &ruuid.m_uuid, &rpcstatus);
  77. if (RPC_S_OK != rpcstatus)
  78. throw scu::OsException(rpcstatus);
  79. return fResult;
  80. }
  81. // Operations
  82. // Access
  83. basic_string<unsigned char>
  84. Uuid::AsUString()
  85. {
  86. RpcString rpcsUuid;
  87. #if defined(UNICODE)
  88. RPC_STATUS rpcstatus = UuidToString(&m_uuid, (SLB_PLPTSTR)&rpcsUuid.m_psz);
  89. #else
  90. RPC_STATUS rpcstatus = UuidToString(&m_uuid, &rpcsUuid.m_psz);
  91. #endif
  92. if (RPC_S_OK != rpcstatus)
  93. throw scu::OsException(rpcstatus);
  94. return basic_string<unsigned char>(rpcsUuid.m_psz);
  95. }
  96. unsigned short
  97. Uuid::HashValue()
  98. {
  99. RPC_STATUS rpcstatus;
  100. unsigned short usValue = UuidHash(&m_uuid, &rpcstatus);
  101. if (RPC_S_OK != rpcstatus)
  102. throw scu::OsException(rpcstatus);
  103. return usValue;
  104. }
  105. // Predicates
  106. bool
  107. Uuid::IsNil()
  108. {
  109. RPC_STATUS rpcstatus;
  110. int fResult = UuidIsNil(&m_uuid, &rpcstatus);
  111. if (RPC_S_OK != rpcstatus)
  112. throw scu::OsException(rpcstatus);
  113. return fResult == TRUE;
  114. }
  115. /////////////////////////// PROTECTED /////////////////////////////////
  116. // C'tors/D'tors
  117. // Operators
  118. // Operations
  119. // Access
  120. // Predicates
  121. // Static Variables
  122. /////////////////////////// PRIVATE /////////////////////////////////
  123. // C'tors/D'tors
  124. // Operators
  125. // Operations
  126. // Access
  127. // Predicates
  128. // Static Variables