2011-11-01 17:57:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-08-19 01:54:23 +00:00
|
|
|
#include <string>
|
2018-11-30 15:36:41 +00:00
|
|
|
#include <IO/WriteBufferFromVector.h>
|
2019-01-23 19:32:59 +00:00
|
|
|
#include <common/StringRef.h>
|
2011-11-01 17:57:37 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
|
2011-11-01 17:57:37 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/** Writes the data to a string.
|
|
|
|
* Note: before using the resulting string, destroy this object.
|
2011-11-01 17:57:37 +00:00
|
|
|
*/
|
2018-11-30 15:36:41 +00:00
|
|
|
using WriteBufferFromString = WriteBufferFromVector<std::string>;
|
2011-11-01 17:57:37 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
|
2017-08-01 14:33:38 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
/// For correct order of initialization.
|
|
|
|
class StringHolder
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
}
|
2017-08-01 13:31:38 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
/// Creates the string by itself and allows to get it.
|
2017-08-01 14:33:38 +00:00
|
|
|
class WriteBufferFromOwnString : public detail::StringHolder, public WriteBufferFromString
|
2017-07-31 21:39:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-08-01 14:33:38 +00:00
|
|
|
WriteBufferFromOwnString() : WriteBufferFromString(value) {}
|
2017-07-31 21:39:24 +00:00
|
|
|
|
2019-01-23 19:32:59 +00:00
|
|
|
StringRef stringRef() const { return isFinished() ? StringRef(value) : StringRef(value.data(), pos - value.data()); }
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
std::string & str()
|
|
|
|
{
|
2020-01-10 21:42:26 +00:00
|
|
|
finalize();
|
2017-08-01 14:33:38 +00:00
|
|
|
return value;
|
2017-07-31 21:39:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-01 17:57:37 +00:00
|
|
|
}
|