Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Trilinos_Details_LinearSolverFactory.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Teuchos: Common Tools Package
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40// @HEADER
41
43#include <set>
44
45namespace Trilinos {
46namespace Details {
47namespace Impl {
48
49namespace { // (anonymous)
50
51// All package names that registerLinearSolverFactory has seen,
52// for any combination of template parameters MV and OP.
53static std::set<std::string>* packageNames_ = NULL;
54
55// atexit() hook for freeing packageNames_.
56void freePackageNames ()
57{
58 if (packageNames_ != NULL) {
59 delete packageNames_;
60 packageNames_ = NULL;
61 }
62}
63
64void createPackageNames ()
65{
66 if (packageNames_ == NULL) {
67 packageNames_ = new std::set<std::string> ();
68 // It _is_ possible for atexit() to fail (e.g., because it ran
69 // out of memory for storing callbacks). We could throw an
70 // exception here in that case, but I think it's better just
71 // to let the minor memory leak happen.
72 (void) atexit (freePackageNames);
73 }
74}
75
76} // namespace (anonymous)
77
78bool rememberRegisteredSomeLinearSolverFactory (const std::string& packageName)
79{
80 createPackageNames ();
82 (packageNames_ == NULL, std::logic_error, "Trilinos::Details::"
83 "Impl::rememberRegisteredSomeLinearSolverFactory: "
84 "Should never get here! packageNames_ is NULL.");
85
86 std::pair<std::set<std::string>::iterator, bool> ret =
87 packageNames_->insert (packageName);
88 // ret.second is true if the item was NOT in the set before.
89 return ! ret.second;
90}
91
92bool registeredSomeLinearSolverFactory (const std::string& packageName)
93{
94 createPackageNames ();
96 (packageNames_ == NULL, std::logic_error, "Trilinos::Details::"
97 "Impl::rememberRegisteredSomeLinearSolverFactory: "
98 "Should never get here! packageNames_ is NULL.");
99
100 std::set<std::string>::const_iterator it = packageNames_->find (packageName);
101 return it != packageNames_->end ();
102}
103
105{
106#if defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
107 return true;
108#else // NOT defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
109 return false;
110#endif // defined(TRILINOS_HAVE_LINEAR_SOLVER_FACTORY_REGISTRATION)
111}
112
113} // namespace Impl
114} // namespace Details
115} // namespace Trilinos
116
117
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.