2
0

FileStream.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. /*
  3. * FileStream.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  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 class 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. };