FileStream.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <iosfwd>
  3. #include <boost/iostreams/categories.hpp>
  4. #include <boost/iostreams/stream.hpp>
  5. class 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. #else
  26. template class DLL_LINKAGE boost::iostreams::stream<FileBuf>;
  27. #endif
  28. class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
  29. {
  30. public:
  31. FileStream() = default;
  32. explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
  33. : boost::iostreams::stream<FileBuf>(p, mode) {}
  34. static bool CreateFile(const boost::filesystem::path& filename);
  35. static zlib_filefunc64_def* GetMinizipFilefunc();
  36. };