ClickHouse/src/DataStreams/OwningBlockInputStream.h

36 lines
840 B
C++
Raw Normal View History

2016-11-17 01:09:46 +00:00
#pragma once
#include <memory>
#include <DataStreams/IBlockInputStream.h>
2016-11-17 01:09:46 +00:00
namespace DB
{
/** Provides reading from a Buffer, taking exclusive ownership over it's lifetime,
2017-05-25 19:26:17 +00:00
* simplifies usage of ReadBufferFromFile (no need to manage buffer lifetime) etc.
*/
2016-11-17 01:09:46 +00:00
template <typename OwnType>
class OwningBlockInputStream : public IBlockInputStream
2016-11-17 01:09:46 +00:00
{
public:
2019-08-03 11:02:40 +00:00
OwningBlockInputStream(const BlockInputStreamPtr & stream_, std::unique_ptr<OwnType> own_)
: stream{stream_}, own{std::move(own_)}
{
children.push_back(stream);
}
2016-11-17 01:09:46 +00:00
Block getHeader() const override { return children.at(0)->getHeader(); }
2016-11-17 01:09:46 +00:00
private:
Block readImpl() override { return stream->read(); }
2016-11-17 01:09:46 +00:00
String getName() const override { return "Owning"; }
2016-11-17 01:09:46 +00:00
protected:
BlockInputStreamPtr stream;
std::unique_ptr<OwnType> own;
2016-11-17 01:09:46 +00:00
};
}