FileStream.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * FileStream.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <boost/iostreams/categories.hpp>
  12. #include <boost/iostreams/stream.hpp>
  13. class DLL_LINKAGE FileBuf
  14. {
  15. public:
  16. typedef char char_type;
  17. typedef struct category_ :
  18. boost::iostreams::seekable_device_tag,
  19. boost::iostreams::closable_tag
  20. {} category;
  21. FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode);
  22. std::streamsize read(char* s, std::streamsize n);
  23. std::streamsize write(const char* s, std::streamsize n);
  24. std::streamoff seek(std::streamoff off, std::ios_base::seekdir way);
  25. void close();
  26. private:
  27. void* filePtr;
  28. };
  29. struct zlib_filefunc64_def_s;
  30. typedef zlib_filefunc64_def_s zlib_filefunc64_def;
  31. #ifdef VCMI_DLL
  32. extern template struct DLL_LINKAGE boost::iostreams::stream<FileBuf>;
  33. #endif
  34. class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
  35. {
  36. public:
  37. FileStream() = default;
  38. explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
  39. : boost::iostreams::stream<FileBuf>(p, mode) {}
  40. static bool CreateFile(const boost::filesystem::path& filename);
  41. static zlib_filefunc64_def* GetMinizipFilefunc();
  42. };