diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index 31d9386..b33d659 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -18,7 +18,7 @@ #include "type_info.hpp" namespace chaiscript { -class Dynamic_Cast_Conversions; +class Type_Conversions; namespace detail { namespace exception { class bad_any_cast; @@ -72,7 +72,7 @@ namespace chaiscript /// assert(i == 5); /// \endcode template - typename detail::Cast_Helper::Result_Type boxed_cast(const Boxed_Value &bv, const Dynamic_Cast_Conversions *t_conversions = nullptr) + typename detail::Cast_Helper::Result_Type boxed_cast(const Boxed_Value &bv, const Type_Conversions *t_conversions = nullptr) { try { return detail::Cast_Helper::cast(bv, t_conversions); @@ -92,12 +92,12 @@ namespace chaiscript // std::cout << "trying an up conversion " << typeid(Type).name() << std::endl; // We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it // either way, we are not responsible if it doesn't work - return detail::Cast_Helper::cast(t_conversions->boxed_dynamic_cast(bv), t_conversions); + return detail::Cast_Helper::cast(t_conversions->boxed_type_conversion(bv), t_conversions); } catch (...) { try { // std::cout << "trying a down conversion " << typeid(Type).name() << std::endl; // try going the other way - down the inheritance graph - return detail::Cast_Helper::cast(t_conversions->boxed_dynamic_down_cast(bv), t_conversions); + return detail::Cast_Helper::cast(t_conversions->boxed_type_down_conversion(bv), t_conversions); } catch (const chaiscript::detail::exception::bad_any_cast &) { throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type)); } diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 8ae7552..3222fd1 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -17,7 +17,7 @@ namespace chaiscript { - class Dynamic_Cast_Conversions; + class Type_Conversions; namespace detail { @@ -36,7 +36,7 @@ namespace chaiscript { typedef typename std::reference_wrapper::type > Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { if (ob.get_type_info().bare_equal_type_info(typeid(Result))) { @@ -63,7 +63,7 @@ namespace chaiscript struct Cast_Helper_Inner { typedef const Result * Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { if (ob.is_ref()) { @@ -89,7 +89,7 @@ namespace chaiscript struct Cast_Helper_Inner { typedef Result * Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { if (ob.is_ref()) { @@ -107,7 +107,7 @@ namespace chaiscript { typedef Result& Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { if (!ob.get_type_info().is_const() && ob.get_type_info().bare_equal_type_info(typeid(Result))) { @@ -124,7 +124,7 @@ namespace chaiscript { typedef typename std::shared_ptr Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { return ob.get().cast >(); } @@ -136,7 +136,7 @@ namespace chaiscript { typedef typename std::shared_ptr Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { if (!ob.get_type_info().is_const()) { @@ -178,7 +178,7 @@ namespace chaiscript { typedef const Boxed_Value & Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { return ob; } @@ -190,7 +190,7 @@ namespace chaiscript { typedef Boxed_Value& Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { return const_cast(ob); } @@ -246,7 +246,7 @@ namespace chaiscript { typedef typename Cast_Helper_Inner::Result_Type Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *t_conversions) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *t_conversions) { return Cast_Helper_Inner::cast(ob, t_conversions); } diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index f54cd13..557a20a 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -19,7 +19,7 @@ #include "type_info.hpp" namespace chaiscript { -class Dynamic_Cast_Conversions; +class Type_Conversions; } // namespace chaiscript namespace chaiscript @@ -832,7 +832,7 @@ namespace chaiscript { typedef Boxed_Number Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { return Boxed_Number(ob); } diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index b49d14c..b8d4e19 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -141,7 +141,7 @@ namespace chaiscript return *this; } - Module &add(Dynamic_Cast_Conversion d) + Module &add(Type_Conversion d) { m_conversions.push_back(std::move(d)); return *this; @@ -197,7 +197,7 @@ namespace chaiscript std::vector > m_funcs; std::vector > m_globals; std::vector m_evals; - std::vector m_conversions; + std::vector m_conversions; template static void apply(InItr begin, const InItr end, T &t) @@ -300,7 +300,7 @@ namespace chaiscript return arity; } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return std::any_of(m_funcs.cbegin(), m_funcs.cend(), [&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); }); @@ -312,7 +312,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return dispatch::dispatch(m_funcs.cbegin(), m_funcs.cend(), params, t_conversions); } @@ -409,7 +409,7 @@ namespace chaiscript } /// Add a new conversion for upcasting to a base class - void add(const Dynamic_Cast_Conversion &d) + void add(const Type_Conversion &d) { m_conversions.add_conversion(d); } @@ -768,7 +768,7 @@ namespace chaiscript m_state.m_reserved_words.insert(name); } - const Dynamic_Cast_Conversions &conversions() const + const Type_Conversions &conversions() const { return m_conversions; } @@ -1138,7 +1138,7 @@ namespace chaiscript int call_depth; }; - Dynamic_Cast_Conversions m_conversions; + Type_Conversions m_conversions; chaiscript::detail::threading::Thread_Storage m_stack_holder; diff --git a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp index 184246e..9a90e7c 100644 --- a/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp +++ b/include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp @@ -47,34 +47,60 @@ namespace chaiscript }; } - namespace detail + namespace exception { - class Dynamic_Conversion + class bad_boxed_type_cast : public bad_boxed_cast { public: - virtual Boxed_Value convert(const Boxed_Value &derived) const = 0; - virtual Boxed_Value convert_down(const Boxed_Value &base) const = 0; - - const Type_Info &base() const + bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to, + const std::string &t_what) CHAISCRIPT_NOEXCEPT + : bad_boxed_cast(t_from, t_to, t_what) { - return m_base; } - const Type_Info &derived() const + + bad_boxed_type_cast(const Type_Info &t_from, const std::type_info &t_to) CHAISCRIPT_NOEXCEPT + : bad_boxed_cast(t_from, t_to) { - return m_derived; + } + + bad_boxed_type_cast(const std::string &w) CHAISCRIPT_NOEXCEPT + : bad_boxed_cast(w) + { + } + + virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT {} + }; + } + + + namespace detail + { + class Type_Conversion_Base + { + public: + virtual Boxed_Value convert(const Boxed_Value &from) const = 0; + virtual Boxed_Value convert_down(const Boxed_Value &to) const = 0; + + const Type_Info &to() const + { + return m_to; + } + const Type_Info &from() const + { + return m_from; } protected: - Dynamic_Conversion(const Type_Info &t_base, const Type_Info &t_derived) - : m_base(t_base), m_derived(t_derived) + Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from) + : m_to(t_to), m_from(t_from) { } - virtual ~Dynamic_Conversion() {} + virtual ~Type_Conversion_Base() {} private: - Type_Info m_base; - Type_Info m_derived; + Type_Info m_to; + Type_Info m_from; }; @@ -130,11 +156,11 @@ namespace chaiscript }; template - class Dynamic_Conversion_Impl : public Dynamic_Conversion + class Dynamic_Conversion_Impl : public Type_Conversion_Base { public: Dynamic_Conversion_Impl() - : Dynamic_Conversion(user_type(), user_type()) + : Type_Conversion_Base(user_type(), user_type()) { } @@ -150,94 +176,94 @@ namespace chaiscript }; } - class Dynamic_Cast_Conversions + class Type_Conversions { public: - Dynamic_Cast_Conversions() + Type_Conversions() { } - Dynamic_Cast_Conversions(const Dynamic_Cast_Conversions &t_other) + Type_Conversions(const Type_Conversions &t_other) : m_conversions(t_other.get_conversions()) { } - void add_conversion(const std::shared_ptr &conversion) + void add_conversion(const std::shared_ptr &conversion) { chaiscript::detail::threading::unique_lock l(m_mutex); m_conversions.insert(conversion); } - template - bool dynamic_cast_converts() const + template + bool converts() const { - return dynamic_cast_converts(user_type(), user_type()); + return converts(user_type(), user_type()); } - bool dynamic_cast_converts(const Type_Info &base, const Type_Info &derived) const + bool converts(const Type_Info &to, const Type_Info &from) const { - return has_conversion(base, derived) || has_conversion(derived, base); + return has_conversion(to, from) || has_conversion(from, to); } - template - Boxed_Value boxed_dynamic_cast(const Boxed_Value &derived) const + template + Boxed_Value boxed_type_conversion(const Boxed_Value &from) const { try { - return get_conversion(user_type(), derived.get_type_info())->convert(derived); + return get_conversion(user_type(), from.get_type_info())->convert(from); } catch (const std::out_of_range &) { - throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "No known conversion"); + throw exception::bad_boxed_dynamic_cast(from.get_type_info(), typeid(To), "No known conversion"); } catch (const std::bad_cast &) { - throw exception::bad_boxed_dynamic_cast(derived.get_type_info(), typeid(Base), "Unable to perform dynamic_cast operation"); + throw exception::bad_boxed_dynamic_cast(from.get_type_info(), typeid(To), "Unable to perform dynamic_cast operation"); } } - template - Boxed_Value boxed_dynamic_down_cast(const Boxed_Value &base) const + template + Boxed_Value boxed_type_down_conversion(const Boxed_Value &to) const { try { - return get_conversion(base.get_type_info(), user_type())->convert_down(base); + return get_conversion(to.get_type_info(), user_type())->convert_down(to); } catch (const std::out_of_range &) { - throw exception::bad_boxed_dynamic_cast(base.get_type_info(), typeid(Derived), "No known conversion"); + throw exception::bad_boxed_dynamic_cast(to.get_type_info(), typeid(From), "No known conversion"); } catch (const std::bad_cast &) { - throw exception::bad_boxed_dynamic_cast(base.get_type_info(), typeid(Derived), "Unable to perform dynamic_cast operation"); + throw exception::bad_boxed_dynamic_cast(to.get_type_info(), typeid(From), "Unable to perform dynamic_cast operation"); } } - bool has_conversion(const Type_Info &base, const Type_Info &derived) const + bool has_conversion(const Type_Info &to, const Type_Info &from) const { chaiscript::detail::threading::shared_lock l(m_mutex); - return find(base, derived) != m_conversions.end(); + return find(to, from) != m_conversions.end(); } - std::shared_ptr get_conversion(const Type_Info &base, const Type_Info &derived) const + std::shared_ptr get_conversion(const Type_Info &to, const Type_Info &from) const { chaiscript::detail::threading::shared_lock l(m_mutex); auto itr = - find(base, derived); + find(to, from); if (itr != m_conversions.end()) { return *itr; } else { - throw std::out_of_range("No such conversion exists from " + derived.bare_name() + " to " + base.bare_name()); + throw std::out_of_range("No such conversion exists from " + from.bare_name() + " to " + to.bare_name()); } } private: - std::set >::const_iterator find( - const Type_Info &base, const Type_Info &derived) const + std::set >::const_iterator find( + const Type_Info &to, const Type_Info &from) const { return std::find_if(m_conversions.begin(), m_conversions.end(), - [&base, &derived](const std::shared_ptr &conversion) + [&to, &from](const std::shared_ptr &conversion) { - return conversion->base().bare_equal(base) && conversion->derived().bare_equal(derived); + return conversion->to().bare_equal(to) && conversion->from().bare_equal(from); } ); } - std::set > get_conversions() const + std::set> get_conversions() const { chaiscript::detail::threading::shared_lock l(m_mutex); @@ -245,19 +271,19 @@ namespace chaiscript } mutable chaiscript::detail::threading::shared_mutex m_mutex; - std::set > m_conversions; + std::set> m_conversions; }; - typedef std::shared_ptr Dynamic_Cast_Conversion; + typedef std::shared_ptr Type_Conversion; - /// \brief Used to register a base / parent class relationship with ChaiScript. Necessary if you + /// \brief Used to register a to / parent class relationship with ChaiScript. Necessary if you /// want automatic conversions up your inheritance hierarchy. /// - /// Create a new base class registration for applying to a module or to the ChaiScript engine + /// Create a new to class registration for applying to a module or to the ChaiScript engine /// Currently, due to limitations in module loading on Windows, and for the sake of portability, /// if you have a type that is introduced in a loadable module and is used by multiple modules /// (through a tertiary dll that is shared between the modules, static linking the new type - /// into both loadable modules would not be portable), you need to register the base type + /// into both loadable modules would not be portable), you need to register the to type /// relationship in all modules that use the newly added type in a polymorphic way. /// /// Example: @@ -268,11 +294,11 @@ namespace chaiscript /// {}; /// /// chaiscript::ChaiScript chai; - /// chai.add(chaiscript::base_class()); + /// chai.add(chaiscript::to_class()); /// \endcode /// template - Dynamic_Cast_Conversion base_class() + Type_Conversion base_class() { //Can only be used with related polymorphic types //may be expanded some day to support conversions other than child -> parent @@ -280,7 +306,7 @@ namespace chaiscript static_assert(std::is_polymorphic::value, "Base class must be polymorphic"); static_assert(std::is_polymorphic::value, "Derived class must be polymorphic"); - return std::shared_ptr(new detail::Dynamic_Conversion_Impl()); + return std::shared_ptr(new detail::Dynamic_Conversion_Impl()); } } diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 5c93240..93ffd26 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -23,7 +23,7 @@ #include "type_info.hpp" namespace chaiscript { -class Dynamic_Cast_Conversions; +class Type_Conversions; namespace dispatch { class Proxy_Function_Base; } // namespace dispatch @@ -106,7 +106,7 @@ namespace chaiscript } } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { if (dynamic_object_typename_match(vals, m_type_name, m_ti, t_conversions)) { @@ -134,7 +134,7 @@ namespace chaiscript protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { if (dynamic_object_typename_match(params, m_type_name, m_ti, t_conversions)) { @@ -144,7 +144,7 @@ namespace chaiscript } } - virtual bool compare_first_type(const Boxed_Value &bv, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return dynamic_object_typename_match(bv, m_type_name, m_ti, t_conversions); } @@ -162,7 +162,7 @@ namespace chaiscript } bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name, - const std::unique_ptr &ti, const Dynamic_Cast_Conversions &t_conversions) const + const std::unique_ptr &ti, const Type_Conversions &t_conversions) const { if (bv.get_type_info().bare_equal(m_doti)) { @@ -184,7 +184,7 @@ namespace chaiscript } bool dynamic_object_typename_match(const std::vector &bvs, const std::string &name, - const std::unique_ptr &ti, const Dynamic_Cast_Conversions &t_conversions) const + const std::unique_ptr &ti, const Type_Conversions &t_conversions) const { if (bvs.size() > 0) { @@ -248,7 +248,7 @@ namespace chaiscript } } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { std::vector new_vals{Boxed_Value(Dynamic_Object(m_type_name))}; new_vals.insert(new_vals.end(), vals.begin(), vals.end()); @@ -269,7 +269,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { auto bv = var(Dynamic_Object(m_type_name)); std::vector new_params{bv}; diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index 66ce0d6..a434f07 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -18,7 +18,7 @@ namespace chaiscript { class Boxed_Value; -class Dynamic_Cast_Conversions; +class Type_Conversions; namespace detail { template struct Cast_Helper; } // namespace detail @@ -36,7 +36,7 @@ namespace chaiscript /// \param[in] funcs the set of functions to dispatch on. template std::function - functor(const std::vector &funcs, const Dynamic_Cast_Conversions *t_conversions) + functor(const std::vector &funcs, const Type_Conversions *t_conversions) { FunctionType *p=nullptr; return detail::build_function_caller_helper(p, funcs, t_conversions); @@ -55,7 +55,7 @@ namespace chaiscript /// \param[in] func A function to execute. template std::function - functor(Const_Proxy_Function func, const Dynamic_Cast_Conversions *t_conversions) + functor(Const_Proxy_Function func, const Type_Conversions *t_conversions) { return functor(std::vector({func}), t_conversions); } @@ -64,7 +64,7 @@ namespace chaiscript /// and creating a typesafe C++ function caller from it. template std::function - functor(const Boxed_Value &bv, const Dynamic_Cast_Conversions *t_conversions) + functor(const Boxed_Value &bv, const Type_Conversions *t_conversions) { return functor(boxed_cast(bv, t_conversions), t_conversions); } @@ -77,7 +77,7 @@ namespace chaiscript { typedef std::function Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *t_conversions) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *t_conversions) { if (ob.get_type_info().bare_equal(user_type())) { @@ -94,7 +94,7 @@ namespace chaiscript { typedef std::function Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *t_conversions) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *t_conversions) { if (ob.get_type_info().bare_equal(user_type())) { @@ -111,7 +111,7 @@ namespace chaiscript { typedef std::function Result_Type; - static Result_Type cast(const Boxed_Value &ob, const Dynamic_Cast_Conversions *t_conversions) + static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *t_conversions) { if (ob.get_type_info().bare_equal(user_type())) { diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index f3c012b..2da9b7b 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -32,7 +32,7 @@ namespace chaiscript struct Function_Caller_Ret { static Ret call(const std::vector &t_funcs, - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + const std::vector ¶ms, const Type_Conversions &t_conversions) { return boxed_cast(dispatch::dispatch(t_funcs, params, t_conversions)); } @@ -45,7 +45,7 @@ namespace chaiscript struct Function_Caller_Ret { static Ret call(const std::vector &t_funcs, - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + const std::vector ¶ms, const Type_Conversions &t_conversions) { return Boxed_Number(dispatch::dispatch(t_funcs, params, t_conversions)).get_as(); } @@ -59,7 +59,7 @@ namespace chaiscript struct Function_Caller_Ret { static void call(const std::vector &t_funcs, - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + const std::vector ¶ms, const Type_Conversions &t_conversions) { dispatch::dispatch(t_funcs, params, t_conversions); } @@ -71,7 +71,7 @@ namespace chaiscript template struct Build_Function_Caller_Helper { - Build_Function_Caller_Helper(std::vector t_funcs, const Dynamic_Cast_Conversions &t_conversions) + Build_Function_Caller_Helper(std::vector t_funcs, const Type_Conversions &t_conversions) : m_funcs(std::move(t_funcs)), m_conversions(t_conversions) { @@ -88,13 +88,13 @@ namespace chaiscript } std::vector m_funcs; - Dynamic_Cast_Conversions m_conversions; + Type_Conversions m_conversions; }; template - std::function build_function_caller_helper(Ret (Params...), const std::vector &funcs, const Dynamic_Cast_Conversions *t_conversions) + std::function build_function_caller_helper(Ret (Params...), const std::vector &funcs, const Type_Conversions *t_conversions) { if (funcs.size() == 1) { @@ -110,7 +110,7 @@ namespace chaiscript // we cannot make any other guesses or assumptions really, so continuing } - return std::function(Build_Function_Caller_Helper(funcs, t_conversions?*t_conversions:Dynamic_Cast_Conversions())); + return std::function(Build_Function_Caller_Helper(funcs, t_conversions?*t_conversions:Type_Conversions())); } } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 16ceaf8..a0cd4b8 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -26,7 +26,7 @@ #include "type_info.hpp" namespace chaiscript { -class Dynamic_Cast_Conversions; +class Type_Conversions; namespace exception { class bad_boxed_cast; struct arity_error; @@ -55,7 +55,7 @@ namespace chaiscript public: virtual ~Proxy_Function_Base() {} - Boxed_Value operator()(const std::vector ¶ms, const chaiscript::Dynamic_Cast_Conversions &t_conversions) const + Boxed_Value operator()(const std::vector ¶ms, const chaiscript::Type_Conversions &t_conversions) const { Boxed_Value bv = do_call(params, t_conversions); return bv; @@ -68,7 +68,7 @@ namespace chaiscript const std::vector &get_param_types() const { return m_types; } virtual bool operator==(const Proxy_Function_Base &) const = 0; - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const = 0; + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const = 0; bool has_arithmetic_param() const { @@ -82,7 +82,7 @@ namespace chaiscript //! Return true if the function is a possible match //! to the passed in values - bool filter(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const + bool filter(const std::vector &vals, const Type_Conversions &t_conversions) const { int arity = get_arity(); @@ -106,7 +106,7 @@ namespace chaiscript virtual std::string annotation() const = 0; - static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Dynamic_Cast_Conversions &t_conversions) + static bool compare_type_to_param(const Type_Info &ti, const Boxed_Value &bv, const Type_Conversions &t_conversions) { if (ti.is_undef() || ti.bare_equal(user_type()) @@ -114,7 +114,7 @@ namespace chaiscript && (ti.bare_equal(user_type()) || ti.bare_equal(bv.get_type_info()) || bv.get_type_info().bare_equal(user_type >()) - || t_conversions.dynamic_cast_converts(ti, bv.get_type_info()) + || t_conversions.converts(ti, bv.get_type_info()) ) ) ) @@ -125,7 +125,7 @@ namespace chaiscript } } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const = 0; + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const = 0; Proxy_Function_Base(std::vector t_types) : m_types(std::move(t_types)), m_has_arithmetic_param(false) @@ -141,7 +141,7 @@ namespace chaiscript } - virtual bool compare_first_type(const Boxed_Value &bv, const Dynamic_Cast_Conversions &t_conversions) const + virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions &t_conversions) const { const std::vector &types = get_param_types(); @@ -233,7 +233,7 @@ namespace chaiscript && !this->m_guard && !prhs->m_guard); } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return (m_arity < 0 || vals.size() == size_t(m_arity)) && test_guard(vals, t_conversions); @@ -260,7 +260,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { if (m_arity < 0 || params.size() == size_t(m_arity)) { @@ -278,7 +278,7 @@ namespace chaiscript } private: - bool test_guard(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const + bool test_guard(const std::vector ¶ms, const Type_Conversions &t_conversions) const { if (m_guard) { @@ -351,7 +351,7 @@ namespace chaiscript virtual ~Bound_Function() {} - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return m_f->call_match(build_param_list(vals), t_conversions); } @@ -429,7 +429,7 @@ namespace chaiscript return retval; } - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return (*m_f)(build_param_list(params), t_conversions); } @@ -460,7 +460,7 @@ namespace chaiscript return ""; } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { if (int(vals.size()) != get_arity()) { @@ -470,7 +470,7 @@ namespace chaiscript return compare_types(m_types, vals) || compare_types_with_cast(vals, t_conversions); } - virtual bool compare_types_with_cast(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const = 0; + virtual bool compare_types_with_cast(const std::vector &vals, const Type_Conversions &t_conversions) const = 0; }; /** @@ -490,7 +490,7 @@ namespace chaiscript virtual ~Proxy_Function_Impl() {} - virtual bool compare_types_with_cast(const std::vector &vals, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual bool compare_types_with_cast(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return detail::compare_types_cast(m_dummy_func, vals, t_conversions); } @@ -506,7 +506,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const { return detail::Do_Call::result_type>::go(m_f, params, t_conversions); } @@ -549,7 +549,7 @@ namespace chaiscript return 1; } - virtual bool call_match(const std::vector &vals, const Dynamic_Cast_Conversions &) const CHAISCRIPT_OVERRIDE + virtual bool call_match(const std::vector &vals, const Type_Conversions &) const CHAISCRIPT_OVERRIDE { if (vals.size() != 1) { @@ -565,7 +565,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { if (params.size() == 1) { @@ -622,7 +622,7 @@ namespace chaiscript { template bool types_match_except_for_arithmetic(const FuncType &t_func, const std::vector &plist, - const Dynamic_Cast_Conversions &t_conversions) + const Type_Conversions &t_conversions) { if (t_func->get_arity() != static_cast(plist.size())) { @@ -650,7 +650,7 @@ namespace chaiscript template Boxed_Value dispatch_with_conversions(InItr begin, const InItr &end, const std::vector &plist, - const Dynamic_Cast_Conversions &t_conversions) + const Type_Conversions &t_conversions) { InItr orig(begin); @@ -714,7 +714,7 @@ namespace chaiscript */ template Boxed_Value dispatch(InItr begin, const InItr &end, - const std::vector &plist, const Dynamic_Cast_Conversions &t_conversions) + const std::vector &plist, const Type_Conversions &t_conversions) { InItr orig(begin); while (begin != end) @@ -745,7 +745,7 @@ namespace chaiscript */ template Boxed_Value dispatch(const Funcs &funcs, - const std::vector &plist, const Dynamic_Cast_Conversions &t_conversions) + const std::vector &plist, const Type_Conversions &t_conversions) { return dispatch::dispatch(funcs.begin(), funcs.end(), plist, t_conversions); } diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index b908d1f..744d40b 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -20,7 +20,7 @@ #include "type_info.hpp" namespace chaiscript { -class Dynamic_Cast_Conversions; +class Type_Conversions; namespace exception { class bad_boxed_cast; } // namespace exception @@ -72,7 +72,7 @@ namespace chaiscript template struct Try_Cast { - static void do_try(const std::vector ¶ms, int generation, const Dynamic_Cast_Conversions &t_conversions) + static void do_try(const std::vector ¶ms, int generation, const Type_Conversions &t_conversions) { boxed_cast(params[generation], &t_conversions); Try_Cast::do_try(params, generation+1, t_conversions); @@ -83,7 +83,7 @@ namespace chaiscript template<> struct Try_Cast<> { - static void do_try(const std::vector &, int, const Dynamic_Cast_Conversions &) + static void do_try(const std::vector &, int, const Type_Conversions &) { } }; @@ -96,7 +96,7 @@ namespace chaiscript */ template bool compare_types_cast(Ret (*)(Params...), - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + const std::vector ¶ms, const Type_Conversions &t_conversions) { try { Try_Cast::do_try(params, 0, t_conversions); @@ -113,7 +113,7 @@ namespace chaiscript template static Ret do_call(const std::function &f, - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams) + const std::vector ¶ms, const Type_Conversions &t_conversions, InnerParams &&... innerparams) { return Call_Func::do_call(f, params, t_conversions, std::forward(innerparams)..., params[sizeof...(Params) - count]); } @@ -128,7 +128,7 @@ namespace chaiscript #endif template static Ret do_call(const std::function &f, - const std::vector &, const Dynamic_Cast_Conversions &t_conversions, InnerParams &&... innerparams) + const std::vector &, const Type_Conversions &t_conversions, InnerParams &&... innerparams) { return f(boxed_cast(std::forward(innerparams), &t_conversions)...); } @@ -145,7 +145,7 @@ namespace chaiscript */ template Ret call_func(const std::function &f, - const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + const std::vector ¶ms, const Type_Conversions &t_conversions) { if (params.size() == sizeof...(Params)) { @@ -171,7 +171,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const std::function &fun, const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms, const Type_Conversions &t_conversions) { return Handle_Return::handle(call_func(fun, params, t_conversions)); } @@ -181,7 +181,7 @@ namespace chaiscript struct Do_Call { template - static Boxed_Value go(const std::function &fun, const std::vector ¶ms, const Dynamic_Cast_Conversions &t_conversions) + static Boxed_Value go(const std::function &fun, const std::vector ¶ms, const Type_Conversions &t_conversions) { call_func(fun, params, t_conversions); return Handle_Return::handle(); diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 539157c..b476d29 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -679,7 +679,7 @@ namespace chaiscript /// chaiscript::ChaiScript chai; /// chai.add(chaiscript::base_class()); /// \endcode - ChaiScript &add(const Dynamic_Cast_Conversion &d) + ChaiScript &add(const Type_Conversion &d) { m_engine.add(d); return *this;