ChaiScript / ChaiScript
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

11
#ifndef CHAISCRIPT_BAD_BOXED_CAST_HPP_
12
#define CHAISCRIPT_BAD_BOXED_CAST_HPP_
13

14
#include <string>
15
#include <typeinfo>
16

17
#include "../chaiscript_defines.hpp"
18
#include "../utility/static_string.hpp"
19
#include "type_info.hpp"
20

21
namespace chaiscript {
22
class Type_Info;
23
}  // namespace chaiscript
24

25
namespace chaiscript 
26
{
27
  namespace exception
28
  {
29
    /// \brief Thrown in the event that a Boxed_Value cannot be cast to the desired type
30
    ///
31
    /// It is used internally during function dispatch and may be used by the end user.
32
    ///
33
    /// \sa chaiscript::boxed_cast
34
    class bad_boxed_cast : public std::bad_cast
35
    {
36
      public:
37 1
        bad_boxed_cast(Type_Info t_from, const std::type_info &t_to,
38
             utility::Static_String t_what) noexcept
39 1
          : from(t_from), to(&t_to), m_what(std::move(t_what))
40
        {
41
        }
42

43 1
        bad_boxed_cast(Type_Info t_from, const std::type_info &t_to) noexcept
44 1
          : from(t_from), to(&t_to), m_what("Cannot perform boxed_cast")
45
        {
46
        }
47

48 1
        explicit bad_boxed_cast(utility::Static_String t_what) noexcept
49 1
          : m_what(std::move(t_what))
50
        {
51
        }
52

53
        bad_boxed_cast(const bad_boxed_cast &) noexcept = default;
54 1
        ~bad_boxed_cast() noexcept override = default;
55

56
        /// \brief Description of what error occurred
57
        const char * what() const noexcept override
58
        {
59
          return m_what.c_str();
60
        }
61

62
        Type_Info from; ///< Type_Info contained in the Boxed_Value
63
        const std::type_info *to = nullptr; ///< std::type_info of the desired (but failed) result type
64

65
      private:
66
        utility::Static_String m_what;
67
    };
68
  }
69
}
70

71

72

73
#endif
74

Read our documentation on viewing source code .

Loading