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