Class WriteBufferFromOwnString now can return StringRef too.

This commit is contained in:
Vitaly Baranov 2019-01-23 22:32:59 +03:00
parent b7ee466cd7
commit b1aba679d0
2 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <string>
#include <IO/WriteBufferFromVector.h>
#include <common/StringRef.h>
namespace DB
@ -29,6 +30,8 @@ class WriteBufferFromOwnString : public detail::StringHolder, public WriteBuffer
public:
WriteBufferFromOwnString() : WriteBufferFromString(value) {}
StringRef stringRef() const { return isFinished() ? StringRef(value) : StringRef(value.data(), pos - value.data()); }
std::string & str()
{
finish();

View File

@ -64,6 +64,14 @@ public:
set(nullptr, 0);
}
bool isFinished() const { return is_finished; }
void restart()
{
set(reinterpret_cast<Position>(vector.data()), vector.size());
is_finished = false;
}
~WriteBufferFromVector() override
{
if (!is_finished)