cauldron  0.0.0
 All Classes Namespaces Files Functions Variables Typedefs
facility.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 #include <vector>
5 #include <memory>
6 
7 
8 namespace cauldron {
9 template<typename Product>
10 using Converter = std::function<Product(Product)>;
11 
12 
13 template<typename Product>
14 class Facility {
15  public:
16  Facility() = default;
17 
18  Facility(std::initializer_list<Converter<Product>> converters) :
19  converters_(converters) {}
20 
21  explicit Facility(const std::vector<Converter<Product>> &converters) :
22  converters_(converters) {}
23 
24  Facility<Product> expand(const Converter<Product> &converter) const {
25  std::vector<Converter<Product>> converters(converters_);
26  converters.push_back(converter);
27  return Facility<Product>(converters);
28  }
29 
30  Product convert(Product product) const {
31  for (const auto &converter: converters_) {
32  product = converter(product);
33  }
34  return product;
35  }
36 
37  protected:
38  std::vector<Converter<Product>> converters_;
39 };
40 }
std::vector< Converter< Product > > converters_
Definition: facility.h:38
std::function< Product(Product)> Converter
Definition: facility.h:10
Facility< Product > expand(const Converter< Product > &converter) const
Definition: facility.h:24
Facility(std::initializer_list< Converter< Product >> converters)
Definition: facility.h:18
Facility(const std::vector< Converter< Product >> &converters)
Definition: facility.h:21
Product convert(Product product) const
Definition: facility.h:30
Definition: facility.h:14