FactoryCreation.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <type_traits>
7 
8 #include "Utilities/TMPL.hpp"
9 
10 namespace Options::protocols {
11 /*!
12  * \brief Compile-time information for factory-creation
13  *
14  * A class conforming to this protocol is placed in the metavariables
15  * to provide information on the set of derived classes for each
16  * factory-creatable base class. The conforming class must provide
17  * the following type aliases:
18  *
19  * - `factory_classes`: A `tmpl::map` from the base class to the list
20  * of derived classes. List all derived classes that should be
21  * factory-creatable, e.g. through input-file options.
22  *
23  * Here's an example for a class conforming to this protocol:
24  *
25  * \snippet Test_Factory.cpp factory_creation
26  */
28  template <typename ConformingType>
29  struct test {
30  using factory_classes = typename ConformingType::factory_classes;
31 
32  template <typename BaseClass, typename DerivedClass>
34  static_assert(std::is_base_of_v<BaseClass, DerivedClass>,
35  "FactoryCreation protocol: The first template argument to "
36  "this struct is not a base class of the second.");
37  };
38 
39  using all_classes_are_derived_classes = tmpl::all<
40  factory_classes,
41  tmpl::bind<
42  tmpl::all, tmpl::bind<tmpl::back, tmpl::_1>,
44  tmpl::bind<tmpl::front, tmpl::parent<tmpl::_1>>, tmpl::_1>>>>;
45 
46  static_assert(all_classes_are_derived_classes::value);
47  };
48 };
49 } // namespace Options::protocols
std::true_type
Options::protocols::FactoryCreation::test
Definition: FactoryCreation.hpp:29
Options::protocols::FactoryCreation
Compile-time information for factory-creation.
Definition: FactoryCreation.hpp:27
Options::protocols::FactoryCreation::test::factory_class_is_derived_from_base_class
Definition: FactoryCreation.hpp:33
type_traits
TMPL.hpp