| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <memory> |
| 4 | |
| 5 | #include <DataStreams/IBlockInputStream.h> |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | /** Provides reading from a Buffer, taking exclusive ownership over it's lifetime, |
| 11 | * simplifies usage of ReadBufferFromFile (no need to manage buffer lifetime) etc. |
| 12 | */ |
| 13 | template <typename OwnType> |
| 14 | class OwningBlockInputStream : public IBlockInputStream |
| 15 | { |
| 16 | public: |
| 17 | OwningBlockInputStream(const BlockInputStreamPtr & stream_, std::unique_ptr<OwnType> own_) |
| 18 | : stream{stream_}, own{std::move(own_)} |
| 19 | { |
| 20 | children.push_back(stream); |
| 21 | } |
| 22 | |
| 23 | Block getHeader() const override { return children.at(0)->getHeader(); } |
| 24 | |
| 25 | private: |
| 26 | Block readImpl() override { return stream->read(); } |
| 27 | |
| 28 | String getName() const override { return "Owning"; } |
| 29 | |
| 30 | protected: |
| 31 | BlockInputStreamPtr stream; |
| 32 | std::unique_ptr<OwnType> own; |
| 33 | }; |
| 34 | |
| 35 | } |
| 36 |