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.

71 lines
1.6 KiB

  1. //========= Copyright 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 );
  26. ~CUtlStreamBuffer();
  27. // Open the file. normally done in constructor
  28. void Open( const char *pFileName, const char *pPath, int nFlags );
  29. // close the file. normally done in destructor
  30. void Close();
  31. // Is the file open?
  32. bool IsOpen() const;
  33. private:
  34. // error flags
  35. enum
  36. {
  37. FILE_OPEN_ERROR = MAX_ERROR_FLAG << 1,
  38. FILE_WRITE_ERROR = MAX_ERROR_FLAG << 2,
  39. };
  40. // Overflow functions
  41. bool StreamPutOverflow( int nSize );
  42. bool StreamGetOverflow( int nSize );
  43. // Grow allocation size to fit requested size
  44. void GrowAllocatedSize( int nSize );
  45. // Reads bytes from the file; fixes up maxput if necessary and null terminates
  46. int ReadBytesFromFile( int nBytesToRead, int nReadOffset );
  47. FileHandle_t OpenFile( const char *pFileName, const char *pPath );
  48. FileHandle_t m_hFileHandle;
  49. char *m_pFileName;
  50. char *m_pPath;
  51. };
  52. #endif // UTLSTREAMBUFFER_H