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.

107 lines
2.3 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef UTLBINARYBLOCK_H
  7. #define UTLBINARYBLOCK_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlmemory.h"
  12. #include "tier1/strtools.h"
  13. #include "limits.h"
  14. //-----------------------------------------------------------------------------
  15. // Base class, containing simple memory management
  16. //-----------------------------------------------------------------------------
  17. class CUtlBinaryBlock
  18. {
  19. public:
  20. CUtlBinaryBlock( int growSize = 0, int initSize = 0 );
  21. // NOTE: nInitialLength indicates how much of the buffer starts full
  22. CUtlBinaryBlock( void* pMemory, int nSizeInBytes, int nInitialLength );
  23. CUtlBinaryBlock( const void* pMemory, int nSizeInBytes );
  24. CUtlBinaryBlock( const CUtlBinaryBlock& src );
  25. void Get( void *pValue, int nMaxLen ) const;
  26. void Set( const void *pValue, int nLen );
  27. const void *Get( ) const;
  28. void *Get( );
  29. unsigned char& operator[]( int i );
  30. const unsigned char& operator[]( int i ) const;
  31. int Length() const;
  32. void SetLength( int nLength ); // Undefined memory will result
  33. bool IsEmpty() const;
  34. void Clear();
  35. void Purge();
  36. bool IsReadOnly() const;
  37. CUtlBinaryBlock &operator=( const CUtlBinaryBlock &src );
  38. // Test for equality
  39. bool operator==( const CUtlBinaryBlock &src ) const;
  40. private:
  41. CUtlMemory<unsigned char> m_Memory;
  42. int m_nActualLength;
  43. };
  44. //-----------------------------------------------------------------------------
  45. // class inlines
  46. //-----------------------------------------------------------------------------
  47. inline const void *CUtlBinaryBlock::Get( ) const
  48. {
  49. return m_Memory.Base();
  50. }
  51. inline void *CUtlBinaryBlock::Get( )
  52. {
  53. return m_Memory.Base();
  54. }
  55. inline int CUtlBinaryBlock::Length() const
  56. {
  57. return m_nActualLength;
  58. }
  59. inline unsigned char& CUtlBinaryBlock::operator[]( int i )
  60. {
  61. return m_Memory[i];
  62. }
  63. inline const unsigned char& CUtlBinaryBlock::operator[]( int i ) const
  64. {
  65. return m_Memory[i];
  66. }
  67. inline bool CUtlBinaryBlock::IsReadOnly() const
  68. {
  69. return m_Memory.IsReadOnly();
  70. }
  71. inline bool CUtlBinaryBlock::IsEmpty() const
  72. {
  73. return Length() == 0;
  74. }
  75. inline void CUtlBinaryBlock::Clear()
  76. {
  77. SetLength( 0 );
  78. }
  79. inline void CUtlBinaryBlock::Purge()
  80. {
  81. SetLength( 0 );
  82. m_Memory.Purge();
  83. }
  84. #endif // UTLBINARYBLOCK_H