Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
Ifpack2_Details_getParamTryingTypes.hpp
1// @HEADER
2// *****************************************************************************
3// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4//
5// Copyright 2009 NTESS and the Ifpack2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
11#define IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
12
13#include "Ifpack2_config.h"
14#include "Teuchos_TypeNameTraits.hpp"
15#include "Teuchos_ParameterList.hpp"
16
17namespace Ifpack2 {
18namespace Details {
19
20template <class... CandidateTypes>
21struct GetParamTryingTypes {
22 template <class ResultType>
23 static void
24 get(ResultType& result,
25 const Teuchos::ParameterEntry& ent,
26 const std::string& paramName,
27 const char prefix[]);
28};
29
30template <>
31struct GetParamTryingTypes<> {
32 template <class ResultType>
33 static void
34 get(ResultType& /* result */,
35 const Teuchos::ParameterEntry& /* ent */,
36 const std::string& paramName,
37 const char prefix[]) {
38 using Teuchos::TypeNameTraits;
39 TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, prefix << "\"" << paramName << "\" parameter exists in input ParameterList, but does not "
40 "have the right type. The proper type is "
41 << TypeNameTraits<ResultType>::name() << ".");
42 }
43};
44
45template <class First, class... Rest>
46struct GetParamTryingTypes<First, Rest...> {
47 template <class ResultType>
48 static void
49 get(ResultType& result,
50 const Teuchos::ParameterEntry& ent,
51 const std::string& paramName,
52 const char prefix[]) {
53 if (ent.template isType<First>()) {
54 result = static_cast<ResultType>(Teuchos::getValue<First>(ent));
55 } else {
56 using rest_type = GetParamTryingTypes<Rest...>;
57 rest_type::template get<ResultType>(result, ent, paramName, prefix);
58 }
59 }
60};
61
62template <class ResultType, class... CandidateTypes>
63void getParamTryingTypes(ResultType& result,
64 const Teuchos::ParameterList& params,
65 const std::string& paramName,
66 const char prefix[]) {
67 using Teuchos::ParameterEntry;
68 const ParameterEntry* ent = params.getEntryPtr(paramName);
69 if (ent != nullptr) {
70 using impl_type = GetParamTryingTypes<CandidateTypes...>;
71 impl_type::template get<ResultType>(result, *ent, paramName, prefix);
72 }
73}
74
75} // namespace Details
76} // namespace Ifpack2
77
78#endif // IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
Ifpack2 implementation details.
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:40