Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Trilinos_Details_LinearSolverFactory.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11#include <set>
12
13namespace Trilinos {
14namespace Details {
15namespace Impl {
16
17namespace { // (anonymous)
18
19// All package names that registerLinearSolverFactory has seen,
20// for any combination of template parameters MV and OP.
21static std::set<std::string>* packageNames_ = NULL;
22
23// atexit() hook for freeing packageNames_.
24void freePackageNames ()
25{
26 if (packageNames_ != NULL) {
27 delete packageNames_;
28 packageNames_ = NULL;
29 }
30}
31
32void createPackageNames ()
33{
34 if (packageNames_ == NULL) {
35 packageNames_ = new std::set<std::string> ();
36 // It _is_ possible for atexit() to fail (e.g., because it ran
37 // out of memory for storing callbacks). We could throw an
38 // exception here in that case, but I think it's better just
39 // to let the minor memory leak happen.
40 (void) atexit (freePackageNames);
41 }
42}
43
44} // namespace (anonymous)
45
46bool rememberRegisteredSomeLinearSolverFactory (const std::string& packageName)
47{
48 createPackageNames ();
50 (packageNames_ == NULL, std::logic_error, "Trilinos::Details::"
51 "Impl::rememberRegisteredSomeLinearSolverFactory: "
52 "Should never get here! packageNames_ is NULL.");
53
54 std::pair<std::set<std::string>::iterator, bool> ret =
55 packageNames_->insert (packageName);
56 // ret.second is true if the item was NOT in the set before.
57 return ! ret.second;
58}
59
60bool registeredSomeLinearSolverFactory (const std::string& packageName)
61{
62 createPackageNames ();
64 (packageNames_ == NULL, std::logic_error, "Trilinos::Details::"
65 "Impl::rememberRegisteredSomeLinearSolverFactory: "
66 "Should never get here! packageNames_ is NULL.");
67
68 std::set<std::string>::const_iterator it = packageNames_->find (packageName);
69 return it != packageNames_->end ();
70}
71
73{
74#if defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
75 return true;
76#else // NOT defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
77 return false;
78#endif // defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
79}
80
81} // namespace Impl
82} // namespace Details
83} // namespace Trilinos
84
85
Declaration and definition of linear solver factory, and "factory of factories".
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Namespace of implementation details.
bool registeredSomeLinearSolverFactory(const std::string &packageName)
Did the package with the given name register at least one LinearSolverFactory, with any template para...
bool rememberRegisteredSomeLinearSolverFactory(const std::string &packageName)
Remember which packages registered at least one LinearSolverFactory, with any template parameters.
bool haveLinearSolverFactoryRunTimeRegistration()
Whether the CMake run-time registration option is ON.
Namespace of things generally useful to many Trilinos packages.