Thrill  0.1
cat_block_source.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/data/cat_block_source.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_DATA_CAT_BLOCK_SOURCE_HEADER
13 #define THRILL_DATA_CAT_BLOCK_SOURCE_HEADER
14 
15 #include <thrill/data/block.hpp>
16 
17 #include <utility>
18 #include <vector>
19 
20 namespace thrill {
21 namespace data {
22 
23 //! \addtogroup data_layer
24 //! \{
25 
26 /*!
27  * CatBlockSource is a BlockSource which concatenates all Blocks available from
28  * a vector of BlockSources. They are concatenated in order: first all Blocks
29  * from source zero, then from source one, etc.
30  */
31 template <typename BlockSource>
33 {
34 public:
35  //! default constructor
36  CatBlockSource() = default;
37 
38  //! Construct a BlockSource which catenates many other BlockSources.
39  explicit CatBlockSource(std::vector<BlockSource>&& sources)
40  : sources_(std::move(sources)) { }
41 
42  //! non-copyable: delete copy-constructor
43  CatBlockSource(const CatBlockSource&) = delete;
44  //! non-copyable: delete assignment operator
45  CatBlockSource& operator = (const CatBlockSource&) = delete;
46  //! move-constructor: default
47  CatBlockSource(CatBlockSource&&) = default;
48  //! move-assignment operator: default
50 
51  //! Advance to next block of file, delivers current_ and end_ for
52  //! BlockReader. Returns false if the source is empty.
54  for ( ; current_ < sources_.size(); ++current_) {
55  PinnedBlock b = sources_[current_].NextBlock();
56  if (b.IsValid()) return b;
57  }
58  return PinnedBlock();
59  }
60 
61 private:
62  //! vector containing block sources
63  std::vector<BlockSource> sources_;
64 
65  //! current source, all sources < current_ are empty.
66  size_t current_ = 0;
67 };
68 
69 //! \}
70 
71 } // namespace data
72 } // namespace thrill
73 
74 #endif // !THRILL_DATA_CAT_BLOCK_SOURCE_HEADER
75 
76 /******************************************************************************/
CatBlockSource()=default
default constructor
STL namespace.
CatBlockSource is a BlockSource which concatenates all Blocks available from a vector of BlockSources...
std::vector< BlockSource > sources_
vector containing block sources
A pinned / pin-counted derivative of a Block.
Definition: block.hpp:157
CatBlockSource & operator=(const CatBlockSource &)=delete
non-copyable: delete assignment operator
CatBlockSource(std::vector< BlockSource > &&sources)
Construct a BlockSource which catenates many other BlockSources.
size_t current_
current source, all sources < current_ are empty.
bool IsValid() const
Return whether the enclosed ByteBlock is valid.
Definition: block.hpp:223