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.

70 lines
1.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "dt_utlvector_common.h"
  7. #include "utldict.h"
  8. #include "tier0/memdbgon.h"
  9. static CUtlDict<int,int> *g_STDict = 0;
  10. static CUtlDict<int,int> *g_RTDict = 0;
  11. char* AllocateStringHelper2( const char *pFormat, va_list marker )
  12. {
  13. char str[512];
  14. _vsnprintf( str, sizeof( str ), pFormat, marker );
  15. str[ sizeof(str) - 1 ] = 0;
  16. int len = strlen( str ) + 1;
  17. char *pRet = new char[len];
  18. memcpy( pRet, str, len );
  19. return pRet;
  20. }
  21. char* AllocateStringHelper( const char *pFormat, ... )
  22. {
  23. va_list marker;
  24. va_start( marker, pFormat );
  25. char *pRet = AllocateStringHelper2( pFormat, marker );
  26. va_end( marker );
  27. return pRet;
  28. }
  29. char* AllocateUniqueDataTableName( bool bSendTable, const char *pFormat, ... )
  30. {
  31. // Setup the string.
  32. va_list marker;
  33. va_start( marker, pFormat );
  34. char *pRet = AllocateStringHelper2( pFormat, marker );
  35. va_end( marker );
  36. // Make sure it's unique.
  37. #ifdef _DEBUG
  38. // Have to allocate them here because if they're declared as straight global variables,
  39. // their constructors won't have been called yet by the time we get in here.
  40. if ( !g_STDict )
  41. {
  42. g_STDict = new CUtlDict<int,int>;
  43. g_RTDict = new CUtlDict<int,int>;
  44. }
  45. CUtlDict<int,int> *pDict = bSendTable ? g_STDict : g_RTDict;
  46. if ( pDict->Find( pRet ) != pDict->InvalidIndex() )
  47. {
  48. // If it hits this, then they have 2 utlvectors in different data tables with the same name and the
  49. // same size limit. The names of
  50. Assert( false );
  51. }
  52. pDict->Insert( pRet, 0 );
  53. #endif
  54. return pRet;
  55. }