From 600899ad77e5110ebf0a14e35276566a9aa92b41 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 11 Jun 2009 00:32:50 +0000 Subject: [PATCH] Initial work towards function variables. Existing dispatch works, but lookup of function variables is still untested --- boxedcpp/boxed_value.hpp | 10 ++++++++++ boxedcpp/boxedcpp.hpp | 18 ++++++++++++++++-- boxedcpp/proxy_functions.hpp | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/boxedcpp/boxed_value.hpp b/boxedcpp/boxed_value.hpp index 4ecbcd2..a15f093 100644 --- a/boxedcpp/boxed_value.hpp +++ b/boxedcpp/boxed_value.hpp @@ -206,6 +206,16 @@ struct Cast_Helper } }; +template +struct Cast_Helper > +{ + typename boost::shared_ptr operator()(Boxed_Value ob) + { + return boost::any_cast >(ob.get()); + } +}; + + template<> struct Cast_Helper { diff --git a/boxedcpp/boxedcpp.hpp b/boxedcpp/boxedcpp.hpp index e742ff8..7f95529 100644 --- a/boxedcpp/boxedcpp.hpp +++ b/boxedcpp/boxedcpp.hpp @@ -116,12 +116,26 @@ class BoxedCPP_System return std::vector(m_types.begin(), m_types.end()); } - std::vector get_function(const std::string &t_name) const + std::vector > + get_function(const std::string &t_name) const { + std::vector > funcs; + + try { + funcs.insert(funcs.end(), + Function_Map::value_type( + t_name, + Cast_Helper()(get_object(t_name))) + ); + } catch (const std::bad_cast &) { + } catch (const std::range_error &) { + } + std::pair range = m_functions.equal_range(t_name); - return std::vector(range.first, range.second); + funcs.insert(funcs.end(), range.first, range.second); + return funcs; } std::vector get_functions() const diff --git a/boxedcpp/proxy_functions.hpp b/boxedcpp/proxy_functions.hpp index 0dc56fa..0645a5d 100644 --- a/boxedcpp/proxy_functions.hpp +++ b/boxedcpp/proxy_functions.hpp @@ -178,10 +178,10 @@ class Proxy_Function_Impl : public Proxy_Function Func m_f; }; -Boxed_Value dispatch(const std::vector > > &funcs, +Boxed_Value dispatch(const std::vector > > &funcs, const std::vector &plist) { - for (std::vector > >::const_iterator itr = funcs.begin(); + for (std::vector > >::const_iterator itr = funcs.begin(); itr != funcs.end(); ++itr) {