Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/zstr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@
#include <zlib.h>
#include <memory>
#include <iostream>

#include "strict_fstream.hpp"

#if defined(__GNUC__) && !defined(__clang__)
#if (__GNUC__ > 5) || (__GNUC__ == 5 && __GNUC_MINOR__>0)
#define CAN_MOVE_IOSTREAM
#endif
#else
#define CAN_MOVE_IOSTREAM
#endif

namespace zstr
{

Expand Down Expand Up @@ -424,10 +431,12 @@ class ifstream
void close() {
_fs.close();
}
#ifdef CAN_MOVE_IOSTREAM
void open(const std::string filename, std::ios_base::openmode mode = std::ios_base::in) {
_fs.open(filename, mode);
std::istream::operator=(std::istream(new istreambuf(_fs.rdbuf())));
}
#endif
bool is_open() const {
return _fs.is_open();
}
Expand Down Expand Up @@ -461,11 +470,13 @@ class ofstream
std::ostream::flush();
_fs.close();
}
#ifdef CAN_MOVE_IOSTREAM
void open(const std::string filename, std::ios_base::openmode mode = std::ios_base::out, int level = Z_DEFAULT_COMPRESSION) {
flush();
_fs.open(filename, mode | std::ios_base::binary);
std::ostream::operator=(std::ostream(new ostreambuf(_fs.rdbuf(), default_buff_size, level)));
}
#endif
bool is_open() const {
return _fs.is_open();
}
Expand All @@ -488,4 +499,3 @@ class ofstream
}; // class ofstream

} // namespace zstr