Remove ostream from class StreamBuffer

This commit is contained in:
2023-10-18 14:22:35 -04:00
parent 67b0265092
commit 3e8aa31a95
5 changed files with 46 additions and 59 deletions

View File

@@ -335,38 +335,6 @@ util::HashValue StreamBuffer::hash() const {
return std::make_pair(hash1, hash2);
}
class StreamBufferWriter : public std::streambuf, public eng::opnew {
private:
StreamBuffer *target_;
public:
StreamBufferWriter(StreamBuffer *t) : target_(t) {}
virtual int_type overflow(int_type c) {
if (c != EOF) {
target_->write_uint8(c);
}
return c;
}
};
class StreamBufferOStream : public std::ostream, public eng::opnew {
private:
StreamBufferWriter writer_;
public:
StreamBufferOStream(StreamBuffer *t) : std::ostream(nullptr), writer_(t) {
rdbuf(&writer_);
}
virtual ~StreamBufferOStream() {
}
};
std::ostream &StreamBuffer::ostream() {
if (ostream_ == nullptr) {
ostream_.reset(new StreamBufferOStream(this));
}
return *ostream_;
}
int lua_writer_into_streambuffer(lua_State *L, const void* bytes, size_t sz, void* sbv) {
StreamBuffer *sb = (StreamBuffer *)sbv;
memcpy(sb->make_space(sz), bytes, sz);
@@ -508,11 +476,5 @@ LuaDefine(unittests_streambuffer, "", "some unit tests") {
eqsb1.write_int32(34);
LuaAssert(L, !eqsb1.contents_equal(&eqsb2));
// Check the OStream functionality.
StreamBuffer ossb;
ossb.ostream() << "Testing.";
ossb.ostream() << "Foo.";
LuaAssertStrEq(L, ossb.read_entire_contents(), "Testing.Foo.");
return 0;
}