11#ifndef CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_
12#define CHAISCRIPT_DYNAMIC_CAST_CONVERSION_HPP_
36 const std::string &t_what) noexcept
60 const std::string &t_what) noexcept
108 : m_to(
std::move(t_to)), m_from(
std::move(t_from))
119 template<
typename From,
typename To>
138 throw std::bad_cast();
149 throw std::bad_cast();
159 const To &
data =
static_cast<const To &
>(
d);
163 To &
data =
static_cast<To &
>(
d);
175 template<
typename From,
typename To>
194 throw std::bad_cast();
205#ifdef CHAISCRIPT_LIBCPP
207 if (std::string(
typeid(To).
name()).
find(
"Assignable_Proxy_Function") != std::string::npos) {
209 if (std::string(
typeid(*from).name()).find(
"Assignable_Proxy_Function_Impl") != std::string::npos) {
210 return std::static_pointer_cast<To>(from);
214 throw std::bad_cast();
224 const To &
data =
dynamic_cast<const To &
>(
d);
228 To &
data =
dynamic_cast<To &
>(
d);
240 template<
typename Base,
typename Derived>
260 template<
typename Base,
typename Derived>
272 "Unable to cast down inheritance hierarchy with non-polymorphic types");
288 template<
typename Callable>
294 m_func(
std::move(t_func))
306 return m_func(t_from);
331 bool operator()(
const std::type_info *t_lhs,
const std::type_info *t_rhs)
const
333 return *t_lhs != *t_rhs && t_lhs->before(*t_rhs);
340 m_convertableTypes(),
351 const std::set<const std::type_info *, Less_Than> &
thread_cache()
const
353 auto &cache = *m_thread_cache;
354 if (cache.size() != m_num_types)
357 cache = m_convertableTypes;
363 void add_conversion(
const std::shared_ptr<detail::Type_Conversion_Base> &conversion)
367 m_conversions.insert(conversion);
368 m_convertableTypes.insert({conversion->to().bare_type_info(), conversion->from().bare_type_info()});
369 m_num_types = m_convertableTypes.size();
378 template<
typename To,
typename From>
387 if (types.count(to.bare_type_info()) != 0 && types.count(from.bare_type_info()) != 0)
395 template<
typename To>
401 template<
typename From>
414 }
catch (
const std::out_of_range &) {
416 }
catch (
const std::bad_cast &) {
427 }
catch (
const std::out_of_range &) {
429 }
catch (
const std::bad_cast &) {
441 std::vector<Boxed_Value>
ret;
449 return find_bidir(to, from) != m_conversions.end();
456 const auto itr =
find(to, from);
458 if (itr != m_conversions.end())
462 throw std::out_of_range(
"No such conversion exists from " + from.bare_name() +
" to " + to.bare_name());
467 return *m_conversion_saves;
471 std::set<std::shared_ptr<detail::Type_Conversion_Base> >::const_iterator find_bidir(
474 return std::find_if(m_conversions.begin(), m_conversions.end(),
475 [&to, &from](
const std::shared_ptr<detail::Type_Conversion_Base> &conversion) ->
bool
477 return (conversion->to().bare_equal(to) && conversion->from().bare_equal(from))
478 || (conversion->bidir() && conversion->from().bare_equal(to) && conversion->to().bare_equal(from));
483 std::set<std::shared_ptr<detail::Type_Conversion_Base> >::const_iterator
find(
484 const Type_Info &to,
const Type_Info &from)
const
486 return std::find_if(m_conversions.begin(), m_conversions.end(),
487 [&to, &from](
const std::shared_ptr<detail::Type_Conversion_Base> &conversion)
489 return conversion->to().bare_equal(to) && conversion->from().bare_equal(from);
494 std::set<std::shared_ptr<detail::Type_Conversion_Base>> get_conversions()
const
498 return m_conversions;
504 std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions;
505 std::set<const std::type_info *, Less_Than> m_convertableTypes;
506 std::atomic_size_t m_num_types;
507 mutable chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache;
508 mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves;
516 : m_conversions(t_conversions),
522 return &m_conversions.get();
526 return &m_conversions.get();
534 std::reference_wrapper<const Type_Conversions> m_conversions;
535 std::reference_wrapper<Type_Conversions::Conversion_Saves> m_saves;
561 template<
typename Base,
typename Derived>
562 Type_Conversion base_class(
typename std::enable_if<std::is_polymorphic<Base>::value && std::is_polymorphic<Derived>::value>::type* =
nullptr)
566 static_assert(std::is_base_of<Base,Derived>::value,
"Classes are not related by inheritance");
571 template<
typename Base,
typename Derived>
572 Type_Conversion base_class(
typename std::enable_if<!std::is_polymorphic<Base>::value || !std::is_polymorphic<Derived>::value>::type* =
nullptr)
576 static_assert(std::is_base_of<Base,Derived>::value,
"Classes are not related by inheritance");
582 template<
typename Callable>
584 const Callable &t_func)
589 template<
typename From,
typename To,
typename Callable>
600 template<
typename From,
typename To>
603 static_assert(std::is_convertible<From, To>::value,
"Types are not automatically convertible");
612 template<
typename To>
619 vec.reserve(from_vec.size());
630 template<
typename To>
637 for (
const std::pair<std::string, Boxed_Value> &p : from_map) {
P func(int c, EveryApi &ev)
Definition test.cpp:59
void * find(int i)
Definition ui.cc:347
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
bool is_pointer() const noexcept
Definition boxed_value.hpp:306
bool is_const() const noexcept
Definition boxed_value.hpp:235
const Type_Info & get_type_info() const noexcept
Definition boxed_value.hpp:224
const Type_Conversions * operator->() const
Definition type_conversions.hpp:521
const Type_Conversions * get() const
Definition type_conversions.hpp:525
Type_Conversions_State(const Type_Conversions &t_conversions, Type_Conversions::Conversion_Saves &t_saves)
Definition type_conversions.hpp:514
Type_Conversions::Conversion_Saves & saves() const
Definition type_conversions.hpp:529
Definition type_conversions.hpp:321
std::vector< Boxed_Value > take_saves(Conversion_Saves &t_saves)
Definition type_conversions.hpp:439
bool converts(const Type_Info &to, const Type_Info &from) const
Definition type_conversions.hpp:384
bool converts() const
Definition type_conversions.hpp:379
void add_conversion(const std::shared_ptr< detail::Type_Conversion_Base > &conversion)
Definition type_conversions.hpp:363
Boxed_Value boxed_type_down_conversion(const Type_Info &from, Conversion_Saves &t_saves, const Boxed_Value &to) const
Definition type_conversions.hpp:421
Type_Conversions(Type_Conversions &&)=default
Boxed_Value boxed_type_conversion(Conversion_Saves &t_saves, const Boxed_Value &from) const
Definition type_conversions.hpp:396
bool convertable_type() const
Definition type_conversions.hpp:373
Type_Conversions & operator=(const Type_Conversions &)=delete
Type_Conversions(const Type_Conversions &t_other)=delete
Boxed_Value boxed_type_down_conversion(Conversion_Saves &t_saves, const Boxed_Value &to) const
Definition type_conversions.hpp:402
Boxed_Value boxed_type_conversion(const Type_Info &to, Conversion_Saves &t_saves, const Boxed_Value &from) const
Definition type_conversions.hpp:408
static void enable_conversion_saves(Conversion_Saves &t_saves, bool t_val)
Definition type_conversions.hpp:434
const std::set< const std::type_info *, Less_Than > & thread_cache() const
Definition type_conversions.hpp:351
Type_Conversions & operator=(Type_Conversions &&)=default
Conversion_Saves & conversion_saves() const
Definition type_conversions.hpp:466
bool has_conversion(const Type_Info &to, const Type_Info &from) const
Definition type_conversions.hpp:446
std::shared_ptr< detail::Type_Conversion_Base > get_conversion(const Type_Info &to, const Type_Info &from) const
Definition type_conversions.hpp:452
Type_Conversions()
Definition type_conversions.hpp:337
Compile time deduced information about a type.
Definition type_info.hpp:34
constexpr bool bare_equal(const Type_Info &ti) const noexcept
Definition type_info.hpp:75
Definition type_conversions.hpp:177
static Boxed_Value cast(const Boxed_Value &t_from)
Definition type_conversions.hpp:179
Dynamic_Conversion_Impl()
Definition type_conversions.hpp:244
Boxed_Value convert_down(const Boxed_Value &t_base) const override
Definition type_conversions.hpp:249
Boxed_Value convert(const Boxed_Value &t_derived) const override
Definition type_conversions.hpp:254
Definition type_conversions.hpp:121
static Boxed_Value cast(const Boxed_Value &t_from)
Definition type_conversions.hpp:123
bool bidir() const override
Definition type_conversions.hpp:275
Boxed_Value convert(const Boxed_Value &t_derived) const override
Definition type_conversions.hpp:280
Static_Conversion_Impl()
Definition type_conversions.hpp:264
Boxed_Value convert_down(const Boxed_Value &t_base) const override
Definition type_conversions.hpp:269
Definition type_conversions.hpp:85
virtual Boxed_Value convert_down(const Boxed_Value &to) const =0
virtual Boxed_Value convert(const Boxed_Value &from) const =0
virtual bool bidir() const
Definition type_conversions.hpp:99
Type_Conversion_Base(Type_Info t_to, Type_Info t_from)
Definition type_conversions.hpp:107
virtual ~Type_Conversion_Base()=default
const Type_Info & to() const
Definition type_conversions.hpp:90
const Type_Info & from() const
Definition type_conversions.hpp:94
Definition type_conversions.hpp:290
Boxed_Value convert(const Boxed_Value &t_from) const override
Definition type_conversions.hpp:303
bool bidir() const override
Definition type_conversions.hpp:309
Type_Conversion_Impl(Type_Info t_from, Type_Info t_to, Callable t_func)
Definition type_conversions.hpp:292
Boxed_Value convert_down(const Boxed_Value &) const override
Definition type_conversions.hpp:298
bad_boxed_cast(Type_Info t_from, const std::type_info &t_to, std::string t_what) noexcept
Definition bad_boxed_cast.hpp:36
Definition type_conversions.hpp:33
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &)=default
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
Definition type_conversions.hpp:41
bad_boxed_dynamic_cast(const std::string &w) noexcept
Definition type_conversions.hpp:46
bad_boxed_dynamic_cast(const Type_Info &t_from, const std::type_info &t_to, const std::string &t_what) noexcept
Definition type_conversions.hpp:35
~bad_boxed_dynamic_cast() noexcept override=default
Definition type_conversions.hpp:57
bad_boxed_type_cast(const bad_boxed_type_cast &)=default
~bad_boxed_type_cast() noexcept override=default
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to, const std::string &t_what) noexcept
Definition type_conversions.hpp:59
bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to) noexcept
Definition type_conversions.hpp:65
bad_boxed_type_cast(const std::string &w) noexcept
Definition type_conversions.hpp:70
ret($return)
Definition mesh_login_result.php:5
d
Definition meshpage.php:3895
iVBORw0KGgoAAAANSUhEUgAAANcAAAB5CAMAAACdtUQZAAAA51BMVEX</div ></div >< div style="padding: 0px 0px; width: 1324px;">< div style="height: 400px; width: 1324px;"></div >< div itemscope itemtype="https: </div><div itemscope itemtype="https:</div >< div itemscope itemtype="https: </div></div><p><div style="padding:0px 0px;width:1324px;"><div></div><div itemscope itemtype="https:< ul >< li >< b > Application name
8AkrcAgqgAs9wqQ0ey2tkAo8gAuuQfeI4hPUH09fXHy8z4+fng4uNKXF/Lz9BzfoAcgpkQMTUAKjAbOT4Qr9AXhJ8Rl7ktMCwTosA...
Definition meshpage.php:1610
lazy data
Definition meshpage.php:1583
std::unique_lock< T > shared_lock
Definition chaiscript_threading.hpp:52
std::mutex shared_mutex
Definition chaiscript_threading.hpp:58
std::unique_lock< T > unique_lock
Definition chaiscript_threading.hpp:49
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.
constexpr Type_Info user_type(const T &)
Creates a Type_Info object representing the type passed in.
Definition type_info.hpp:221
std::shared_ptr< chaiscript::detail::Type_Conversion_Base > Type_Conversion
Definition type_conversions.hpp:538
Type_Conversion base_class(typename std::enable_if< std::is_polymorphic< Base >::value &&std::is_polymorphic< Derived >::value >::type *=nullptr)
Used to register a to / parent class relationship with ChaiScript. Necessary if you want automatic co...
Definition type_conversions.hpp:562
std::shared_ptr< B > make_shared(Arg &&... arg)
Definition chaiscript_defines.hpp:87
Type_Conversion map_conversion()
Definition type_conversions.hpp:631
Type_Conversion type_conversion()
Definition type_conversions.hpp:601
Type_Conversion vector_conversion()
Definition type_conversions.hpp:613
Definition type_conversions.hpp:324
bool enabled
Definition type_conversions.hpp:325
std::vector< Boxed_Value > saves
Definition type_conversions.hpp:326
Definition type_conversions.hpp:330
bool operator()(const std::type_info *t_lhs, const std::type_info *t_rhs) const
Definition type_conversions.hpp:331
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