Team Fortress 2 Source Code as on 22/4/2020
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.

56 lines
1.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. // Utilities for globally unique IDs
  8. //=============================================================================//
  9. #ifndef UNIQUEID_H
  10. #define UNIQUEID_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier1/utlvector.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. struct UniqueId_t;
  19. class CUtlBuffer;
  20. //-----------------------------------------------------------------------------
  21. // Defines a globally unique ID
  22. //-----------------------------------------------------------------------------
  23. struct UniqueId_t
  24. {
  25. unsigned char m_Value[16];
  26. };
  27. //-----------------------------------------------------------------------------
  28. // Methods related to unique ids
  29. //-----------------------------------------------------------------------------
  30. void CreateUniqueId( UniqueId_t *pDest );
  31. void InvalidateUniqueId( UniqueId_t *pDest );
  32. bool IsUniqueIdValid( const UniqueId_t &id );
  33. bool IsUniqueIdEqual( const UniqueId_t &id1, const UniqueId_t &id2 );
  34. void UniqueIdToString( const UniqueId_t &id, char *pBuf, int nMaxLen );
  35. bool UniqueIdFromString( UniqueId_t *pDest, const char *pBuf, int nMaxLen = 0 );
  36. void CopyUniqueId( const UniqueId_t &src, UniqueId_t *pDest );
  37. bool Serialize( CUtlBuffer &buf, const UniqueId_t &src );
  38. bool Unserialize( CUtlBuffer &buf, UniqueId_t &dest );
  39. inline bool operator ==( const UniqueId_t& lhs, const UniqueId_t& rhs )
  40. {
  41. return !Q_memcmp( (void *)&lhs.m_Value[ 0 ], (void *)&rhs.m_Value[ 0 ], sizeof( lhs.m_Value ) );
  42. }
  43. #endif // UNIQUEID_H