FactoryHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "Utilities/TMPL.hpp"
7 
8 namespace Options {
9 namespace detail {
10 template <typename FactoryClasses, typename... NewClasses>
11 struct add_factory_classes;
12 
13 template <typename FactoryClasses, typename BaseClass, typename NewClasses,
14  typename... RestNewClasses>
15 struct add_factory_classes<FactoryClasses, tmpl::pair<BaseClass, NewClasses>,
16  RestNewClasses...>
18  tmpl::insert<
19  tmpl::erase<FactoryClasses, BaseClass>,
20  tmpl::pair<
21  BaseClass,
22  tmpl::append<
23  tmpl::conditional_t<
24  tmpl::has_key<FactoryClasses, BaseClass>::value,
25  tmpl::at<FactoryClasses, BaseClass>, tmpl::list<>>,
26  NewClasses>>>,
27  RestNewClasses...> {};
28 
29 template <typename FactoryClasses>
30 struct add_factory_classes<FactoryClasses> {
31  using type = FactoryClasses;
32 };
33 } // namespace detail
34 
35 /// Add new factory-creatable classes to the list in a
36 /// `factory_creation` struct.
37 ///
38 /// For each `tmpl::pair<Base, DerivedList>` in the `NewClasses`
39 /// parameter pack, append the classes in `DerivedList` to the list
40 /// for `Base` in `FactoryClasses`. The `FactoryClasses` map need not
41 /// have a preexisting entry for `Base`.
42 ///
43 /// This example adds three new derived classes, two for one base
44 /// class and one for another.
45 ///
46 /// \snippet Test_FactoryHelpers.cpp add_factory_classes
47 ///
48 /// \see Options::protocols::FactoryCreation
49 template <typename FactoryClasses, typename... NewClasses>
50 using add_factory_classes =
51  typename detail::add_factory_classes<FactoryClasses, NewClasses...>::type;
52 } // namespace Options
Options
Utilities for parsing input files.
Definition: MinmodType.hpp:8
Options::add_factory_classes
typename detail::add_factory_classes< FactoryClasses, NewClasses... >::type add_factory_classes
Add new factory-creatable classes to the list in a factory_creation struct.
Definition: FactoryHelpers.hpp:51
TMPL.hpp