2017-02-22 15:29:43 +00:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2017-02-22 15:29:43 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct IReadableWriteBuffer
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// At the first time returns getReadBufferImpl(). Next calls return nullptr.
|
|
|
|
inline std::shared_ptr<ReadBuffer> tryGetReadBuffer()
|
|
|
|
{
|
|
|
|
if (!can_reread)
|
|
|
|
return nullptr;
|
2017-02-28 14:15:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
can_reread = false;
|
|
|
|
return getReadBufferImpl();
|
|
|
|
}
|
2017-02-28 14:15:13 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual ~IReadableWriteBuffer() {}
|
2017-02-28 14:15:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Creates read buffer from current write buffer.
|
|
|
|
/// Returned buffer points to the first byte of original buffer.
|
|
|
|
/// Original stream becomes invalid.
|
|
|
|
virtual std::shared_ptr<ReadBuffer> getReadBufferImpl() = 0;
|
2017-02-22 15:29:43 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool can_reread = true;
|
2017-02-22 15:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|