Team Fortress 2 Source Code as on 22/4/2020
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.

113 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // videomacros.h - Commone macros used by valve video services
  4. //
  5. // Purpose - to save typing, make things cleaer, prep for c++0x, prep for 64-bit,
  6. // make lots of money, and drive Brian crazy
  7. //
  8. // ===========================================================================
  9. #ifndef VIDEOMACROS_H
  10. #define VIDEOMACROS_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include <tier0/dbg.h>
  15. // ------------------------------------------------------------------------
  16. // MACROS
  17. // ------------------------------------------------------------------------
  18. #define nullchar ( (char) 0x00 )
  19. #ifndef nullptr
  20. #define nullptr ( 0 )
  21. #endif
  22. #define ZeroVar( var ) V_memset( &var, nullchar, sizeof( var ) )
  23. #define ZeroVarPtr( pVar ) V_memset( pVar, nullchar, sizeof( *pVar) )
  24. #define SAFE_DELETE( var ) if ( var != nullptr ) { delete var; var = nullptr; }
  25. #define SAFE_DELETE_ARRAY( var ) if ( var != nullptr ) { delete[] var; var = nullptr; }
  26. #define SAFE_RELEASE( var ) if ( var != nullptr ) { var->Release(); var = nullptr; }
  27. #define SAFE_FREE( var ) if ( var != nullptr ) { free( var ); var = nullptr; }
  28. // Common Assert Patterns
  29. #define AssertPtr( _exp ) Assert( ( _exp ) != nullptr )
  30. #define AssertNull( _exp ) Assert( ( _exp ) == nullptr )
  31. #define AssertStr( _str ) Assert( ( _str ) != nullptr && *( _str ) != nullchar )
  32. #define AssertInRange( _exp, low, high ) Assert( ( _exp ) > ( low ) && ( _exp ) < ( high ) )
  33. #define AssertIncRange( _exp, low, high ) Assert( ( _exp ) >= ( low ) && ( _exp ) <= ( high ) )
  34. // AssertExit macros .. in release builds, or when Assert is disabled, they exit (w/ opt return value)
  35. // if the assert condition is false
  36. //
  37. #ifdef DBGFLAG_ASSERT
  38. #define AssertExit( _exp ) Assert( _exp )
  39. #define AssertExitV( _exp , _rval ) Assert( _exp )
  40. #define AssertExitF( _exp ) Assert( _exp )
  41. #define AssertExitN( _exp ) Assert( _exp )
  42. #define AssertExitFunc( _exp, _func ) Assert( _exp )
  43. #define AssertPtrExit( _exp ) Assert( ( _exp ) != nullptr )
  44. #define AssertPtrExitV( _exp , _rval ) Assert( ( _exp ) != nullptr )
  45. #define AssertPtrExitF( _exp ) Assert( ( _exp ) != nullptr )
  46. #define AssertPtrExitN( _exp ) Assert( ( _exp ) != nullptr )
  47. #define AssertInRangeExit( _exp , low , high ) Assert( ( _exp ) > ( low ) && ( _exp ) < ( high ) )
  48. #define AssertInRangeExitV( _exp , low , high, _rval ) Assert( ( _exp ) > ( low ) && ( _exp ) < ( high ) )
  49. #define AssertInRangeExitF( _exp , low , high ) Assert( ( _exp ) > ( low ) && ( _exp ) < ( high ) )
  50. #define AssertInRangeExitN( _exp , low , high ) Assert( ( _exp ) > ( low ) && ( _exp ) < ( high ) )
  51. #else // Asserts not enabled
  52. #define AssertExit( _exp ) if ( !( _exp ) ) return
  53. #define AssertExitV( _exp , _rval ) if ( !( _exp ) ) return _rval
  54. #define AssertExitF( _exp ) if ( !( _exp ) ) return false
  55. #define AssertExitN( _exp ) if ( !( _exp ) ) return nullptr
  56. #define AssertExitFunc( _exp, _func ) if ( !( _exp ) ) { _func; return; }
  57. #define AssertPtrExit( _exp ) if ( ( _exp ) == nullptr ) return
  58. #define AssertPtrExitV( _exp , _rval ) if ( ( _exp ) == nullptr ) return _rval
  59. #define AssertPtrExitF( _exp ) if ( ( _exp ) == nullptr ) return false
  60. #define AssertPtrExitN( _exp ) if ( ( _exp ) == nullptr ) return nullptr
  61. #define AssertInRangeExit( _exp, low, high ) if ( ( _exp ) <= ( low ) || ( _exp ) >= ( high ) ) return
  62. #define AssertInRangeExitV( _exp, low, high, _rval ) if ( ( _exp ) <= ( low ) || ( _exp ) >= ( high ) ) return _rval
  63. #define AssertInRangeExitF( _exp, low, high ) if ( ( _exp ) <= ( low ) || ( _exp ) >= ( high ) ) return false
  64. #define AssertInRangeExitN( _exp, low, high ) if ( ( _exp ) <= ( low ) || ( _exp ) >= ( high ) ) return nullptr
  65. #endif
  66. #define WarningAssert( _msg ) AssertMsg( false, _msg )
  67. #define STRINGS_MATCH 0
  68. #define IS_NOT_EMPTY( str ) ( (str) != nullptr && *(str) != nullchar )
  69. #define IS_EMPTY_STR( str ) ( (str) == nullptr || *(str) == nullchar )
  70. #define IS_IN_RANGE( var, low, high ) ( (var) >= (low) && (var) <= (high) )
  71. #define IS_IN_RANGECOUNT( var, low, high ) ( (var) >= (low) && (var) < (high) )
  72. #define IS_OUT_OF_RANGE( var, low, high ) ( (var) < (low) || (var) > (high) )
  73. #define IS_OUT_OF_RANGECOUNT( var, low, high ) ( (var) < (low) || (var) >= (high) )
  74. #define BITFLAGS_SET( var, bits ) ( ( (var) & (bits) ) == (bits) )
  75. #define ANY_BITFLAGS_SET( var, bits ) ( ( (var) & (bits) ) != 0 )
  76. #define MAKE_UINT64( highVal, lowVal ) ( ( (uint64) highVal << 32 ) | (uint64) lowVal )
  77. #define CONTAINING_MULTIPLE_OF( var, multVal ) ( (var) + ( multVal - 1) ) - ( ( (var) - 1) % multVal )
  78. // use this whenever we do address arithmetic in bytes
  79. typedef unsigned char* memaddr_t;
  80. typedef int32 memoffset_t;
  81. #endif // VIDEOMACROS_H