11#ifndef CHAISCRIPT_BOXED_CAST_HELPER_HPP_
12#define CHAISCRIPT_BOXED_CAST_HELPER_HPP_
33 throw std::runtime_error(
"Attempted to dereference null Boxed_Value");
37 static const T *verify_type_no_throw(
const Boxed_Value &ob,
const std::type_info &ti,
const T *ptr) {
46 static T *verify_type_no_throw(
const Boxed_Value &ob,
const std::type_info &ti, T *ptr) {
47 if (!ob.is_const() && ob.get_type_info() == ti) {
50 throw chaiscript::detail::exception::bad_any_cast();
56 static const T *verify_type(
const Boxed_Value &ob,
const std::type_info &ti,
const T *ptr) {
57 if (ob.get_type_info().bare_equal_type_info(ti)) {
60 throw chaiscript::detail::exception::bad_any_cast();
65 static T *verify_type(
const Boxed_Value &ob,
const std::type_info &ti, T *ptr) {
66 if (!ob.is_const() && ob.get_type_info().bare_equal_type_info(ti)) {
69 throw chaiscript::detail::exception::bad_any_cast();
74 template<
typename Result>
79 return *
static_cast<const Result *
>(verify_type(ob,
typeid(Result), ob.
get_const_ptr()));
83 template<
typename Result>
90 template<
typename Result>
95 return static_cast<const Result *
>(verify_type_no_throw(ob,
typeid(Result), ob.
get_const_ptr()));
100 template<
typename Result>
105 return static_cast<Result *
>(verify_type_no_throw(ob,
typeid(Result), ob.
get_ptr()));
109 template<
typename Result>
114 template<
typename Result>
121 template<
typename Result>
126 return *
static_cast<const Result *
>(verify_type(ob,
typeid(Result), ob.
get_const_ptr()));
133 template<
typename Result>
138 return *
static_cast<Result *
>(verify_type(ob,
typeid(Result), ob.
get_ptr()));
143 template<
typename Result>
148 return std::move(*
static_cast<Result *
>(verify_type(ob,
typeid(Result), ob.
get_ptr())));
154 template<
typename Result>
159 return std::move(*(ob.
get().
cast<std::shared_ptr<std::unique_ptr<Result>>>()));
165 template<
typename Result>
170 return *(ob.
get().
cast<std::shared_ptr<std::unique_ptr<Result>>>());
176 template<
typename Result>
181 return *(ob.
get().
cast<std::shared_ptr<std::unique_ptr<Result>>>());
187 template<
typename Result>
192 return ob.
get().
cast<std::shared_ptr<Result> >();
197 template<
typename Result>
204 return std::const_pointer_cast<const Result>(ob.
get().
cast<std::shared_ptr<Result> >());
206 return ob.
get().
cast<std::shared_ptr<const Result> >();
212 template<
typename Result>
217 template<
typename Result>
222 template<
typename Result>
225 static_assert(!std::is_const<Result>::value,
"Non-const reference to std::shared_ptr<const T> is not supported");
228 std::shared_ptr<Result> &res = ob.
get().
cast<std::shared_ptr<Result> >();
235 template<
typename Result>
240 template<
typename Result>
280 template<
typename Result>
285 template<
typename Result>
290 template<
typename Result>
295 template<
typename Result>
300 template<
typename Result>
305 template<
typename Result>
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
void * get_ptr() const noexcept
Definition boxed_value.hpp:311
const void * get_const_ptr() const noexcept
Definition boxed_value.hpp:316
const chaiscript::detail::Any & get() const noexcept
Definition boxed_value.hpp:286
const Type_Info & get_type_info() const noexcept
Definition boxed_value.hpp:224
auto pointer_sentinel(std::shared_ptr< T > &ptr) const
Definition boxed_value.hpp:247
Definition type_conversions.hpp:512
constexpr bool is_const() const noexcept
Definition type_info.hpp:86
ToType & cast() const
Definition any.hpp:125
Thrown in the event that an Any cannot be cast to the desired type.
Definition any.hpp:22
Classes and functions reserved for internal use. Items in this namespace are not supported.
T * throw_if_null(T *t)
Definition boxed_cast_helper.hpp:30
Namespace chaiscript contains every API call that the average user will be concerned with.
static Boxed_Value cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:250
static std::reference_wrapper< Boxed_Value > cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:260
static Result * cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:103
static Result & cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:136
static Result && cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:146
static const Result * cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:93
static const Result & cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:124
static std::unique_ptr< Result > & cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:179
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:190
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:226
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:200
static std::unique_ptr< Result > & cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:168
static std::unique_ptr< Result > && cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:157
Generic Cast_Helper_Inner, for casting to any type.
Definition boxed_cast_helper.hpp:76
static Result cast(const Boxed_Value &ob, const Type_Conversions_State *)
Definition boxed_cast_helper.hpp:77
The exposed Cast_Helper object that by default just calls the Cast_Helper_Inner.
Definition boxed_cast_helper.hpp:313
static decltype(auto) cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
Definition boxed_cast_helper.hpp:314