Line data Source code
1 0 : // 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 0 : 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 Options/Test_Factory.cpp factory_creation
26 : */
27 1 : struct FactoryCreation {
28 : template <typename ConformingType>
29 0 : struct test {
30 0 : using factory_classes = typename ConformingType::factory_classes;
31 :
32 : template <typename BaseClass, typename DerivedClass>
33 0 : struct factory_class_is_derived_from_base_class : std::true_type {
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 0 : using all_classes_are_derived_classes = tmpl::all<
40 : factory_classes,
41 : tmpl::bind<
42 : tmpl::all, tmpl::bind<tmpl::back, tmpl::_1>,
43 : tmpl::defer<factory_class_is_derived_from_base_class<
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
|