OMCompiler/SimulationRuntime/cpp/Core/Utils/extension/factory.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Boost.Extension / factory: | ||
| 3 | * factory to register the implementations and create them | ||
| 4 | * | ||
| 5 | * (C) Copyright Jeremy Pack 2008 | ||
| 6 | * Distributed under the Boost Software License, Version 1.0. (See | ||
| 7 | * accompanying file LICENSE_1_0.txt or copy at | ||
| 8 | * http://www.boost.org/LICENSE_1_0.txt) | ||
| 9 | * | ||
| 10 | * See http://www.boost.org/ for latest version. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef BOOST_EXTENSION_FACTORY_HPP | ||
| 14 | #define BOOST_EXTENSION_FACTORY_HPP | ||
| 15 | |||
| 16 | #include <Core/Utils/extension/common.hpp> | ||
| 17 | #include <Core/Utils/extension/impl/create.hpp> | ||
| 18 | #include <type_traits> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace extensions { | ||
| 22 | |||
| 23 | /** Function object returning new instances of T, built from Params. */ | ||
| 24 | template <class T, class... Params> | ||
| 25 | class factory { | ||
| 26 | public: | ||
| 27 | static_assert(std::is_class<T>::value, "factory<T>: T must be a class"); | ||
| 28 | static_assert(!std::is_const<T>::value, "factory<T>: T must not be const"); | ||
| 29 | |||
| 30 | /** Set the factory function to the constructor of D. */ | ||
| 31 | template <class D> | ||
| 32 | void set() { | ||
| 33 | static_assert(std::is_base_of<T, D>::value, | ||
| 34 | "factory<T>::set<D>(): D must inherit from T"); | ||
| 35 | static_assert(!std::is_const<D>::value, | ||
| 36 | "factory<T>::set<D>(): D must not be const"); | ||
| 37 |
6/10✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 378 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 80 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 80 times.
|
1156 | this->func = &impl::create_function<T, D, Params...>::create; |
| 38 | } | ||
| 39 | |||
| 40 | 946 | factory() : func(0) {} | |
| 41 | |||
| 42 | bool is_valid() const { return this->func != 0; } | ||
| 43 | |||
| 44 | 278 | T* create(Params... p) const { | |
| 45 |
25/57<unknown function 44>:
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 50 times.
✓ Branch 5 taken 68 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 68 times.
<unknown function 45>:
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
boost::extensions::factory<IAlgLoopSolverFactory, IGlobalSettings*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::create(IGlobalSettings*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) const:
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 38 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 40 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 40 times.
✗ Branch 27 not taken.
boost::extensions::factory<ISettingsFactory, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) const:
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 40 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 40 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 40 times.
boost::extensions::factory<ISimController, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) const:
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
1312 | return this->func ? this->func(p...) : 0; |
| 46 | } | ||
| 47 | |||
| 48 | private: | ||
| 49 | typedef T* (*func_ptr_type)(Params...); | ||
| 50 | func_ptr_type func; | ||
| 51 | }; | ||
| 52 | |||
| 53 | } // namespace extensions | ||
| 54 | } // namespace boost | ||
| 55 | |||
| 56 | #endif // BOOST_EXTENSION_FACTORY_HPP | ||
| 57 |