TECA
The Toolkit for Extreme Climate Analysis
teca_bad_cast.h
1 #ifndef teca_bad_cast_h
2 #define teca_bad_cast_h
3 
4 #include "teca_config.h"
5 
6 #include <exception>
7 #include <string>
8 #include <typeinfo>
9 
10 /** @brief
11  * An exception that maybe thrown when a conversion between two data types
12  * fails.
13  */
14 class TECA_EXPORT teca_bad_cast : public std::exception
15 {
16 public:
17  teca_bad_cast() = delete;
18  ~teca_bad_cast() = default;
19 
20  teca_bad_cast(const std::string &from, const std::string &to);
21 
22  const char* what() const noexcept { return m_what.c_str(); }
23 
24 private:
25  std::string m_what;
26 };
27 
28 /** returns the class name of the teca_algorithm or the string "nullptr"
29  * if the algorithm is a nullptr.
30  */
31 template <typename class_t>
33 std::string safe_class_name(const class_t &o)
34 {
35  return o ? std::string(o->get_class_name()) : std::string("nullptr");
36 }
37 
38 template <typename ptr_t>
40 std::string safe_pointer_name(const ptr_t *o)
41 {
42  return std::string("pointer of type ") +
43  (o ? std::string(typeid(o).name()) : std::string("nullptr"));
44 }
45 
46 #endif
An exception that maybe thrown when a conversion between two data types fails.
Definition: teca_bad_cast.h:15
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.