Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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"
16 
17 namespace Ifpack2 {
18 namespace Details {
19 
20 template<class ... CandidateTypes>
21 struct 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 
30 template<>
31 struct 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  {
41  (true, std::invalid_argument, prefix << "\"" << paramName
42  << "\" parameter exists in input ParameterList, but does not "
43  "have the right type. The proper type is "
44  << TypeNameTraits<ResultType>::name () << ".");
45  }
46 };
47 
48 template<class First, class ... Rest>
49 struct GetParamTryingTypes<First, Rest...> {
50  template<class ResultType>
51  static void
52  get (ResultType& result,
53  const Teuchos::ParameterEntry& ent,
54  const std::string& paramName,
55  const char prefix[])
56  {
57  if (ent.template isType<First> ()) {
58  result = static_cast<ResultType> (Teuchos::getValue<First> (ent));
59  }
60  else {
61  using rest_type = GetParamTryingTypes<Rest...>;
62  rest_type::template get<ResultType> (result, ent, paramName, prefix);
63  }
64  }
65 };
66 
67 template<class ResultType, class ... CandidateTypes>
68 void
69 getParamTryingTypes (ResultType& result,
70  const Teuchos::ParameterList& params,
71  const std::string& paramName,
72  const char prefix[])
73 {
75  const ParameterEntry* ent = params.getEntryPtr (paramName);
76  if (ent != nullptr) {
77  using impl_type = GetParamTryingTypes<CandidateTypes...>;
78  impl_type::template get<ResultType> (result, *ent, paramName, prefix);
79  }
80 }
81 
82 } // namespace Details
83 } // namespace Ifpack2
84 
85 #endif // IFPACK2_DETAILS_GETPARAMTRYINGTYPES_HPP
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterEntry * getEntryPtr(const std::string &name)