Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_dyn_cast.hpp
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
10#ifndef TEUCHOS_DYN_CAST_HPP
11#define TEUCHOS_DYN_CAST_HPP
12
13
15
16
17namespace Teuchos {
18
19
28class m_bad_cast : public std::bad_cast {
29 std::string msg;
30public:
31 explicit m_bad_cast(const std::string& what_arg ) : msg(what_arg) {}
32 virtual ~m_bad_cast() throw() {}
33 virtual const char* what() const throw() { return msg.data(); }
34};
35
36
37// Throw <tt>m_bad_cast</tt> for below function
38TEUCHOSCORE_LIB_DLL_EXPORT void dyn_cast_throw_exception(
39 const std::string &T_from,
40 const std::string &T_from_concr,
41 const std::string &T_to
42 );
43
44
139template <class T_To, class T_From>
140inline
142{
143 T_To *to_ = dynamic_cast<T_To*>(&from);
144 if(!to_)
147 typeName(from),
149 );
150 return *to_;
151}
152
153
154} // namespace Teuchos
155
156
157#endif // TEUCHOS_DYN_CAST_HPP
Defines basic traits returning the name of a type in a portable and readable way.
Smart reference counting pointer class for automatic garbage collection.
Default traits class that just returns typeid(T).name().
Exception class for bad cast.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
T_To & dyn_cast(T_From &from)
Dynamic casting utility function meant to replace dynamic_cast<T&> by throwing a better documented er...
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOSCORE_LIB_DLL_EXPORT void dyn_cast_throw_exception(const std::string &T_from, const std::string &T_from_concr, const std::string &T_to)