Counter Strike : Global Offensive Source Code
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.

74 lines
1.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef UTLSTRINGTOKEN_H
  9. #define UTLSTRINGTOKEN_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include <limits.h>
  14. #include "tier0/threadtools.h"
  15. #include "tier1/mempool.h"
  16. #include "tier1/generichash.h"
  17. #define DEBUG_STRINGTOKENS 0
  18. #define STRINGTOKEN_MURMURHASH_SEED 0x31415926
  19. class CUtlStringToken
  20. {
  21. public:
  22. uint32 m_nHashCode;
  23. #if DEBUG_STRINGTOKENS
  24. char const *m_pDebugName;
  25. #endif
  26. FORCEINLINE bool operator==( CUtlStringToken const &other ) const
  27. {
  28. return ( other.m_nHashCode == m_nHashCode );
  29. }
  30. FORCEINLINE bool operator!=( CUtlStringToken const &other ) const
  31. {
  32. return ( other.m_nHashCode != m_nHashCode );
  33. }
  34. FORCEINLINE bool operator<( CUtlStringToken const &other ) const
  35. {
  36. return ( m_nHashCode < other.m_nHashCode );
  37. }
  38. /// access to the hash code for people who need to store thse as 32-bits, regardless of the
  39. /// setting of DEBUG_STRINGTOKENS (for instance, for atomic operations).
  40. FORCEINLINE uint32 GetHashCode( void ) const { return m_nHashCode; }
  41. FORCEINLINE void SetHashCode( uint32 nCode ) { m_nHashCode = nCode; }
  42. #ifndef _DEBUG // the auto-generated things are too big when not inlined and optimized away
  43. #include "tier1/utlstringtoken_generated_contructors.h"
  44. #else
  45. CUtlStringToken( char const *pString ) // generate one from a dynamic string
  46. {
  47. m_nHashCode = MurmurHash2LowerCase( pString, STRINGTOKEN_MURMURHASH_SEED );
  48. }
  49. #endif
  50. CUtlStringToken() { m_nHashCode = 0; }
  51. };
  52. FORCEINLINE CUtlStringToken MakeStringToken( char const *pString )
  53. {
  54. CUtlStringToken ret;
  55. ret.m_nHashCode = MurmurHash2LowerCase( pString, STRINGTOKEN_MURMURHASH_SEED );
  56. return ret;
  57. }
  58. #endif // UTLSTRINGTOKEN_H