FileStream_WIN32.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // FileStream_WIN32.h
  3. //
  4. // Library: Foundation
  5. // Package: Streams
  6. // Module: FileStream
  7. //
  8. // Definition of the FileStreamBuf, FileInputStream and FileOutputStream classes.
  9. //
  10. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_FileStream_WIN32_INCLUDED
  16. #define Foundation_FileStream_WIN32_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/BufferedBidirectionalStreamBuf.h"
  19. #include "Poco/UnWindows.h"
  20. namespace Poco {
  21. class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
  22. /// This stream buffer handles Fileio
  23. {
  24. public:
  25. FileStreamBuf();
  26. /// Creates a FileStreamBuf.
  27. ~FileStreamBuf();
  28. /// Destroys the FileStream.
  29. void open(const std::string& path, std::ios::openmode mode);
  30. /// Opens the given file in the given mode.
  31. bool close();
  32. /// Closes the File stream buffer. Returns true if successful,
  33. /// false otherwise.
  34. std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
  35. /// change position by offset, according to way and mode
  36. std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
  37. /// change to specified position, according to mode
  38. protected:
  39. enum
  40. {
  41. BUFFER_SIZE = 4096
  42. };
  43. int readFromDevice(char* buffer, std::streamsize length);
  44. int writeToDevice(const char* buffer, std::streamsize length);
  45. private:
  46. std::string _path;
  47. HANDLE _handle;
  48. UInt64 _pos;
  49. };
  50. } // namespace Poco
  51. #endif // Foundation_FileStream_WIN32_INCLUDED