Minor reorg of type conversion code to support move to using it in dispatch
This commit is contained in:
@@ -220,7 +220,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
std::multimap<std::string, Proxy_Function> m_functions;
|
std::multimap<std::string, Proxy_Function> m_functions;
|
||||||
std::map<std::string, Boxed_Value> m_global_objects;
|
std::map<std::string, Boxed_Value> m_global_objects;
|
||||||
std::map<std::pair<Type_Info, Type_Info>, Type_Conversion> m_type_conversions;
|
Type_Converter m_type_converter;
|
||||||
Type_Name_Map m_types;
|
Type_Name_Map m_types;
|
||||||
std::set<std::string> m_reserved_words;
|
std::set<std::string> m_reserved_words;
|
||||||
};
|
};
|
||||||
@@ -259,7 +259,7 @@ namespace chaiscript
|
|||||||
boost::unique_lock<boost::shared_mutex> l(m_mutex);
|
boost::unique_lock<boost::shared_mutex> l(m_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_state.m_type_conversions.insert(std::make_pair(std::make_pair(tc.from(), tc.to()), tc));
|
m_state.m_type_converter.add(tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -171,6 +171,46 @@ namespace chaiscript
|
|||||||
|
|
||||||
return Type_Conversion(boost::shared_ptr<detail::Type_Conversion_Impl>(new detail::Dynamic_Cast_Conversion<Cleaned_From, Cleaned_To>()));
|
return Type_Conversion(boost::shared_ptr<detail::Type_Conversion_Impl>(new detail::Dynamic_Cast_Conversion<Cleaned_From, Cleaned_To>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Type_Converter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool add(const Type_Conversion &t_tc)
|
||||||
|
{
|
||||||
|
return m_conversions.insert(std::make_pair(std::make_pair(t_tc.from(), t_tc.to()), t_tc)).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty()
|
||||||
|
{
|
||||||
|
return m_conversions.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Boxed_Value convert(const Boxed_Value &t_bv, const Type_Info &t_to) const
|
||||||
|
{
|
||||||
|
if (t_bv.get_type_info().bare_equal(t_to))
|
||||||
|
{
|
||||||
|
return t_bv;
|
||||||
|
} else {
|
||||||
|
std::map<std::pair<Type_Info, Type_Info>, Type_Conversion>::const_iterator itr = m_conversions.begin(),
|
||||||
|
end = m_conversions.end();
|
||||||
|
|
||||||
|
while (itr != end)
|
||||||
|
{
|
||||||
|
if (itr->first.first.bare_equal(t_bv.get_type_info())
|
||||||
|
&& itr->first.second.bare_equal(t_to))
|
||||||
|
{
|
||||||
|
return itr->second.convert(t_bv);
|
||||||
|
}
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw bad_boxed_cast("Unable to convert boxed_value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::pair<Type_Info, Type_Info>, Type_Conversion> m_conversions;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user