1/* Copyright (c) 2018 BlackBerry Limited
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6http://www.apache.org/licenses/LICENSE-2.0
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License. */
12#pragma once
13
14#include <DataStreams/IBlockInputStream.h>
15
16
17namespace DB
18{
19
20/** A stream of blocks from a shared vector of blocks
21 */
22class BlocksBlockInputStream : public IBlockInputStream
23{
24public:
25 /// Acquires shared ownership of the blocks vector
26 BlocksBlockInputStream(const std::shared_ptr<BlocksPtr> & blocks_ptr_, Block header_)
27 : blocks(*blocks_ptr_), it((*blocks_ptr_)->begin()), end((*blocks_ptr_)->end()), header(std::move(header_)) {}
28
29 String getName() const override { return "Blocks"; }
30
31 Block getHeader() const override { return header; }
32
33protected:
34 Block readImpl() override
35 {
36 if (it == end)
37 return Block();
38
39 Block res = *it;
40 ++it;
41 return res;
42 }
43
44private:
45 BlocksPtr blocks;
46 Blocks::iterator it;
47 const Blocks::iterator end;
48 Block header;
49};
50
51}
52