\doxysection{registry.\+hpp}
\hypertarget{registry_8hpp_source}{}\label{registry_8hpp_source}\index{ginkgo/core/config/registry.hpp@{ginkgo/core/config/registry.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ SPDX-\/FileCopyrightText:\ 2017\ -\/\ 2024\ The\ Ginkgo\ authors}}
\DoxyCodeLine{00002\ \textcolor{comment}{//}}
\DoxyCodeLine{00003\ \textcolor{comment}{//\ SPDX-\/License-\/Identifier:\ BSD-\/3-\/Clause}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#ifndef\ GKO\_PUBLIC\_CORE\_CONFIG\_REGISTRY\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_CONFIG\_REGISTRY\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <complex>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <functional>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <map>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <unordered\_map>}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#include\ <utility>}}
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/exception\_helpers.hpp>}}
\DoxyCodeLine{00017\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/lin\_op.hpp>}}
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/types.hpp>}}
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/utils\_helper.hpp>}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#include\ <ginkgo/core/config/property\_tree.hpp>}}
\DoxyCodeLine{00021\ \textcolor{preprocessor}{\#include\ <ginkgo/core/stop/criterion.hpp>}}
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00025\ \textcolor{keyword}{namespace\ }config\ \{}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1config_1_1registry}{registry}};}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1config_1_1type__descriptor}{type\_descriptor}};}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \textcolor{keyword}{using\ }configuration\_map\ =}
\DoxyCodeLine{00033\ \ \ \ \ std::map<std::string,}
\DoxyCodeLine{00034\ \ \ \ \ \ \ \ \ \ \ \ \ \ std::function<deferred\_factory\_parameter<gko::LinOpFactory>(}
\DoxyCodeLine{00035\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1config_1_1pnode}{pnode}}\&,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1config_1_1registry}{registry}}\&,\ \doxymbox{\hyperlink{classgko_1_1config_1_1type__descriptor}{type\_descriptor}})>>;}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{namespace\ }detail\ \{}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00041\ \textcolor{keyword}{class\ }registry\_accessor;}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00049\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,\ \textcolor{keyword}{typename}\ =\ \textcolor{keywordtype}{void}>}
\DoxyCodeLine{00050\ \textcolor{keyword}{struct\ }base\_type\ \{\};}
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00053\ \textcolor{keyword}{struct\ }base\_type<T,\ std::enable\_if\_t<std::is\_convertible<T*,\ LinOp*>::value>>\ \{}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ LinOp;}
\DoxyCodeLine{00055\ \};}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00058\ \textcolor{keyword}{struct\ }base\_type<}
\DoxyCodeLine{00059\ \ \ \ \ T,\ std::enable\_if\_t<std::is\_convertible<T*,\ LinOpFactory*>::value>>\ \{}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ LinOpFactory;}
\DoxyCodeLine{00061\ \};}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00064\ \textcolor{keyword}{struct\ }base\_type<}
\DoxyCodeLine{00065\ \ \ \ \ T,}
\DoxyCodeLine{00066\ \ \ \ \ std::enable\_if\_t<std::is\_convertible<T*,\ stop::CriterionFactory*>::value>>\ \{}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ \doxymbox{\hyperlink{namespacegko_1_1stop_a61839f234ddbaaf68db337e58e012499}{stop::CriterionFactory}};}
\DoxyCodeLine{00068\ \};}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00075\ \textcolor{keyword}{class\ }allowed\_ptr\ \{}
\DoxyCodeLine{00076\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00084\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00085\ \ \ \ \ allowed\_ptr(std::shared\_ptr<Type>\ obj);}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{bool}\ contains()\ \textcolor{keyword}{const};}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00103\ \ \ \ \ std::shared\_ptr<Type>\ get()\ \textcolor{keyword}{const};}
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00105\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00106\ \ \ \ \ \textcolor{keyword}{struct\ }generic\_container\ \{}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \textcolor{keyword}{virtual}\ \string~generic\_container()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00108\ \ \ \ \ \};}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keyword}{struct\ }concrete\_container\ :\ generic\_container\ \{}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ concrete\_container(std::shared\_ptr<Type>\ obj)\ :\ ptr\{obj\}}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{static\_assert}(}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same<Type,\ typename\ base\_type<Type>::type>::value,}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}The\ given\ type\ must\ be\ a\ base\_type"{}});}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ std::shared\_ptr<Type>\ ptr;}
\DoxyCodeLine{00120\ \ \ \ \ \};}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ \ \ \ \ std::shared\_ptr<generic\_container>\ data\_;}
\DoxyCodeLine{00123\ \};}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00127\ \textcolor{keyword}{inline}\ allowed\_ptr::allowed\_ptr(std::shared\_ptr<Type>\ obj)}
\DoxyCodeLine{00128\ \{}
\DoxyCodeLine{00129\ \ \ \ \ data\_\ =}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ std::make\_shared<concrete\_container<typename\ base\_type<Type>::type>>(}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \ \ \ \ obj);}
\DoxyCodeLine{00132\ \}}
\DoxyCodeLine{00133\ }
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00136\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{bool}\ allowed\_ptr::contains()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00137\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{dynamic\_cast<}\textcolor{keyword}{const\ }concrete\_container<Type>*\textcolor{keyword}{>}(data\_.get());}
\DoxyCodeLine{00139\ \}}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ }
\DoxyCodeLine{00142\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Type>}
\DoxyCodeLine{00143\ \textcolor{keyword}{inline}\ std::shared\_ptr<Type>\ allowed\_ptr::get()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00144\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00145\ \ \ \ \ GKO\_THROW\_IF\_INVALID(this-\/>\textcolor{keyword}{template}\ contains<Type>(),}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}does\ not\ hold\ the\ requested\ type."{}});}
\DoxyCodeLine{00147\ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{dynamic\_cast<}concrete\_container<Type>*\textcolor{keyword}{>}(data\_.get())-\/>ptr;}
\DoxyCodeLine{00148\ \}}
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ \}\ \ \textcolor{comment}{//\ namespace\ detail}}
\DoxyCodeLine{00152\ }
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00167\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1config_1_1registry_a7654f0aa74acafe25e75f5d4361ed1a7}{registry}}\ final\ \{}
\DoxyCodeLine{00168\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00169\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }detail::registry\_accessor;}
\DoxyCodeLine{00170\ }
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00181\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1config_1_1registry_a7654f0aa74acafe25e75f5d4361ed1a7}{registry}}(\textcolor{keyword}{const}\ configuration\_map\&\ additional\_map\ =\ \{\});}
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00195\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1config_1_1registry_a0177e182b5c819d025012d9b267404da}{registry}}(}
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::unordered\_map<std::string,\ detail::allowed\_ptr>\&\ stored\_map,}
\DoxyCodeLine{00197\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ configuration\_map\&\ additional\_map\ =\ \{\});}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00207\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00208\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classgko_1_1config_1_1registry_ab22c49993b94f307f29a85bb663fff47}{emplace}}(std::string\ key,\ std::shared\_ptr<T>\ data);}
\DoxyCodeLine{00209\ }
\DoxyCodeLine{00210\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00220\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00221\ \ \ \ \ std::shared\_ptr<T>\ get\_data(std::string\ key)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00222\ }
\DoxyCodeLine{00226\ \ \ \ \ \textcolor{keyword}{const}\ configuration\_map\&\ get\_build\_map()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ build\_map\_;\ \}}
\DoxyCodeLine{00227\ }
\DoxyCodeLine{00228\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00229\ \ \ \ \ std::unordered\_map<std::string,\ detail::allowed\_ptr>\ stored\_map\_;}
\DoxyCodeLine{00230\ \ \ \ \ configuration\_map\ build\_map\_;}
\DoxyCodeLine{00231\ \};}
\DoxyCodeLine{00232\ }
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00235\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classgko_1_1config_1_1registry_ab22c49993b94f307f29a85bb663fff47}{registry::emplace}}(std::string\ key,\ std::shared\_ptr<T>\ data)}
\DoxyCodeLine{00236\ \{}
\DoxyCodeLine{00237\ \ \ \ \ \textcolor{keyword}{auto}\ it\ =\ stored\_map\_.emplace(key,\ data);}
\DoxyCodeLine{00238\ \ \ \ \ \textcolor{keywordflow}{return}\ it.second;}
\DoxyCodeLine{00239\ \}}
\DoxyCodeLine{00240\ }
\DoxyCodeLine{00241\ }
\DoxyCodeLine{00242\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00243\ \textcolor{keyword}{inline}\ std::shared\_ptr<T>\ registry::get\_data(std::string\ key)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00244\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00245\ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{namespacegko_ae3e355a655feea026a7c46814d37a9c9}{gko::as<T>}}(stored\_map\_.at(key)}
\DoxyCodeLine{00246\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .template\ get<\textcolor{keyword}{typename}\ detail::base\_type<T>::type>());}
\DoxyCodeLine{00247\ \}}
\DoxyCodeLine{00248\ }
\DoxyCodeLine{00249\ \}\ \ \textcolor{comment}{//\ namespace\ config}}
\DoxyCodeLine{00250\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00251\ }
\DoxyCodeLine{00252\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_CONFIG\_REGISTRY\_HPP\_}}

\end{DoxyCode}
