Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/toolkit/source/NvBlastTkGUID.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 #ifndef NVBLASTTKGUID_H
00030 #define NVBLASTTKGUID_H
00031 
00032 #include "NvPreprocessor.h"
00033 
00034 #if NV_WINDOWS_FAMILY
00035 #include <rpc.h>
00036 #else
00037 //#include <uuid/uuid.h>
00038 #include "NvBlastTime.h"
00039 #endif
00040 
00041 #include "PsHash.h"
00042 
00043 namespace Nv
00044 {
00045 namespace Blast
00046 {
00047 
00048 #if NV_WINDOWS_FAMILY
00049 
00050 NV_INLINE NvBlastID TkGenerateGUID(void* ptr)
00051 {
00052     NV_UNUSED(ptr);
00053 
00054     NV_COMPILE_TIME_ASSERT(sizeof(UUID) == sizeof(NvBlastID));
00055 
00056     NvBlastID guid;
00057     UuidCreate(reinterpret_cast<UUID*>(&guid));
00058 
00059     return guid;
00060 }
00061 
00062 #else
00063 
00064 NV_INLINE NvBlastID TkGenerateGUID(void* ptr)
00065 {
00066 //  NV_COMPILE_TIME_ASSERT(sizeof(uuid_t) == sizeof(NvBlastID));
00067     Time time;
00068 
00069     NvBlastID guid;
00070     //  uuid_generate_random(reinterpret_cast<uuid_t&>(guid));
00071 
00072     *reinterpret_cast<uint64_t*>(guid.data) = reinterpret_cast<uintptr_t>(ptr);
00073     *reinterpret_cast<int64_t*>(guid.data + 8) = time.getLastTickCount();
00074 
00075     return guid;
00076 }
00077 
00078 #endif
00079 
00080 
00089 NV_INLINE bool TkGUIDsEqual(const NvBlastID* id1, const NvBlastID* id2)
00090 {
00091     return !memcmp(id1, id2, sizeof(NvBlastID));
00092 }
00093 
00094 
00100 NV_INLINE void TkGUIDReset(NvBlastID* id)
00101 {
00102     memset(id, 0, sizeof(NvBlastID));
00103 }
00104 
00105 
00112 NV_INLINE bool TkGUIDIsZero(const NvBlastID* id)
00113 {
00114     return *reinterpret_cast<const uint64_t*>(&id->data[0]) == 0 && *reinterpret_cast<const uint64_t*>(&id->data[8]) == 0;
00115 }
00116 
00117 } // namespace Blast
00118 } // namespace Nv
00119 
00120 
00121 namespace physx
00122 {
00123 namespace shdfnd
00124 {
00125 
00126 // hash specialization for NvBlastID
00127 template <>
00128 struct Hash<NvBlastID>
00129 {
00130     uint32_t operator()(const NvBlastID& k) const
00131     {
00132         // "DJB" string hash
00133         uint32_t h = 5381;
00134         for (uint32_t i = 0; i < sizeof(k.data) / sizeof(k.data[0]); ++i)
00135             h = ((h << 5) + h) ^ uint32_t(k.data[i]);
00136         return h;
00137     }
00138     bool equal(const NvBlastID& k0, const NvBlastID& k1) const
00139     {
00140         return Nv::Blast::TkGUIDsEqual(&k0, &k1);
00141     }
00142 };
00143 
00144 } // namespace shdfnd
00145 } // namespace physx
00146 
00147 
00148 #endif // #ifndef NVBLASTTKGUID_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com