1#pragma once
2
3#include <DataStreams/IBlockInputStream.h>
4
5
6namespace DB
7{
8
9/** A stream of blocks from which you can read the next block from an explicitly provided list.
10 * Also see OneBlockInputStream.
11 */
12class BlocksListBlockInputStream : public IBlockInputStream
13{
14public:
15 /// Acquires the ownership of the block list.
16 BlocksListBlockInputStream(BlocksList && list_)
17 : list(std::move(list_)), it(list.begin()), end(list.end()) {}
18
19 /// Uses a list of blocks lying somewhere else.
20 BlocksListBlockInputStream(BlocksList::iterator & begin_, BlocksList::iterator & end_)
21 : it(begin_), end(end_) {}
22
23 String getName() const override { return "BlocksList"; }
24
25protected:
26 Block getHeader() const override { return list.empty() ? Block() : *list.begin(); }
27
28 Block readImpl() override
29 {
30 if (it == end)
31 return Block();
32
33 Block res = *it;
34 ++it;
35 return res;
36 }
37
38private:
39 BlocksList list;
40 BlocksList::iterator it;
41 const BlocksList::iterator end;
42};
43
44}
45