ClickHouse/dbms/IO/WriteBufferFromString.h

43 lines
864 B
C++
Raw Normal View History

2011-11-01 17:57:37 +00:00
#pragma once
#include <string>
#include <IO/WriteBufferFromVector.h>
#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
*/
using WriteBufferFromString = WriteBufferFromVector<std::string>;
2011-11-01 17:57:37 +00:00
2017-07-31 21:39:24 +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.
class WriteBufferFromOwnString : public detail::StringHolder, public WriteBufferFromString
2017-07-31 21:39:24 +00:00
{
public:
WriteBufferFromOwnString() : WriteBufferFromString(value) {}
2017-07-31 21:39:24 +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();
return value;
2017-07-31 21:39:24 +00:00
}
};
2011-11-01 17:57:37 +00:00
}