Wayverb
iterative_builder.h
1 #pragma once
2 
3 #include "utilities/aligned/vector.h"
4 
5 #include <experimental/optional>
6 
7 namespace wayverb {
8 namespace raytracer {
9 
10 template <typename T>
11 class iterative_builder final {
12 public:
13  iterative_builder(size_t items)
14  : data_{items} {}
15 
16  template <typename It, typename Func>
17  void push(It b, It e, const Func& func) {
18  const auto input_size = std::distance(b, e);
19  const auto num_items = get_num_items();
20  if (input_size != num_items) {
21  throw std::runtime_error{
22  "Incorrect range size passed to iterative_builder."};
23  }
24 
25  for (auto i = 0ul; i != num_items; ++i) {
26  push_item(i, func(b[i]));
27  }
28  }
29 
30  template <typename It>
31  void push(It b, It e) {
32  push(b, e, [](const auto& i) -> const auto& { return i; });
33  }
34 
35  const auto& get_data() const { return data_; }
36  auto& get_data() { return data_; }
37 
38  auto get_num_items() const { return data_.size(); }
39 
40 private:
41  void push_item(size_t index, T item) {
42  data_[index].emplace_back(std::move(item));
43  }
44  void push_item(size_t index, const std::experimental::optional<T>& item) {
45  if (item) {
46  push_item(index, *item);
47  }
48  }
49 
50  util::aligned::vector<util::aligned::vector<T>> data_;
51 };
52 
53 } // namespace raytracer
54 } // namespace wayverb
Definition: iterative_builder.h:11
Definition: pressure.h:22
Definition: capsule_base.h:9