Major updates to the C++ API. Please see trunk/src/example.cpp to follow along
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
#include "register_function.hpp"
|
||||
|
||||
|
||||
namespace dispatchkit
|
||||
namespace chaiscript
|
||||
{
|
||||
/**
|
||||
* Input_Range, based on the D concept of ranges.
|
||||
@@ -76,24 +76,22 @@ namespace dispatchkit
|
||||
template<typename ContainerType>
|
||||
void bootstrap_input_range(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<Input_Range<ContainerType> >(type+"_Range");
|
||||
system.register_type<typename ContainerType::iterator>(type+"_Iterator");
|
||||
system.add(type_<Input_Range<ContainerType> >(), type + "_Range");
|
||||
system.add(type_<typename ContainerType::iterator>(), type+"_Iterator");
|
||||
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>, ContainerType &>(), "range");
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>,
|
||||
typename ContainerType::iterator>(), "range");
|
||||
system.add(constructor<Input_Range<ContainerType> (ContainerType &)>(), "range");
|
||||
system.add(constructor<Input_Range<ContainerType> (typename ContainerType::iterator)>(), "range");
|
||||
|
||||
typedef std::pair<typename ContainerType::iterator, typename ContainerType::iterator> ItrPair;
|
||||
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>,
|
||||
const ItrPair &>(), "range");
|
||||
system.register_type<ItrPair>(type+"_Iterator_Pair");
|
||||
system.add(constructor<Input_Range<ContainerType> (const ItrPair &)>(), "range");
|
||||
|
||||
system.add(type_<ItrPair>(), type+"_Iterator_Pair");
|
||||
|
||||
register_function(system, &Input_Range<ContainerType>::empty, "empty");
|
||||
register_function(system, &Input_Range<ContainerType>::pop_front, "pop_front");
|
||||
register_function(system, &Input_Range<ContainerType>::front, "front");
|
||||
system.register_function(build_constructor<Input_Range<ContainerType>, const Input_Range<ContainerType> &>(), "clone");
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +115,10 @@ namespace dispatchkit
|
||||
|
||||
//In the interest of runtime safety for the system, we prefer the at() method for [] access,
|
||||
//to throw an exception in an out of bounds condition.
|
||||
system.register_function(
|
||||
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::at)), "[]");
|
||||
system.register_function(
|
||||
boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::operator[])), "at");
|
||||
system.add(
|
||||
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::at))), "[]");
|
||||
system.add(
|
||||
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(indexoper(&ContainerType::operator[]))), "at");
|
||||
|
||||
}
|
||||
|
||||
@@ -144,9 +142,9 @@ namespace dispatchkit
|
||||
{
|
||||
bootstrap_assignable<ContainerType>(system, type);
|
||||
|
||||
register_function(system, &ContainerType::size, "size");
|
||||
register_function(system, &ContainerType::max_size, "max_size");
|
||||
register_function(system, &ContainerType::empty, "empty");
|
||||
system.add(fun(&ContainerType::size), "size");
|
||||
system.add(fun(&ContainerType::max_size), "max_size");
|
||||
system.add(fun(&ContainerType::empty), "empty");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +165,7 @@ namespace dispatchkit
|
||||
template<typename Type>
|
||||
void bootstrap_default_constructible(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_function(build_constructor<Type>(), type);
|
||||
system.add(constructor<Type ()>(), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,8 +222,8 @@ namespace dispatchkit
|
||||
insert_name = "insert_at";
|
||||
}
|
||||
|
||||
register_function(system, &insert_at<ContainerType>, insert_name);
|
||||
register_function(system, &erase_at<ContainerType>, "erase_at");
|
||||
system.add(fun(&insert_at<ContainerType>), insert_name);
|
||||
system.add(fun(&erase_at<ContainerType>), "erase_at");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,7 +238,7 @@ namespace dispatchkit
|
||||
|
||||
typedef typename ContainerType::reference (ContainerType::*backptr)();
|
||||
|
||||
register_function(system, (backptr(&ContainerType::back)), "back");
|
||||
system.add(fun(backptr(&ContainerType::back)), "back");
|
||||
|
||||
std::string push_back_name;
|
||||
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
|
||||
@@ -250,8 +248,8 @@ namespace dispatchkit
|
||||
push_back_name = "push_back";
|
||||
}
|
||||
|
||||
register_function(system, &ContainerType::push_back, push_back_name);
|
||||
register_function(system, &ContainerType::pop_back, "pop_back");
|
||||
system.add(fun(&ContainerType::push_back), push_back_name);
|
||||
system.add(fun(&ContainerType::pop_back), "pop_back");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +259,7 @@ namespace dispatchkit
|
||||
template<typename VectorType>
|
||||
void bootstrap_vector(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<VectorType>(type);
|
||||
system.add(type_<VectorType>(), type);
|
||||
bootstrap_random_access_container<VectorType>(system, type);
|
||||
bootstrap_back_insertion_sequence<VectorType>(system, type);
|
||||
}
|
||||
@@ -284,15 +282,15 @@ namespace dispatchkit
|
||||
template<typename PairType>
|
||||
void bootstrap_pair(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<PairType>(type);
|
||||
system.add(type_<PairType>(), type);
|
||||
|
||||
register_member(system, &PairType::first, "first");
|
||||
register_member(system, &PairType::second, "second");
|
||||
system.add(fun(&PairType::first), "first");
|
||||
system.add(fun(&PairType::second), "second");
|
||||
|
||||
system.register_function(build_constructor<PairType >(), type);
|
||||
system.register_function(build_constructor<PairType, const PairType &>(), type);
|
||||
system.register_function(build_constructor<PairType, const PairType &>(), "clone");
|
||||
system.register_function(build_constructor<PairType, const typename PairType::first_type &, const typename PairType::second_type &>(), type);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +313,7 @@ namespace dispatchkit
|
||||
void bootstrap_unique_associative_container(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
register_function(system, &ContainerType::count, "count");
|
||||
system.add(fun(&ContainerType::count), "count");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,7 +328,7 @@ namespace dispatchkit
|
||||
|
||||
bootstrap_reversible_container<ContainerType>(system, type);
|
||||
bootstrap_associative_container<ContainerType>(system, type);
|
||||
register_function(system, eq_range(&ContainerType::equal_range), "equal_range");
|
||||
system.add(fun(eq_range(&ContainerType::equal_range)), "equal_range");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,8 +349,8 @@ namespace dispatchkit
|
||||
template<typename MapType>
|
||||
void bootstrap_map(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<MapType>(type);
|
||||
register_function(system, &MapType::operator[], "[]");
|
||||
system.add(type_<MapType>(), type);
|
||||
system.add(fun(&MapType::operator[]), "[]");
|
||||
bootstrap_unique_sorted_associative_container<MapType>(system, type);
|
||||
bootstrap_pair_associative_container<MapType>(system, type);
|
||||
}
|
||||
@@ -364,19 +362,19 @@ namespace dispatchkit
|
||||
template<typename String>
|
||||
void bootstrap_string(Dispatch_Engine &system, const std::string &type)
|
||||
{
|
||||
system.register_type<String>(type);
|
||||
system.add(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);
|
||||
typedef typename String::size_type (String::*find_func)(const String &, typename String::size_type) const;
|
||||
register_function(system, find_func(&String::find), "find");
|
||||
register_function(system, find_func(&String::rfind), "rfind");
|
||||
register_function(system, find_func(&String::find_first_of), "find_first_of");
|
||||
register_function(system, find_func(&String::find_last_of), "find_last_of");
|
||||
register_function(system, find_func(&String::find_first_not_of), "find_first_not_of");
|
||||
register_function(system, find_func(&String::find_last_not_of), "find_last_not_of");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user