GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
handle_return.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_HANDLE_RETURN_HPP_
12#define CHAISCRIPT_HANDLE_RETURN_HPP_
13
14#include <functional>
15#include <memory>
16#include <type_traits>
17
18#include "boxed_number.hpp"
19#include "boxed_value.hpp"
20
21namespace chaiscript {
22class Boxed_Number;
23} // namespace chaiscript
24
25namespace chaiscript
26{
27 namespace dispatch
28 {
29 template<class T, class U> class Proxy_Function_Callable_Impl;
30 template<class T> class Assignable_Proxy_Function_Impl;
31
32 namespace detail
33 {
35 template<typename Ret>
37 {
38 template<typename T,
39 typename = typename std::enable_if<std::is_pod<typename std::decay<T>::type>::value>::type>
41 {
42 return Boxed_Value(std::move(r), true);
43 }
44
45 template<typename T,
46 typename = typename std::enable_if<!std::is_pod<typename std::decay<T>::type>::value>::type>
47 static Boxed_Value handle(T &&r)
48 {
49 return Boxed_Value(std::make_shared<T>(std::forward<T>(r)), true);
50 }
51 };
52
53 template<typename Ret>
54 struct Handle_Return<const std::function<Ret> &>
55 {
56 static Boxed_Value handle(const std::function<Ret> &f) {
57 return Boxed_Value(
59 );
60 }
61 };
62
63 template<typename Ret>
64 struct Handle_Return<std::function<Ret>> : Handle_Return<const std::function<Ret> &>
65 {
66 };
67
68 template<typename Ret>
69 struct Handle_Return<const std::shared_ptr<std::function<Ret>>>
70 {
71 static Boxed_Value handle(const std::shared_ptr<std::function<Ret>> &f) {
72 return Boxed_Value(
74 );
75 }
76 };
77
78 template<typename Ret>
79 struct Handle_Return<const std::shared_ptr<std::function<Ret>> &> : Handle_Return<const std::shared_ptr<std::function<Ret>>>
80 {
81 };
82
83 template<typename Ret>
84 struct Handle_Return<std::shared_ptr<std::function<Ret>>> : Handle_Return<const std::shared_ptr<std::function<Ret>>>
85 {
86 };
87
88 template<typename Ret>
89 struct Handle_Return<std::function<Ret> &>
90 {
91 static Boxed_Value handle(std::function<Ret> &f) {
92 return Boxed_Value(
94 std::shared_ptr<std::function<Ret>>())
95 );
96 }
97
98 static Boxed_Value handle(const std::function<Ret> &f) {
99 return Boxed_Value(
101 );
102 }
103 };
104
105 template<typename Ret>
107 {
109 {
110 return Boxed_Value(p, true);
111 }
112 };
113
114 template<typename Ret>
115 struct Handle_Return<const Ret *&>
116 {
117 static Boxed_Value handle(const Ret *p)
118 {
119 return Boxed_Value(p, true);
120 }
121 };
122
123 template<typename Ret>
125 {
127 {
128 return Boxed_Value(p, true);
129 }
130 };
131
132 template<typename Ret>
133 struct Handle_Return<const Ret *>
134 {
135 static Boxed_Value handle(const Ret *p)
136 {
137 return Boxed_Value(p, true);
138 }
139 };
140
141 template<typename Ret>
142 struct Handle_Return<std::shared_ptr<Ret> &>
143 {
144 static Boxed_Value handle(const std::shared_ptr<Ret> &r)
145 {
146 return Boxed_Value(r, true);
147 }
148 };
149
150 template<typename Ret>
151 struct Handle_Return<std::shared_ptr<Ret>> : Handle_Return<std::shared_ptr<Ret> &>
152 {
153 };
154
155 template<typename Ret>
156 struct Handle_Return<const std::shared_ptr<Ret> &> : Handle_Return<std::shared_ptr<Ret> &>
157 {
158 };
159
160
161 template<typename Ret>
162 struct Handle_Return<std::unique_ptr<Ret>> : Handle_Return<std::unique_ptr<Ret> &>
163 {
164 static Boxed_Value handle(std::unique_ptr<Ret> &&r)
165 {
166 return Boxed_Value(std::move(r), true);
167 }
168 };
169
170
171
172 template<typename Ret>
173 struct Handle_Return<const Ret &>
174 {
175 static Boxed_Value handle(const Ret &r)
176 {
177 return Boxed_Value(std::cref(r), true);
178 }
179 };
180
181 template<typename Ret>
182 struct Handle_Return<const Ret>
183 {
185 {
186 return Boxed_Value(std::move(r));
187 }
188 };
189
190 template<typename Ret>
192 {
194 {
195 return Boxed_Value(std::ref(r));
196 }
197 };
198
199 template<>
201 {
203 {
204 return r;
205 }
206 };
207
208 template<>
209 struct Handle_Return<const Boxed_Value> : Handle_Return<Boxed_Value>
210 {
211 };
212
213 template<>
217
218 template<>
222
226 template<>
228 {
230 {
231 return r.bv;
232 }
233 };
234
235 template<>
236 struct Handle_Return<const Boxed_Number> : Handle_Return<Boxed_Number>
237 {
238 };
239
240
244 template<>
245 struct Handle_Return<void>
246 {
248 {
249 return void_var();
250 }
251 };
252 }
253 }
254}
255
256#endif
Represents any numeric type, generically. Used internally for generic operations between POD values.
Definition boxed_number.hpp:66
Boxed_Value bv
Definition boxed_number.hpp:905
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
Definition proxy_functions.hpp:196
For any callable object.
Definition proxy_functions.hpp:637
void function(void)
Definition memory_leak_test.cpp:26
Definition callable_traits.hpp:14
Classes and functions specific to the runtime dispatch side of ChaiScript. Some items may be of use t...
Definition callable_traits.hpp:13
Namespace chaiscript contains every API call that the average user will be concerned with.
Boxed_Value void_var()
Definition boxed_value.hpp:466
std::shared_ptr< B > make_shared(Arg &&... arg)
Definition chaiscript_defines.hpp:87
STL namespace.
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition GameApi_bm.cc:4579
Definition GameApi.h:42
static Boxed_Value handle(const Boxed_Number &r)
Definition handle_return.hpp:229
static Boxed_Value handle(const Boxed_Value &r)
Definition handle_return.hpp:202
static Boxed_Value handle(Ret *p)
Definition handle_return.hpp:126
static Boxed_Value handle(Ret *p)
Definition handle_return.hpp:108
static Boxed_Value handle(Ret &r)
Definition handle_return.hpp:193
static Boxed_Value handle(Ret r)
Definition handle_return.hpp:184
static Boxed_Value handle(const Ret *p)
Definition handle_return.hpp:135
static Boxed_Value handle(const Ret *p)
Definition handle_return.hpp:117
static Boxed_Value handle(const Ret &r)
Definition handle_return.hpp:175
static Boxed_Value handle(const std::function< Ret > &f)
Definition handle_return.hpp:56
static Boxed_Value handle(const std::shared_ptr< std::function< Ret > > &f)
Definition handle_return.hpp:71
static Boxed_Value handle(std::function< Ret > &f)
Definition handle_return.hpp:91
static Boxed_Value handle(const std::function< Ret > &f)
Definition handle_return.hpp:98
static Boxed_Value handle(const std::shared_ptr< Ret > &r)
Definition handle_return.hpp:144
static Boxed_Value handle(std::unique_ptr< Ret > &&r)
Definition handle_return.hpp:164
static Boxed_Value handle()
Definition handle_return.hpp:247
Used internally for handling a return value from a Proxy_Function call.
Definition handle_return.hpp:37
static Boxed_Value handle(T &&r)
Definition handle_return.hpp:47
static Boxed_Value handle(T r)
Definition handle_return.hpp:40