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.

87 lines
1.6 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. #ifndef RNDEBUGNAME_HDR
  3. #define RNDEBUGNAME_HDR
  4. #ifdef _DEBUG
  5. #define RUBIKON_DEBUG_NAMES 1
  6. #else
  7. #define RUBIKON_DEBUG_NAMES 0
  8. #endif
  9. class CRnDebugName
  10. {
  11. public:
  12. CRnDebugName() { Init( ); }
  13. ~CRnDebugName();
  14. public:
  15. void SetV( const char* pNameFormat, va_list args );
  16. const char *Get() const;
  17. const char *GetSafe( ) const; // return either name or "", but not NULL
  18. void Init();
  19. public:
  20. #if RUBIKON_DEBUG_NAMES
  21. char *m_pName; // please keep the name at the top if possible: it's much easier to debug in VS that way
  22. #endif
  23. };
  24. inline void CRnDebugName::Init()
  25. {
  26. #if RUBIKON_DEBUG_NAMES
  27. m_pName = NULL;
  28. #endif
  29. }
  30. inline CRnDebugName::~CRnDebugName()
  31. {
  32. #if RUBIKON_DEBUG_NAMES
  33. if( m_pName )
  34. {
  35. delete[]m_pName;
  36. }
  37. #endif
  38. }
  39. //---------------------------------------------------------------------------------------
  40. inline void CRnDebugName::SetV( const char *pNameFormat, va_list args )
  41. {
  42. #if RUBIKON_DEBUG_NAMES
  43. if( m_pName )
  44. {
  45. delete[]m_pName;
  46. m_pName = NULL;
  47. }
  48. if( pNameFormat )
  49. {
  50. CReuseVaList dup_args( args );
  51. int nLen = vsnprintf( NULL, 0, pNameFormat, dup_args.m_ReuseList );
  52. if( nLen > 0 )
  53. {
  54. m_pName = new char[nLen + 2];
  55. m_pName[nLen] = '\xFF';
  56. m_pName[nLen + 1] = '\xFF';
  57. vsnprintf( m_pName, nLen + 1, pNameFormat, args );
  58. AssertDbg( m_pName[nLen + 1] == '\xFF' && m_pName[nLen] == '\0' );
  59. }
  60. }
  61. #endif
  62. }
  63. inline const char *CRnDebugName::Get() const
  64. {
  65. #if RUBIKON_DEBUG_NAMES
  66. return m_pName;
  67. #else
  68. return NULL;
  69. #endif
  70. }
  71. inline const char *CRnDebugName::GetSafe() const
  72. {
  73. const char *p = Get( );
  74. return p ? p : "";
  75. }
  76. #endif