FileStream_POSIX.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // FileStream_POSIX.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_POSIX_INCLUDED
  16. #define Foundation_FileStream_POSIX_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/BufferedBidirectionalStreamBuf.h"
  19. #include <istream>
  20. #include <ostream>
  21. namespace Poco {
  22. class Foundation_API FileStreamBuf: public BufferedBidirectionalStreamBuf
  23. /// This stream buffer handles Fileio
  24. {
  25. public:
  26. FileStreamBuf();
  27. /// Creates a FileStreamBuf.
  28. ~FileStreamBuf();
  29. /// Destroys the FileStream.
  30. void open(const std::string& path, std::ios::openmode mode);
  31. /// Opens the given file in the given mode.
  32. bool close();
  33. /// Closes the File stream buffer. Returns true if successful,
  34. /// false otherwise.
  35. std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
  36. /// Change position by offset, according to way and mode.
  37. std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
  38. /// Change to specified position, according to mode.
  39. protected:
  40. enum
  41. {
  42. BUFFER_SIZE = 4096
  43. };
  44. int readFromDevice(char* buffer, std::streamsize length);
  45. int writeToDevice(const char* buffer, std::streamsize length);
  46. private:
  47. std::string _path;
  48. int _fd;
  49. std::streamoff _pos;
  50. };
  51. } // namespace Poco
  52. #endif // Foundation_FileStream_WIN32_INCLUDED