GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
exception_specification.hpp
Go to the documentation of this file.
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-2017, 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_EXCEPTION_SPECIFICATION_HPP_
12#define CHAISCRIPT_EXCEPTION_SPECIFICATION_HPP_
13
14#include <memory>
15
17#include "boxed_cast.hpp"
18
19namespace chaiscript {
20class Boxed_Value;
21namespace exception {
22class bad_boxed_cast;
23} // namespace exception
24} // namespace chaiscript
25
26namespace chaiscript
27{
28 namespace detail
29 {
31 {
32 virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) = 0;
33
34 virtual ~Exception_Handler_Base() = default;
35
36 protected:
37 template<typename T>
38 static void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
39 {
40 try { T t = t_engine.boxed_cast<T>(bv); throw t; } catch (const chaiscript::exception::bad_boxed_cast &) {}
41 }
42 };
43
44 template<typename ... T>
46 {
47 void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override
48 {
49 (void)std::initializer_list<int>{(throw_type<T>(bv, t_engine), 0)...};
50 }
51 };
52 }
53
104 typedef std::shared_ptr<detail::Exception_Handler_Base> Exception_Handler;
105
108 template<typename ... T>
110 {
111 return std::make_shared<detail::Exception_Handler_Impl<T...>>();
112 }
113}
114
115
116#endif
117
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
Definition dispatchkit.hpp:438
decltype(auto) boxed_cast(const Boxed_Value &bv) const
casts an object while applying any Dynamic_Conversion available
Definition dispatchkit.hpp:462
Thrown in the event that a Boxed_Value cannot be cast to the desired type.
Definition bad_boxed_cast.hpp:34
Classes and functions reserved for internal use. Items in this namespace are not supported.
Classes which may be thrown during error cases when ChaiScript is executing.
Definition bad_boxed_cast.hpp:27
Namespace chaiscript contains every API call that the average user will be concerned with.
std::shared_ptr< detail::Exception_Handler_Base > Exception_Handler
Used in the automatic unboxing of exceptions thrown during script evaluation.
Definition exception_specification.hpp:104
Exception_Handler exception_specification()
creates a chaiscript::Exception_Handler which handles one type of exception unboxing
Definition exception_specification.hpp:109
Definition GameApi.h:42
Definition exception_specification.hpp:31
static void throw_type(const Boxed_Value &bv, const Dispatch_Engine &t_engine)
Definition exception_specification.hpp:38
virtual void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine)=0
Definition exception_specification.hpp:46
void handle(const Boxed_Value &bv, const Dispatch_Engine &t_engine) override
Definition exception_specification.hpp:47