5#ifndef GKO_PUBLIC_CORE_CONFIG_REGISTRY_HPP_
6#define GKO_PUBLIC_CORE_CONFIG_REGISTRY_HPP_
13#include <unordered_map>
16#include <ginkgo/core/base/exception_helpers.hpp>
17#include <ginkgo/core/base/lin_op.hpp>
18#include <ginkgo/core/base/types.hpp>
19#include <ginkgo/core/base/utils_helper.hpp>
20#include <ginkgo/core/config/property_tree.hpp>
21#include <ginkgo/core/stop/criterion.hpp>
32using configuration_map =
34 std::function<deferred_factory_parameter<gko::LinOpFactory>(
35 const pnode&,
const registry&, type_descriptor)>>;
41class registry_accessor;
49template <
typename T,
typename =
void>
53struct base_type<T,
std::enable_if_t<std::is_convertible<T*, LinOp*>::value>> {
59 T,
std::enable_if_t<std::is_convertible<T*, LinOpFactory*>::value>> {
60 using type = LinOpFactory;
66 std::enable_if_t<std::is_convertible<T*, stop::CriterionFactory*>::value>> {
84 template <
typename Type>
85 allowed_ptr(std::shared_ptr<Type> obj);
92 template <
typename Type>
93 bool contains()
const;
102 template <
typename Type>
103 std::shared_ptr<Type> get()
const;
106 struct generic_container {
107 virtual ~generic_container() =
default;
110 template <
typename Type>
111 struct concrete_container : generic_container {
112 concrete_container(std::shared_ptr<Type> obj) : ptr{obj}
115 std::is_same<Type, typename base_type<Type>::type>::value,
116 "The given type must be a base_type");
119 std::shared_ptr<Type> ptr;
122 std::shared_ptr<generic_container> data_;
126template <
typename Type>
127inline allowed_ptr::allowed_ptr(std::shared_ptr<Type> obj)
130 std::make_shared<concrete_container<typename base_type<Type>::type>>(
135template <
typename Type>
136inline bool allowed_ptr::contains()
const
138 return dynamic_cast<const concrete_container<Type>*
>(data_.get());
142template <
typename Type>
143inline std::shared_ptr<Type> allowed_ptr::get()
const
145 GKO_THROW_IF_INVALID(this->
template contains<Type>(),
146 "does not hold the requested type.");
147 return dynamic_cast<concrete_container<Type>*
>(data_.get())->ptr;
169 friend class detail::registry_accessor;
181 registry(
const configuration_map& additional_map = {});
196 const std::unordered_map<std::string, detail::allowed_ptr>& stored_map,
197 const configuration_map& additional_map = {});
207 template <
typename T>
208 bool emplace(std::string key, std::shared_ptr<T> data);
220 template <
typename T>
221 std::shared_ptr<T>
get_data(std::string key)
const;
229 std::unordered_map<std::string, detail::allowed_ptr> stored_map_;
230 configuration_map build_map_;
237 auto it = stored_map_.emplace(key, data);
245 return gko::as<T>(stored_map_.at(key)
246 .template get<
typename detail::base_type<T>::type>());
Definition registry.hpp:167
registry(const std::unordered_map< std::string, detail::allowed_ptr > &stored_map, const configuration_map &additional_map={})
std::shared_ptr< T > get_data(std::string key) const
Definition registry.hpp:243
registry(const configuration_map &additional_map={})
bool emplace(std::string key, std::shared_ptr< T > data)
Definition registry.hpp:235
const configuration_map & get_build_map() const
Definition registry.hpp:226
AbstractFactory< Criterion, CriterionArgs > CriterionFactory
Definition criterion.hpp:226
The Ginkgo namespace.
Definition abstract_factory.hpp:20