46#ifndef MUELU_VARIABLECONTAINER_HPP
47#define MUELU_VARIABLECONTAINER_HPP
51#include <Teuchos_TypeNameTraits.hpp>
53#include <Xpetra_Matrix.hpp>
54#include <Xpetra_Operator.hpp>
79 virtual const std::type_info&
type()
const = 0;
87 const std::type_info&
type()
const {
return typeid(T); }
88 std::string
typeName()
const {
return Teuchos::TypeNameTraits<T>::name(); }
95 if ((
data_ == NULL) || (
data_->type() !=
typeid(T)))
97 const std::string typeName = Teuchos::TypeNameTraits<T>::name();
98 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
99 "Error, cast to type Data<" << typeName <<
"> failed since the content is NULL");
101 TEUCHOS_TEST_FOR_EXCEPTION(
data_->type() !=
typeid(T), Teuchos::bad_any_cast,
102 "Error, cast to type Data<" << typeName <<
"> failed since the actual underlying type is "
103 "\'" <<
data_->typeName() <<
"!");
109 const std::string typeName = Teuchos::TypeNameTraits<T>::name();
110 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
111 "Error, cast to type Data<" << typeName <<
"> failed but should not have and the actual underlying type is "
112 "\'" <<
data_->typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
121 if ((
data_ == NULL) || (
data_->type() !=
typeid(T)))
199 return std::string(
"");
200 return data_->typeName();
214 request_container::iterator it =
requests_.find(reqFactory);
224 request_container::iterator it =
requests_.find(reqFactory);
226 "cannot call Release if factory has not been requested before by factory " << reqFactory);
227 if (--(it->second) == 0)
234 request_container::const_iterator it =
requests_.find(reqFactory);
235 return (it !=
requests_.end()) ? it->second : 0;
269 template<
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
271 typedef Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>
Operator;
272 typedef Xpetra::Matrix <Scalar,LocalOrdinal,GlobalOrdinal,Node>
Matrix;
275 typedef Teuchos::RCP<Operator> TO;
276 typedef Teuchos::RCP<Matrix> TM;
280 TEUCHOS_TEST_FOR_EXCEPTION(
data_ == NULL, Teuchos::bad_any_cast,
281 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed since the content is NULL");
283 if (
data_->type() ==
typeid(TO)) {
287 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
288 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed but should not have and the actual underlying type is "
289 "\'" <<
data_->typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
294 if (
data_->type() !=
typeid(TM))
296 TEUCHOS_TEST_FOR_EXCEPTION(
data_->type() !=
typeid(TM), Teuchos::bad_any_cast,
297 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TM>::name() <<
"> failed since the actual underlying type is "
298 "\'" <<
data_->typeName() <<
"!");
303 TEUCHOS_TEST_FOR_EXCEPTION(!data, std::logic_error,
304 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TM>::name() <<
"> failed but should not have and the actual underlying type is "
305 "\'" <<
data_->typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
313 TEUCHOS_TEST_FOR_EXCEPTION(!datah, std::logic_error,
314 "Error, cast to type Data<" << Teuchos::TypeNameTraits<TO>::name() <<
"> failed but should not have and the actual underlying type is "
315 "\'" <<
datah_->typeName() <<
"! The problem might be related to incompatible RTTI systems in static and shared libraries!");
Base class for MueLu classes.
Exception throws to report errors in the internal logical of the program.
Base class for factories (e.g., R, P, and A_coarse).
virtual std::string typeName() const =0
virtual const std::type_info & type() const =0
const std::type_info & type() const
std::string typeName() const
bool IsRequested() const
Returns true, if data is requested by at least one factory.
DataBase * data_
the data itself
std::map< const FactoryBase *, int > request_container
void RemoveKeepFlag(KeepType keep=UserData)
Removes a keep flag to the flag combination.
bool IsRequested(const FactoryBase *reqFactory) const
Returns true, if data is requested by reqFactory.
std::string GetTypeName()
void AddKeepFlag(KeepType keep=UserData)
Adds a keep flag to the flag combination.
bool IsAvailable() const
Returns true if data is available, i.e.
void Request(const FactoryBase *reqFactory)
Request data.
KeepType GetKeepFlag() const
Returns the keep flag combination.
const T & GetData() const
void SetData(const T &entry)
Store data in container class and set the "Available" status true.
bool IsKept(KeepType keep) const
Returns true if at least one keep flag is set.
const request_container & Requests() const
request_container requests_
requesting factories
bool available_
is data available?
int count_
number of requests by all factories
int NumAllRequests() const
Returns the number of times the data has been requested.
VariableContainer()
Default constructor.
void Release(const FactoryBase *reqFactory)
Release data.
int NumRequests(const FactoryBase *reqFactory) const
Return the number of times the data has been requested by a specific factory.
Namespace for MueLu classes and methods.
@ UserData
User data are always kept. This flag is set automatically when Level::Set("data", data) is used....
static bool check(DataBase *data_, DataBase *&)
Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > Operator
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
static Teuchos::RCP< Operator > & get(DataBase *data_, DataBase *&datah_)
static T & get(DataBase *data_, DataBase *&)