Revamped method for bootstrapping of types, using a new Module class that collects everything related to a type or group of types
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
* http://www.sgi.com/tech/stl/table_of_contents.html
|
||||
*/
|
||||
|
||||
#ifndef __bootstrap_stl_hpp
|
||||
#define __bootstrap_stl_hpp__
|
||||
#ifndef __stl_hpp_type
|
||||
#define __stl_hpp___type
|
||||
|
||||
#include "dispatchkit.hpp"
|
||||
#include "register_function.hpp"
|
||||
@@ -74,24 +74,25 @@ namespace chaiscript
|
||||
* Add Input_Range support for the given ContainerType
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_input_range(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr input_range_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(user_type<Input_Range<ContainerType> >(), type + "_Range");
|
||||
system.add(user_type<typename ContainerType::iterator>(), type+"_Iterator");
|
||||
m->add(user_type<Input_Range<ContainerType> >(), type + "_Range");
|
||||
m->add(user_type<typename ContainerType::iterator>(), type+"_Iterator");
|
||||
|
||||
system.add(constructor<Input_Range<ContainerType> (ContainerType &)>(), "range");
|
||||
system.add(constructor<Input_Range<ContainerType> (typename ContainerType::iterator)>(), "range");
|
||||
m->add(constructor<Input_Range<ContainerType> (ContainerType &)>(), "range");
|
||||
m->add(constructor<Input_Range<ContainerType> (typename ContainerType::iterator)>(), "range");
|
||||
|
||||
typedef std::pair<typename ContainerType::iterator, typename ContainerType::iterator> ItrPair;
|
||||
|
||||
system.add(constructor<Input_Range<ContainerType> (const ItrPair &)>(), "range");
|
||||
m->add(constructor<Input_Range<ContainerType> (const ItrPair &)>(), "range");
|
||||
|
||||
system.add(user_type<ItrPair>(), type+"_Iterator_Pair");
|
||||
m->add(user_type<ItrPair>(), type+"_Iterator_Pair");
|
||||
|
||||
system.add(fun(&Input_Range<ContainerType>::empty), "empty");
|
||||
system.add(fun(&Input_Range<ContainerType>::pop_front), "pop_front");
|
||||
system.add(fun(&Input_Range<ContainerType>::front), "front");
|
||||
system.add(constructor<Input_Range<ContainerType> (const Input_Range<ContainerType> &)>(), "clone");
|
||||
m->add(fun(&Input_Range<ContainerType>::empty), "empty");
|
||||
m->add(fun(&Input_Range<ContainerType>::pop_front), "pop_front");
|
||||
m->add(fun(&Input_Range<ContainerType>::front), "front");
|
||||
m->add(constructor<Input_Range<ContainerType> (const Input_Range<ContainerType> &)>(), "clone");
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,8 +100,9 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/ReversibleContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_reversible_container(Dispatch_Engine &/*system*/, const std::string &/*type*/)
|
||||
ModulePtr reversible_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,18 +110,19 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/RandomAccessContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_random_access_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr random_access_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_reversible_container<ContainerType>(system, type);
|
||||
reversible_container_type<ContainerType>(type, m);
|
||||
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
|
||||
|
||||
//In the interest of runtime safety for the system, we prefer the at() method for [] access,
|
||||
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
|
||||
//to throw an exception in an out of bounds condition.
|
||||
system.add(
|
||||
m->add(
|
||||
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::at))), "[]");
|
||||
system.add(
|
||||
m->add(
|
||||
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::operator[]))), "at");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,10 +130,11 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Assignable.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_assignable(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr assignable_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
add_basic_constructors<ContainerType>(system, type);
|
||||
add_oper_assign<ContainerType>(system);
|
||||
add_basic_constructors<ContainerType>(type, m);
|
||||
add_oper_assign<ContainerType>(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,13 +142,15 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Container.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_assignable<ContainerType>(system, type);
|
||||
assignable_type<ContainerType>(type, m);
|
||||
|
||||
system.add(fun(&ContainerType::size), "size");
|
||||
system.add(fun(&ContainerType::max_size), "max_size");
|
||||
system.add(fun(&ContainerType::empty), "empty");
|
||||
m->add(fun(&ContainerType::size), "size");
|
||||
m->add(fun(&ContainerType::max_size), "max_size");
|
||||
m->add(fun(&ContainerType::empty), "empty");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,10 +158,12 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/ForwardContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_forward_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr forward_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_input_range<ContainerType>(system, type);
|
||||
bootstrap_container<ContainerType>(system, type);
|
||||
input_range_type<ContainerType>(type, m);
|
||||
container_type<ContainerType>(type, m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,9 +171,10 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/DefaultConstructible.html
|
||||
*/
|
||||
template<typename Type>
|
||||
void bootstrap_default_constructible(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr default_constructible_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(constructor<Type ()>(), type);
|
||||
m->add(constructor<Type ()>(), type);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,10 +218,10 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Sequence.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_sequence(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr sequence_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_forward_container<ContainerType>(system, type);
|
||||
bootstrap_default_constructible<ContainerType>(system, type);
|
||||
forward_container_type<ContainerType>(type, m);
|
||||
default_constructible_type<ContainerType>(type, m);
|
||||
|
||||
std::string insert_name;
|
||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
|
||||
@@ -222,8 +231,10 @@ namespace chaiscript
|
||||
insert_name = "insert_at";
|
||||
}
|
||||
|
||||
system.add(fun(&insert_at<ContainerType>), insert_name);
|
||||
system.add(fun(&erase_at<ContainerType>), "erase_at");
|
||||
m->add(fun(&insert_at<ContainerType>), insert_name);
|
||||
m->add(fun(&erase_at<ContainerType>), "erase_at");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,14 +242,14 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/BackInsertionSequence.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_back_insertion_sequence(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr back_insertion_sequence_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_sequence<ContainerType>(system, type);
|
||||
sequence_type<ContainerType>(type, m);
|
||||
|
||||
|
||||
typedef typename ContainerType::reference (ContainerType::*backptr)();
|
||||
|
||||
system.add(fun(backptr(&ContainerType::back)), "back");
|
||||
m->add(fun(backptr(&ContainerType::back)), "back");
|
||||
|
||||
std::string push_back_name;
|
||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
|
||||
@@ -248,8 +259,9 @@ namespace chaiscript
|
||||
push_back_name = "push_back";
|
||||
}
|
||||
|
||||
system.add(fun(&ContainerType::push_back), push_back_name);
|
||||
system.add(fun(&ContainerType::pop_back), "pop_back");
|
||||
m->add(fun(&ContainerType::push_back), push_back_name);
|
||||
m->add(fun(&ContainerType::pop_back), "pop_back");
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,11 +269,12 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Vector.html
|
||||
*/
|
||||
template<typename VectorType>
|
||||
void bootstrap_vector(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr vector_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(user_type<VectorType>(), type);
|
||||
bootstrap_random_access_container<VectorType>(system, type);
|
||||
bootstrap_back_insertion_sequence<VectorType>(system, type);
|
||||
m->add(user_type<VectorType>(), type);
|
||||
random_access_container_type<VectorType>(type, m);
|
||||
back_insertion_sequence_type<VectorType>(type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,10 +282,11 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Vector.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_forward_container<ContainerType>(system, type);
|
||||
bootstrap_default_constructible<ContainerType>(system, type);
|
||||
forward_container_type<ContainerType>(type, m);
|
||||
default_constructible_type<ContainerType>(type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,18 +294,20 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/pair.html
|
||||
*/
|
||||
template<typename PairType>
|
||||
void bootstrap_pair(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr pair_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(user_type<PairType>(), type);
|
||||
m->add(user_type<PairType>(), type);
|
||||
|
||||
system.add(fun(&PairType::first), "first");
|
||||
system.add(fun(&PairType::second), "second");
|
||||
m->add(fun(&PairType::first), "first");
|
||||
m->add(fun(&PairType::second), "second");
|
||||
|
||||
system.add(constructor<PairType ()>(), type);
|
||||
system.add(constructor<PairType (const PairType &)>(), type);
|
||||
system.add(constructor<PairType (const PairType &)>(), "clone");
|
||||
system.add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
||||
}
|
||||
m->add(constructor<PairType ()>(), type);
|
||||
m->add(constructor<PairType (const PairType &)>(), type);
|
||||
m->add(constructor<PairType (const PairType &)>(), "clone");
|
||||
m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -299,10 +315,12 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/PairAssociativeContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_pair_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
bootstrap_pair<typename ContainerType::value_type>(system, type + "_Pair");
|
||||
associative_container_type<ContainerType>(type, m);
|
||||
pair_type<typename ContainerType::value_type>(type + "_Pair", m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -310,10 +328,12 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_unique_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr unique_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
system.add(fun(&ContainerType::count), "count");
|
||||
associative_container_type<ContainerType>(type, m);
|
||||
m->add(fun(&ContainerType::count), "count");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,14 +341,16 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/SortedAssociativeContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_sorted_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr sorted_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
typedef std::pair<typename ContainerType::iterator, typename ContainerType::iterator>
|
||||
(ContainerType::*eq_range)(const typename ContainerType::key_type &);
|
||||
|
||||
bootstrap_reversible_container<ContainerType>(system, type);
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
system.add(fun(eq_range(&ContainerType::equal_range)), "equal_range");
|
||||
reversible_container_type<ContainerType>(type, m);
|
||||
associative_container_type<ContainerType>(type, m);
|
||||
m->add(fun(eq_range(&ContainerType::equal_range)), "equal_range");
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,10 +358,12 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/UniqueSortedAssociativeContainer.html
|
||||
*/
|
||||
template<typename ContainerType>
|
||||
void bootstrap_unique_sorted_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr unique_sorted_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
bootstrap_sorted_associative_container<ContainerType>(system, type);
|
||||
bootstrap_unique_associative_container<ContainerType>(system, type);
|
||||
sorted_associative_container_type<ContainerType>(type, m);
|
||||
unique_associative_container_type<ContainerType>(type, m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,12 +371,14 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/Map.html
|
||||
*/
|
||||
template<typename MapType>
|
||||
void bootstrap_map(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(user_type<MapType>(), type);
|
||||
system.add(fun(&MapType::operator[]), "[]");
|
||||
bootstrap_unique_sorted_associative_container<MapType>(system, type);
|
||||
bootstrap_pair_associative_container<MapType>(system, type);
|
||||
m->add(user_type<MapType>(), type);
|
||||
m->add(fun(&MapType::operator[]), "[]");
|
||||
unique_sorted_associative_container_type<MapType>(type, m);
|
||||
pair_associative_container_type<MapType>(type, m);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,21 +386,23 @@ namespace chaiscript
|
||||
* http://www.sgi.com/tech/stl/basic_string.html
|
||||
*/
|
||||
template<typename String>
|
||||
void bootstrap_string(Dispatch_Engine &system, const std::string &type)
|
||||
ModulePtr string_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||
{
|
||||
system.add(user_type<String>(), type);
|
||||
add_oper_add<String>(system);
|
||||
add_oper_add_equals<String>(system);
|
||||
add_opers_comparison<String>(system);
|
||||
bootstrap_random_access_container<String>(system, type);
|
||||
bootstrap_sequence<String>(system, type);
|
||||
m->add(user_type<String>(), type);
|
||||
add_oper_add<String>(m);
|
||||
add_oper_add_equals<String>(m);
|
||||
add_opers_comparison<String>(m);
|
||||
random_access_container_type<String>(type, m);
|
||||
sequence_type<String>(type, m);
|
||||
typedef typename String::size_type (String::*find_func)(const String &, typename String::size_type) const;
|
||||
system.add(fun(find_func(&String::find)), "find");
|
||||
system.add(fun(find_func(&String::rfind)), "rfind");
|
||||
system.add(fun(find_func(&String::find_first_of)), "find_first_of");
|
||||
system.add(fun(find_func(&String::find_last_of)), "find_last_of");
|
||||
system.add(fun(find_func(&String::find_first_not_of)), "find_first_not_of");
|
||||
system.add(fun(find_func(&String::find_last_not_of)), "find_last_not_of");
|
||||
m->add(fun(find_func(&String::find)), "find");
|
||||
m->add(fun(find_func(&String::rfind)), "rfind");
|
||||
m->add(fun(find_func(&String::find_first_of)), "find_first_of");
|
||||
m->add(fun(find_func(&String::find_last_of)), "find_last_of");
|
||||
m->add(fun(find_func(&String::find_first_not_of)), "find_first_not_of");
|
||||
m->add(fun(find_func(&String::find_last_not_of)), "find_last_not_of");
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user