FileStream.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifdef _MSC_VER
  35. #pragma warning (push)
  36. #pragma warning (disable : 4910)
  37. #endif
  38. extern template struct DLL_LINKAGE boost::iostreams::stream<VCMI_LIB_WRAP_NAMESPACE(FileBuf)>;
  39. #ifdef _MSC_VER
  40. #pragma warning (pop)
  41. #endif
  42. #endif
  43. VCMI_LIB_NAMESPACE_BEGIN
  44. class DLL_LINKAGE FileStream : public boost::iostreams::stream<FileBuf>
  45. {
  46. public:
  47. FileStream() = default;
  48. explicit FileStream(const boost::filesystem::path& p, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
  49. : boost::iostreams::stream<FileBuf>(p, mode) {}
  50. static bool CreateFile(const boost::filesystem::path& filename);
  51. static zlib_filefunc64_def* GetMinizipFilefunc();
  52. };
  53. VCMI_LIB_NAMESPACE_END