Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
polymorphic_object.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
6#define GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
7
8
9#include <memory>
10#include <type_traits>
11
12
13#include <ginkgo/config.hpp>
14
15
16#if GINKGO_BUILD_MPI
17
18
19#include <ginkgo/core/base/polymorphic_object.hpp>
20#include <ginkgo/core/distributed/base.hpp>
21
22
23namespace gko {
24namespace experimental {
25
26
52template <typename ConcreteObject, typename PolymorphicBase = PolymorphicObject>
54 : public EnableAbstractPolymorphicObject<ConcreteObject, PolymorphicBase> {
55protected:
57 ConcreteObject, PolymorphicBase>::EnableAbstractPolymorphicObject;
58
59 std::unique_ptr<PolymorphicObject> create_default_impl(
60 std::shared_ptr<const Executor> exec) const override
61 {
62 return std::unique_ptr<ConcreteObject>{
63 new ConcreteObject(exec, self()->get_communicator())};
64 }
65
66 PolymorphicObject* copy_from_impl(const PolymorphicObject* other) override
67 {
68 as<ConvertibleTo<ConcreteObject>>(other)->convert_to(self());
69 return this;
70 }
71
72 PolymorphicObject* copy_from_impl(
73 std::unique_ptr<PolymorphicObject> other) override
74 {
75 as<ConvertibleTo<ConcreteObject>>(other.get())->move_to(self());
76 return this;
77 }
78
79 PolymorphicObject* move_from_impl(PolymorphicObject* other) override
80 {
81 as<ConvertibleTo<ConcreteObject>>(other)->move_to(self());
82 return this;
83 }
84
85 PolymorphicObject* move_from_impl(
86 std::unique_ptr<PolymorphicObject> other) override
87 {
88 as<ConvertibleTo<ConcreteObject>>(other.get())->move_to(self());
89 return this;
90 }
91
92 PolymorphicObject* clear_impl() override
93 {
94 *self() =
95 ConcreteObject{self()->get_executor(), self()->get_communicator()};
96 return this;
97 }
98
99private:
100 GKO_ENABLE_SELF(ConcreteObject);
101};
102
103
104} // namespace experimental
105} // namespace gko
106
107
108#endif // GINKGO_BUILD_MPI
109#endif // GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:346
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition polymorphic_object.hpp:44
This mixin does the same as EnablePolymorphicObject, but for concrete types that are derived from dis...
Definition polymorphic_object.hpp:54
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::decay_t< T > * as(U *obj)
Performs polymorphic type conversion.
Definition utils_helper.hpp:309