2
0

FileStream.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. VCMI_LIB_NAMESPACE_BEGIN
  14. class DLL_LINKAGE FileBuf
  15. {
  16. public:
  17. typedef char char_type;
  18. typedef struct category_ :
  19. boost::iostreams::seekable_device_tag,
  20. boost::iostreams::closable_tag
  21. {} category;
  22. FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode);
  23. std::streamsize read(char* s, std::streamsize n);
  24. std::streamsize write(const char* s, std::streamsize n);
  25. std::streamoff seek(std::streamoff off, std::ios_base::seekdir way);
  26. void close();
  27. private:
  28. void* filePtr;
  29. };
  30. VCMI_LIB_NAMESPACE_END
  31. struct zlib_filefunc64_def_s;
  32. typedef zlib_filefunc64_def_s zlib_filefunc64_def;
  33. #ifdef VCMI_DLL
  34. extern template struct DLL_LINKAGE boost::iostreams::stream<VCMI_LIB_WRAP_NAMESPACE(FileBuf)>;
  35. #endif
  36. VCMI_LIB_NAMESPACE_BEGIN
  37. class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
  38. {
  39. public:
  40. FileStream() = default;
  41. explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
  42. : boost::iostreams::stream<FileBuf>(p, mode) {}
  43. static bool CreateFile(const boost::filesystem::path& filename);
  44. static zlib_filefunc64_def* GetMinizipFilefunc();
  45. };
  46. VCMI_LIB_NAMESPACE_END