cauldron  0.0.0
 All Classes Namespaces Files Functions Variables Typedefs
builder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "bases.h"
4 
5 
6 namespace cauldron {
17 template<class Object, class ...Value>
18 class Builder : public CloneHelper<Object, Builder<Object, Value...>> {
19  public:
23  explicit Builder(const cauldron::Strategy<Value> &... strategy) :
24  strategies_(std::make_tuple(strategy.clone()...)) {}
25 
32  strategies_(builder.clone_strategies()) {}
33 
37  Object operator()() const override {
38  auto strategies_count = std::tuple_size<decltype(strategies_)>{};
39  return produce(strategies_,
40  std::make_index_sequence<strategies_count>{});
41  }
42 
43  private:
44  std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...> strategies_;
45 
50  template<std::size_t... Indices>
51  Object produce(
52  const std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...> &strategies,
53  std::index_sequence<Indices...>
54  ) const {
55  return produce(std::get<Indices>(strategies)...);
56  }
57 
62  Object produce(
63  const std::unique_ptr<cauldron::Strategy<Value>> &... strategy
64  ) const {
65  return Object((*strategy)()...);
66  }
67 
68  std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...>
69  clone_strategies() const {
70  auto strategies_count = std::tuple_size<decltype(strategies_)>{};
71  return clone_strategies(strategies_,
72  std::make_index_sequence<strategies_count>{});
73  }
74 
79  template<std::size_t... Indices>
80  std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...>
81  clone_strategies(
82  const std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...> &strategies,
83  std::index_sequence<Indices...>
84  ) const {
85  return clone_strategies(std::get<Indices>(strategies)...);
86  }
87 
91  std::tuple<std::unique_ptr<cauldron::Strategy<Value>>...>
92  clone_strategies(
93  const std::unique_ptr<cauldron::Strategy<Value>> &... strategy
94  ) const {
95  return std::make_tuple(strategy->clone()...);
96  }
97 };
98 }
Definition: bases.h:32
Builder(const Builder< Object, Value...> &builder)
Definition: builder.h:31
Builder(const cauldron::Strategy< Value > &...strategy)
Definition: builder.h:23
Definition: bases.h:97
Object operator()() const override
Definition: builder.h:37
std::unique_ptr< Strategy< Object > > clone() const override
Definition: bases.h:99
Definition: builder.h:18