33#include < istream>
44#include < memory>
55#include < ostream>
6+ #include < span>
67#include < vector>
78
89#include " satisfactorysave_export.h"
910
1011namespace SatisfactorySave {
1112
1213 class SATISFACTORYSAVE_API MemIStreambuf : public std::streambuf {
13- private:
14- std::unique_ptr<std::vector<char >> buf_;
15-
1614 public:
17- explicit MemIStreambuf (std::unique_ptr<std::vector<char >> buf) : buf_(std::move(buf)) {
18- setg (buf_->data (), buf_->data (), buf_->data () + buf_->size ());
15+ explicit MemIStreambuf (std::span<const char > buf) {
16+ setg (const_cast <char *>(buf.data ()), const_cast <char *>(buf.data ()),
17+ const_cast <char *>(buf.data () + buf.size ()));
1918 }
2019
2120 protected:
@@ -39,22 +38,35 @@ namespace SatisfactorySave {
3938
4039 class SATISFACTORYSAVE_API MemIStream : public std::istream {
4140 private:
41+ std::unique_ptr<std::vector<char >> data_buf_;
4242 MemIStreambuf memstreambuf_;
4343
4444 public:
45- explicit MemIStream (std::unique_ptr<std:: vector<char >> buf)
45+ explicit MemIStream (std::vector<char >&& buf)
4646 : std::istream(nullptr ),
47- memstreambuf_(std::move(buf)) {
47+ data_buf_(std::make_unique<std::vector<char >>(std::move(buf))),
48+ memstreambuf_(*data_buf_) {
4849 init (&memstreambuf_);
4950 }
51+
52+ explicit MemIStream (std::span<const char > buf) : std::istream(nullptr ), memstreambuf_(buf) {
53+ init (&memstreambuf_);
54+ }
55+
56+ ~MemIStream () override = default ;
57+ MemIStream (const MemIStream&) = delete ;
58+ MemIStream& operator =(const MemIStream&) = delete ;
59+ MemIStream (MemIStream&&) = delete ;
60+ MemIStream& operator =(MemIStream&&) = delete ;
5061 };
5162
5263 class SATISFACTORYSAVE_API MemOStreambuf : public std::streambuf {
5364 private:
5465 std::unique_ptr<std::vector<char >> buf_;
5566
5667 public:
57- explicit MemOStreambuf (std::unique_ptr<std::vector<char >> buf) : buf_(std::move(buf)) {
68+ explicit MemOStreambuf () {
69+ buf_ = std::make_unique<std::vector<char >>();
5870 setp (buf_->data (), buf_->data () + buf_->size ());
5971 }
6072
@@ -102,7 +114,7 @@ namespace SatisfactorySave {
102114 MemOStreambuf memstreambuf_;
103115
104116 public:
105- MemOStream () : std::ostream(nullptr ), memstreambuf_(std::make_unique<std::vector< char >>()) {
117+ MemOStream () : std::ostream(nullptr ) {
106118 init (&memstreambuf_);
107119 }
108120
0 commit comments