FileStream.h 1.2 KB

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