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.

116 lines
4.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the more complete set of operations on the string_t defined
  4. // These should be used instead of direct manipulation to allow more
  5. // flexibility in future ports or optimization.
  6. //
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef STRING_T_H
  10. #define STRING_T_H
  11. #if defined( _WIN32 )
  12. #pragma once
  13. #endif
  14. #ifndef NO_STRING_T
  15. #ifdef WEAK_STRING_T
  16. typedef int string_t;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: The correct way to specify the NULL string as a constant.
  19. //-----------------------------------------------------------------------------
  20. #define NULL_STRING 0
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Given a string_t, make a C string. By convention the result string
  23. // pointer should be considered transient and should not be stored.
  24. //-----------------------------------------------------------------------------
  25. #define STRING( offset ) ( ( offset ) ? reinterpret_cast<const char *>( offset ) : "" )
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Given a C string, obtain a string_t
  28. //-----------------------------------------------------------------------------
  29. #define MAKE_STRING( str ) ( ( *str != 0 ) ? reinterpret_cast<int>( str ) : 0 )
  30. //-----------------------------------------------------------------------------
  31. #define IDENT_STRINGS( s1, s2 ) ( *((void **)&(s1)) == *((void **)&(s2)) )
  32. //-----------------------------------------------------------------------------
  33. #else // Strong string_t
  34. //-----------------------------------------------------------------------------
  35. struct string_t
  36. {
  37. public:
  38. bool operator!() const { return ( pszValue == NULL ); }
  39. bool operator==( const string_t &rhs ) const { return ( pszValue == rhs.pszValue ); }
  40. bool operator!=( const string_t &rhs ) const { return ( pszValue != rhs.pszValue ); }
  41. bool operator<( const string_t &rhs ) const { return ((void *)pszValue < (void *)rhs.pszValue ); }
  42. const char *ToCStr() const { return ( pszValue ) ? pszValue : ""; }
  43. protected:
  44. const char *pszValue;
  45. };
  46. //-----------------------------------------------------------------------------
  47. struct castable_string_t : public string_t // string_t is used in unions, hence, no constructor allowed
  48. {
  49. castable_string_t() { pszValue = NULL; }
  50. castable_string_t( const char *pszFrom ) { pszValue = (pszFrom && *pszFrom) ? pszFrom : 0; }
  51. };
  52. //-----------------------------------------------------------------------------
  53. // Purpose: The correct way to specify the NULL string as a constant.
  54. //-----------------------------------------------------------------------------
  55. #define NULL_STRING castable_string_t()
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Given a string_t, make a C string. By convention the result string
  58. // pointer should be considered transient and should not be stored.
  59. //-----------------------------------------------------------------------------
  60. #define STRING( string_t_obj ) (string_t_obj).ToCStr()
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Given a C string, obtain a string_t
  63. //-----------------------------------------------------------------------------
  64. #define MAKE_STRING( c_str ) castable_string_t( c_str )
  65. //-----------------------------------------------------------------------------
  66. #define IDENT_STRINGS( s1, s2 ) ( *((void **)&(s1)) == *((void **)&(s2)) )
  67. //-----------------------------------------------------------------------------
  68. #endif
  69. #else // NO_STRING_T
  70. typedef const char *string_t;
  71. #define NULL_STRING 0
  72. #define STRING( c_str ) ( c_str )
  73. #define MAKE_STRING( c_str ) ( c_str )
  74. #define IDENT_STRINGS( s1, s2 ) ( *((void **)&(s1)) == *((void **)&(s2)) )
  75. #endif // NO_STRING_T
  76. // Zero the object -- necessary for CNetworkVar and possibly other cases.
  77. inline void EnsureValidValue( string_t &x ) { x = NULL_STRING; }
  78. //=============================================================================
  79. #endif // STRING_T_H