WriteBufferFromString.h 864 字节
Newer Older
A
Alexey Milovidov 已提交
1 2
#pragma once

3
#include <string>
4
#include <IO/WriteBufferFromVector.h>
5
#include <common/StringRef.h>
A
Alexey Milovidov 已提交
6

7

A
Alexey Milovidov 已提交
8 9 10
namespace DB
{

F
f1yegor 已提交
11 12
/** Writes the data to a string.
  * Note: before using the resulting string, destroy this object.
A
Alexey Milovidov 已提交
13
  */
14
using WriteBufferFromString = WriteBufferFromVector<std::string>;
A
Alexey Milovidov 已提交
15

16

17 18 19 20 21 22 23 24 25
namespace detail
{
    /// For correct order of initialization.
    class StringHolder
    {
    protected:
        std::string value;
    };
}
P
proller 已提交
26

27
/// Creates the string by itself and allows to get it.
28
class WriteBufferFromOwnString : public detail::StringHolder, public WriteBufferFromString
29 30
{
public:
31
    WriteBufferFromOwnString() : WriteBufferFromString(value) {}
32

33 34
    StringRef stringRef() const { return isFinished() ? StringRef(value) : StringRef(value.data(), pos - value.data()); }

35 36
    std::string & str()
    {
A
Alexander Burmak 已提交
37
        finalize();
38
        return value;
39 40 41
    }
};

A
Alexey Milovidov 已提交
42
}