mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-02 12:32:04 +00:00
43 lines
864 B
C++
43 lines
864 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <IO/WriteBufferFromVector.h>
|
|
#include <common/StringRef.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/** Writes the data to a string.
|
|
* Note: before using the resulting string, destroy this object.
|
|
*/
|
|
using WriteBufferFromString = WriteBufferFromVector<std::string>;
|
|
|
|
|
|
namespace detail
|
|
{
|
|
/// For correct order of initialization.
|
|
class StringHolder
|
|
{
|
|
protected:
|
|
std::string value;
|
|
};
|
|
}
|
|
|
|
/// Creates the string by itself and allows to get it.
|
|
class WriteBufferFromOwnString : public detail::StringHolder, public WriteBufferFromString
|
|
{
|
|
public:
|
|
WriteBufferFromOwnString() : WriteBufferFromString(value) {}
|
|
|
|
StringRef stringRef() const { return isFinished() ? StringRef(value) : StringRef(value.data(), pos - value.data()); }
|
|
|
|
std::string & str()
|
|
{
|
|
finalize();
|
|
return value;
|
|
}
|
|
};
|
|
|
|
}
|