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.

75 lines
1.8 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. // Serialization/unserialization buffer
  8. //=============================================================================//
  9. #ifndef UTLSTREAMBUFFER_H
  10. #define UTLSTREAMBUFFER_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "tier1/utlbuffer.h"
  15. #include "filesystem.h"
  16. //-----------------------------------------------------------------------------
  17. // Command parsing..
  18. //-----------------------------------------------------------------------------
  19. class CUtlStreamBuffer : public CUtlBuffer
  20. {
  21. typedef CUtlBuffer BaseClass;
  22. public:
  23. // See CUtlBuffer::BufferFlags_t for flags
  24. CUtlStreamBuffer( );
  25. CUtlStreamBuffer( const char *pFileName, const char *pPath, int nFlags = 0, bool bDelayOpen = false, int nOpenFileFlags = 0 );
  26. ~CUtlStreamBuffer();
  27. // Open the file. normally done in constructor
  28. void Open( const char *pFileName, const char *pPath, int nFlags, int nOpenFileFlags = 0 );
  29. // close the file. normally done in destructor
  30. void Close();
  31. // Is the file open?
  32. bool IsOpen() const;
  33. // try flushing the file
  34. bool TryFlushToFile( int nFlushToFileBytes );
  35. private:
  36. // error flags
  37. enum
  38. {
  39. FILE_OPEN_ERROR = MAX_ERROR_FLAG << 1,
  40. };
  41. // Overflow functions
  42. bool StreamPutOverflow( int nSize );
  43. bool StreamGetOverflow( int nSize );
  44. // Grow allocation size to fit requested size
  45. void GrowAllocatedSize( int nSize );
  46. // Reads bytes from the file; fixes up maxput if necessary and null terminates
  47. int ReadBytesFromFile( int nBytesToRead, int nReadOffset );
  48. FileHandle_t OpenFile( const char *pFileName, const char *pPath, int nOpenFileFlags );
  49. FileHandle_t m_hFileHandle;
  50. // cached for delayed open
  51. char *m_pFileName;
  52. char *m_pPath;
  53. int m_nOpenFileFlags;
  54. };
  55. #endif // UTLSTREAMBUFFER_H