ChaiScript
bad_boxed_cast.hpp
1 // This file is distributed under the BSD License.
2 // See "license.txt" for details.
3 // Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4 // Copyright 2009-2018, Jason Turner (jason@emptycrate.com)
5 // http://www.chaiscript.com
6 
7 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
8 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9 
10 #ifndef CHAISCRIPT_BAD_BOXED_CAST_HPP_
11 #define CHAISCRIPT_BAD_BOXED_CAST_HPP_
12 
13 #include <string>
14 #include <typeinfo>
15 
16 #include "../chaiscript_defines.hpp"
17 #include "../utility/static_string.hpp"
18 #include "type_info.hpp"
19 
20 namespace chaiscript {
21  class Type_Info;
22 } // namespace chaiscript
23 
24 namespace chaiscript {
25  namespace exception {
31  class bad_boxed_cast : public std::bad_cast {
32  public:
33  bad_boxed_cast(Type_Info t_from, const std::type_info &t_to, utility::Static_String t_what) noexcept
34  : from(t_from)
35  , to(&t_to)
36  , m_what(std::move(t_what)) {
37  }
38 
39  bad_boxed_cast(Type_Info t_from, const std::type_info &t_to) noexcept
40  : from(t_from)
41  , to(&t_to)
42  , m_what("Cannot perform boxed_cast") {
43  }
44 
45  explicit bad_boxed_cast(utility::Static_String t_what) noexcept
46  : m_what(std::move(t_what)) {
47  }
48 
49  bad_boxed_cast(const bad_boxed_cast &) noexcept = default;
50  ~bad_boxed_cast() noexcept override = default;
51 
53  const char *what() const noexcept override { return m_what.c_str(); }
54 
56  const std::type_info *to = nullptr;
57 
58  private:
60  };
61  } // namespace exception
62 } // namespace chaiscript
63 
64 #endif
Compile time deduced information about a type.
Definition: type_info.hpp:27
Namespace chaiscript contains every API call that the average user will be concerned with...
Thrown in the event that a Boxed_Value cannot be cast to the desired type.
Definition: bad_boxed_cast.hpp:31
Type_Info from
Type_Info contained in the Boxed_Value.
Definition: bad_boxed_cast.hpp:55
Definition: static_string.hpp:11
const char * what() const noexcept override
Description of what error occurred.
Definition: bad_boxed_cast.hpp:53
const std::type_info * to
std::type_info of the desired (but failed) result type
Definition: bad_boxed_cast.hpp:56