33 #ifndef GKO_CORE_BASE_ABSTRACT_FACTORY_HPP_ 34 #define GKO_CORE_BASE_ABSTRACT_FACTORY_HPP_ 37 #include <ginkgo/core/base/polymorphic_object.hpp> 69 template <
typename AbstractProductType,
typename ComponentsType>
72 AbstractFactory<AbstractProductType, ComponentsType>> {
74 using abstract_product_type = AbstractProductType;
75 using components_type = ComponentsType;
91 template <
typename... Args>
92 std::unique_ptr<AbstractProductType>
generate(Args &&... args)
const 94 auto product = this->generate_impl({std::forward<Args>(args)...});
95 for (
auto logger : this->loggers_) {
96 product->add_logger(logger);
118 virtual std::unique_ptr<AbstractProductType> generate_impl(
119 ComponentsType args)
const = 0;
146 template <
typename ConcreteFactory,
typename ProductType,
147 typename ParametersType,
typename PolymorphicBase>
154 using product_type = ProductType;
155 using parameters_type = ParametersType;
156 using polymorphic_base = PolymorphicBase;
157 using abstract_product_type =
158 typename PolymorphicBase::abstract_product_type;
159 using components_type =
typename PolymorphicBase::components_type;
161 template <
typename... Args>
162 std::unique_ptr<ProductType>
generate(Args &&... args)
const 164 auto product = std::unique_ptr<ProductType>(
static_cast<ProductType *
>(
165 this->generate_impl({std::forward<Args>(args)...}).release()));
166 propagate_loggers<ConcreteFactory, ProductType>(product.get());
192 static parameters_type
create() {
return {}; }
202 template <
typename TheFactory,
typename TheType>
203 typename std::enable_if<
204 std::is_base_of<log::Loggable, TheType>::value &&
205 std::is_base_of<log::Loggable, TheFactory>::value,
207 propagate_loggers(TheType *product)
const 209 for (
auto logger : this->loggers_) {
210 product->add_logger(logger);
221 template <
typename TheFactory,
typename TheType>
222 typename std::enable_if<
223 not std::is_base_of<log::Loggable, TheType>::value ||
224 not std::is_base_of<log::Loggable, TheFactory>::value,
226 propagate_loggers(TheType *product)
const 236 const parameters_type ¶meters = {})
239 parameters_{parameters}
242 std::unique_ptr<abstract_product_type> generate_impl(
243 components_type args)
const override 245 return std::unique_ptr<abstract_product_type>(
246 new ProductType(
self(), args));
250 GKO_ENABLE_SELF(ConcreteFactory);
252 ParametersType parameters_;
268 template <
typename ConcreteParametersType,
typename Factory>
270 using factory = Factory;
279 std::unique_ptr<Factory>
on(std::shared_ptr<const Executor> exec)
const 281 return std::unique_ptr<Factory>(
new Factory(exec, *
self()));
285 GKO_ENABLE_SELF(ConcreteParametersType);
292 #endif // GKO_CORE_BASE_ABSTRACT_FACTORY_HPP_ This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:285
std::unique_ptr< Factory > on(std::shared_ptr< const Executor > exec) const
Creates a new factory on the specified executor.
Definition: abstract_factory.hpp:279
std::unique_ptr< AbstractProductType > generate(Args &&... args) const
Creates a new product from the given components.
Definition: abstract_factory.hpp:92
const parameters_type & get_parameters() const noexcept
Returns the parameters of the factory.
Definition: abstract_factory.hpp:175
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:505
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:148
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:269
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition: abstract_factory.hpp:70
static parameters_type create()
Creates a new ParametersType object which can be used to instantiate a new ConcreteFactory.
Definition: abstract_factory.hpp:192
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition: polymorphic_object.hpp:554