\doxysection{json\+\_\+config.\+hpp}
\hypertarget{json__config_8hpp_source}{}\label{json__config_8hpp_source}\index{ginkgo/extensions/config/json\_config.hpp@{ginkgo/extensions/config/json\_config.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\_EXTENSIONS\_CONFIG\_JSON\_CONFIG\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_EXTENSIONS\_CONFIG\_JSON\_CONFIG\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <fstream>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <stdexcept>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <nlohmann/json.hpp>}}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ <ginkgo/core/config/property\_tree.hpp>}}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00019\ \textcolor{keyword}{namespace\ }ext\ \{}
\DoxyCodeLine{00020\ \textcolor{keyword}{namespace\ }config\ \{}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00027\ \textcolor{keyword}{inline}\ gko::config::pnode\ parse\_json(\textcolor{keyword}{const}\ nlohmann::json\&\ input)}
\DoxyCodeLine{00028\ \{}
\DoxyCodeLine{00029\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ dom\ =\ input;}
\DoxyCodeLine{00030\ }
\DoxyCodeLine{00031\ \ \ \ \ \textcolor{keyword}{auto}\ parse\_array\ =\ [](\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ arr)\ \{}
\DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ gko::config::pnode::array\_type\ nodes;}
\DoxyCodeLine{00033\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ it\ :\ arr)\ \{}
\DoxyCodeLine{00034\ \ \ \ \ \ \ \ \ \ \ \ \ nodes.emplace\_back(parse\_json(it));}
\DoxyCodeLine{00035\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00036\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{nodes\};}
\DoxyCodeLine{00037\ \ \ \ \ \};}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keyword}{auto}\ parse\_map\ =\ [](\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ map)\ \{}
\DoxyCodeLine{00039\ \ \ \ \ \ \ \ \ gko::config::pnode::map\_type\ nodes;}
\DoxyCodeLine{00040\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\&\ el\ :\ map.items())\ \{}
\DoxyCodeLine{00041\ \ \ \ \ \ \ \ \ \ \ \ \ nodes.emplace(el.key(),\ parse\_json(el.value()));}
\DoxyCodeLine{00042\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00043\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{nodes\};}
\DoxyCodeLine{00044\ \ \ \ \ \};}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{auto}\ parse\_data\ =\ [](\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\&\ data)\ \{}
\DoxyCodeLine{00046\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (data.is\_number\_integer())\ \{}
\DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{data.template\ get<std::int64\_t>()\};}
\DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00049\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (data.is\_boolean())\ \{}
\DoxyCodeLine{00050\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{data.template\ get<bool>()\};}
\DoxyCodeLine{00051\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (data.is\_number\_float())\ \{}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{data.template\ get<double>()\};}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (data.is\_string())\ \{}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::config::pnode\{}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::string(data.template\ get<std::string>())\};}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}property\_tree\ can\ not\ handle\ the\ node\ with\ content:\ "{}}\ +}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \ \ \ \ data.dump());}
\DoxyCodeLine{00062\ \ \ \ \ \};}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \ \ \ \ \textcolor{keywordflow}{if}\ (dom.is\_array())\ \{}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ parse\_array(dom);}
\DoxyCodeLine{00066\ \ \ \ \ \}}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keywordflow}{if}\ (dom.is\_object())\ \{}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ parse\_map(dom);}
\DoxyCodeLine{00069\ \ \ \ \ \}}
\DoxyCodeLine{00070\ \ \ \ \ \textcolor{keywordflow}{return}\ parse\_data(dom);}
\DoxyCodeLine{00071\ \}}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00073\ }
\DoxyCodeLine{00077\ \textcolor{keyword}{inline}\ gko::config::pnode\ parse\_json\_file(std::string\ filename)}
\DoxyCodeLine{00078\ \{}
\DoxyCodeLine{00079\ \ \ \ \ std::ifstream\ fstream(filename);}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordflow}{return}\ parse\_json(nlohmann::json::parse(fstream));}
\DoxyCodeLine{00081\ \}}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00086\ \textcolor{keyword}{inline}\ gko::config::pnode\ parse\_json\_string(std::string\ json)}
\DoxyCodeLine{00087\ \{}
\DoxyCodeLine{00088\ \ \ \ \ \textcolor{keywordflow}{return}\ parse\_json(nlohmann::json::parse(json));}
\DoxyCodeLine{00089\ \}}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00091\ \}\ \ \textcolor{comment}{//\ namespace\ config}}
\DoxyCodeLine{00092\ \}\ \ \textcolor{comment}{//\ namespace\ ext}}
\DoxyCodeLine{00093\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00096\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_EXTENSIONS\_CONFIG\_JSON\_CONFIG\_HPP\_}}

\end{DoxyCode}
