Stub in of support for type conversions. Not yet fully implemented.

This commit is contained in:
Jason Turner
2010-07-17 21:49:27 +00:00
parent 3f9b5081c6
commit 35ac7342b6
4 changed files with 263 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
#include "boxed_value.hpp"
#include "type_info.hpp"
#include "type_conversion.hpp"
#include "proxy_functions.hpp"
#include "proxy_constructors.hpp"
#include "dynamic_object.hpp"
@@ -43,6 +44,11 @@ namespace chaiscript
return *this;
}
Module &add(const Type_Conversion &tc)
{
m_conversions.push_back(tc);
return *this;
}
//Add a bit of chaiscript to eval during module implementation
Module &eval(const std::string &str)
@@ -62,12 +68,14 @@ namespace chaiscript
{
apply(m_typeinfos.begin(), m_typeinfos.end(), t_engine);
apply(m_funcs.begin(), m_funcs.end(), t_engine);
apply_nameless(m_conversions.begin(), m_conversions.end(), t_engine);
apply_eval(m_evals.begin(), m_evals.end(), t_eval);
}
private:
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
std::vector<Type_Conversion> m_conversions;
std::vector<std::string> m_evals;
template<typename T, typename InItr>
@@ -80,6 +88,16 @@ namespace chaiscript
}
}
template<typename T, typename InItr>
void apply_nameless(InItr begin, InItr end, T &t) const
{
while (begin != end)
{
t.add(*begin);
++begin;
}
}
template<typename T, typename InItr>
void apply_eval(InItr begin, InItr end, T &t) const
{
@@ -202,6 +220,7 @@ namespace chaiscript
{
std::multimap<std::string, Proxy_Function> m_functions;
std::map<std::string, Boxed_Value> m_global_objects;
std::map<std::pair<Type_Info, Type_Info>, Type_Conversion> m_type_conversions;
Type_Name_Map m_types;
std::set<std::string> m_reserved_words;
};
@@ -230,6 +249,19 @@ namespace chaiscript
return add_function(f, name);
}
/**
* Add a new type converter to the system
*/
void add(const Type_Conversion &tc)
{
#ifndef CHAISCRIPT_NO_THREADS
boost::unique_lock<boost::shared_mutex> l(m_mutex);
#endif
m_state.m_type_conversions.insert(std::make_pair(std::make_pair(tc.from(), tc.to()), tc));
}
/**
* Set the value of an object, by name. If the object
* is not available in the current scope it is created