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.

125 lines
3.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "stringpool.h"
  9. #if !defined( GC )
  10. #include "igamesystem.h"
  11. #endif
  12. #include "gamestringpool.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Purpose: The actual storage for pooled per-level strings
  17. //-----------------------------------------------------------------------------
  18. #if !defined( GC )
  19. class CGameStringPool : public CStringPool, public CBaseGameSystem
  20. #else
  21. class CGameStringPool : public CStringPool
  22. #endif
  23. {
  24. virtual char const *Name() { return "CGameStringPool"; }
  25. virtual void LevelShutdownPostEntity()
  26. {
  27. FreeAll();
  28. PurgeDeferredDeleteList();
  29. CGameString::IncrementSerialNumber();
  30. }
  31. public:
  32. ~CGameStringPool()
  33. {
  34. PurgeDeferredDeleteList();
  35. }
  36. void PurgeDeferredDeleteList()
  37. {
  38. for ( int i = 0; i < m_DeferredDeleteList.Count(); ++ i )
  39. {
  40. free( ( void * )m_DeferredDeleteList[ i ] );
  41. }
  42. m_DeferredDeleteList.Purge();
  43. }
  44. void Dump( void )
  45. {
  46. for ( int i = m_Strings.FirstInorder(); i != m_Strings.InvalidIndex(); i = m_Strings.NextInorder(i) )
  47. {
  48. DevMsg( " %d (0x%p) : %s\n", i, m_Strings[i], m_Strings[i] );
  49. }
  50. DevMsg( "\n" );
  51. DevMsg( "Size: %d items\n", m_Strings.Count() );
  52. }
  53. void Remove( const char *pszValue )
  54. {
  55. int i = m_Strings.Find( pszValue );
  56. if ( i != m_Strings.InvalidIndex() )
  57. {
  58. m_DeferredDeleteList.AddToTail( m_Strings[ i ] );
  59. m_Strings.RemoveAt( i );
  60. }
  61. }
  62. private:
  63. CUtlVector< const char * > m_DeferredDeleteList;
  64. };
  65. static CGameStringPool g_GameStringPool;
  66. //-----------------------------------------------------------------------------
  67. // String system accessor
  68. //-----------------------------------------------------------------------------
  69. #if !defined( GC )
  70. IGameSystem *GameStringSystem()
  71. {
  72. return &g_GameStringPool;
  73. }
  74. #endif
  75. //-----------------------------------------------------------------------------
  76. // Purpose: The public accessor for the level-global pooled strings
  77. //-----------------------------------------------------------------------------
  78. string_t AllocPooledString( const char * pszValue )
  79. {
  80. if (pszValue && *pszValue)
  81. return MAKE_STRING( g_GameStringPool.Allocate( pszValue ) );
  82. return NULL_STRING;
  83. }
  84. string_t FindPooledString( const char *pszValue )
  85. {
  86. return MAKE_STRING( g_GameStringPool.Find( pszValue ) );
  87. }
  88. void RemovePooledString( const char *pszValue )
  89. {
  90. g_GameStringPool.Remove( pszValue );
  91. }
  92. int CGameString::gm_iSerialNumber = 1;
  93. #if !defined(CLIENT_DLL) && !defined( GC )
  94. //------------------------------------------------------------------------------
  95. // Purpose:
  96. //------------------------------------------------------------------------------
  97. void CC_DumpGameStringTable( void )
  98. {
  99. if ( !UTIL_IsCommandIssuedByServerAdmin() )
  100. return;
  101. g_GameStringPool.Dump();
  102. }
  103. static ConCommand dumpgamestringtable("dumpgamestringtable", CC_DumpGameStringTable, "Dump the contents of the game string table to the console.", FCVAR_CHEAT);
  104. #endif