FileStream.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <iosfwd>
  3. #include <boost/iostreams/categories.hpp>
  4. #include <boost/iostreams/stream.hpp>
  5. class DLL_LINKAGE FileBuf
  6. {
  7. public:
  8. typedef char char_type;
  9. typedef struct category_ :
  10. boost::iostreams::seekable_device_tag,
  11. boost::iostreams::closable_tag
  12. {} category;
  13. FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode);
  14. std::streamsize read(char* s, std::streamsize n);
  15. std::streamsize write(const char* s, std::streamsize n);
  16. std::streamoff seek(std::streamoff off, std::ios_base::seekdir way);
  17. void close();
  18. private:
  19. void* filePtr;
  20. };
  21. struct zlib_filefunc64_def_s;
  22. typedef zlib_filefunc64_def_s zlib_filefunc64_def;
  23. #ifdef VCMI_DLL
  24. extern template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
  25. #endif
  26. class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
  27. {
  28. public:
  29. FileStream() = default;
  30. explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
  31. : boost::iostreams::stream<FileBuf>(p, mode) {}
  32. static bool CreateFile(const boost::filesystem::path& filename);
  33. static zlib_filefunc64_def* GetMinizipFilefunc();
  34. };