diff --git a/dispatchkit/bootstrap.hpp b/dispatchkit/bootstrap.hpp index 7be961e1..cb3379e3 100644 --- a/dispatchkit/bootstrap.hpp +++ b/dispatchkit/bootstrap.hpp @@ -457,6 +457,15 @@ namespace dispatchkit return l.get_type_info() == r.get_type_info(); } + static bool is_type(const Dispatch_Engine &e, const std::string &type_name, Boxed_Value r) + { + try { + return e.get_type(type_name) == r.get_type_info(); + } catch (const std::range_error &) { + return false; + } + } + static Boxed_Value bind_function(const std::vector ¶ms) { if (params.size() < 2) @@ -488,6 +497,8 @@ namespace dispatchkit s.register_type("string"); + s.register_type("function"); + add_basic_constructors(s, "bool"); add_basic_constructors(s, "string"); add_oper_assign(s); @@ -516,6 +527,8 @@ namespace dispatchkit s.register_function(boost::function(boost::bind(&dump_system, boost::ref(s))), "dump_system"); s.register_function(boost::function(boost::bind(&dump_object, _1)), "dump_object"); + s.register_function(boost::function(boost::bind(&is_type, s, _1, _2)), + "is_type"); s.add_object("_", Placeholder_Object()); diff --git a/dispatchkit/dispatchkit.hpp b/dispatchkit/dispatchkit.hpp index c428f6f6..c4420a34 100644 --- a/dispatchkit/dispatchkit.hpp +++ b/dispatchkit/dispatchkit.hpp @@ -169,6 +169,17 @@ namespace dispatchkit m_types.insert(std::make_pair(name, Get_Type_Info::get())); } + Type_Info get_type(const std::string &name) const + { + Type_Name_Map::const_iterator itr = m_types.find(name); + if (itr != m_types.end()) + { + return itr->second; + } else { + throw std::range_error("Type Not Known"); + } + } + std::vector get_types() const { return std::vector(m_types.begin(), m_types.end());