ClickHouse/dbms/include/DB/Dictionaries/OwningBlockInputStream.h

35 lines
846 B
C++
Raw Normal View History

2016-11-17 01:09:46 +00:00
#pragma once
#include <memory>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
namespace DB
{
/** Provides reading from a Buffer, taking exclusive ownership over it's lifetime,
* 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 IProfilingBlockInputStream
{
public:
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
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
String getID() const override { return "Owning(" + stream->getID() + ")"; }
2016-11-17 01:09:46 +00:00
BlockInputStreamPtr stream;
std::unique_ptr<OwnType> own;
2016-11-17 01:09:46 +00:00
};
}