17#ifndef CHAISCRIPT_BOOTSTRAP_STL_HPP_
18#define CHAISCRIPT_BOOTSTRAP_STL_HPP_
44 template<
typename Container,
typename IterType>
63 throw std::range_error(
"Range empty");
72 throw std::range_error(
"Range empty");
81 throw std::range_error(
"Range empty");
86 decltype(
auto)
back()
const
90 throw std::range_error(
"Range empty");
104 size_t count(
const T &t_target,
const typename T::key_type &t_key)
106 return t_target.count(t_key);
112 t_target.insert(t_other.begin(), t_other.end());
118 t_target.insert(t_val);
124 template<
typename B
idir_Type>
131 m.
add(
constructor<Bidir_Type (
typename Bidir_Type::container_type &)>(),
"range_internal");
133 m.
add(
fun(&Bidir_Type::empty),
"empty");
134 m.
add(
fun(&Bidir_Type::pop_front),
"pop_front");
135 m.
add(
fun(&Bidir_Type::front),
"front");
136 m.
add(
fun(&Bidir_Type::pop_back),
"pop_back");
137 m.
add(
fun(&Bidir_Type::back),
"back");
142 template<
typename Type>
143 void insert_at(
Type &container,
int pos,
const typename Type::value_type &v)
145 auto itr = container.begin();
146 auto end = container.end();
148 if (pos < 0 || std::distance(itr, end) < pos)
150 throw std::range_error(
"Cannot insert past end of range");
153 std::advance(itr, pos);
154 container.insert(itr, v);
159 template<
typename Type>
162 auto itr = container.begin();
163 auto end = container.end();
165 if (pos < 0 || std::distance(itr, end) < (pos-1))
167 throw std::range_error(
"Cannot erase past end of range");
170 std::advance(itr, pos);
171 container.erase(itr);
175 template<
typename ContainerType>
181 template<
typename ContainerType>
184 auto m = std::make_shared<Module>();
192 template<
typename ContainerType>
199 [](ContainerType &c,
int index) ->
typename ContainerType::reference {
202 return c.at(
static_cast<typename ContainerType::size_type
>(index));
207 [](
const ContainerType &c,
int index) ->
typename ContainerType::const_reference {
210 return c.at(
static_cast<typename ContainerType::size_type
>(index));
213 template<
typename ContainerType>
216 auto m = std::make_shared<Module>();
225 template<
typename ContainerType>
231 template<
typename ContainerType>
234 auto m = std::make_shared<Module>();
242 template<
typename ContainerType>
245 m.
add(
fun([](ContainerType *a,
typename ContainerType::size_type n,
const typename ContainerType::value_type& val) {
return a->resize(n, val); } ),
"resize");
246 m.
add(
fun([](ContainerType *a,
typename ContainerType::size_type n) {
return a->resize(n); } ),
"resize");
248 template<
typename ContainerType>
251 auto m = std::make_shared<Module>();
259 template<
typename ContainerType>
262 m.
add(
fun([](ContainerType *a,
typename ContainerType::size_type n) {
return a->reserve(n); } ),
"reserve");
263 m.
add(
fun([](
const ContainerType *a) {
return a->capacity(); } ),
"capacity");
265 template<
typename ContainerType>
268 auto m = std::make_shared<Module>();
276 template<
typename ContainerType>
279 m.
add(
fun([](
const ContainerType *a) {
return a->size(); } ),
"size");
280 m.
add(
fun([](
const ContainerType *a) {
return a->empty(); } ),
"empty");
281 m.
add(
fun([](ContainerType *a) { a->clear(); } ),
"clear");
283 template <
typename ContainerType>
286 auto m = std::make_shared<Module>();
294 template<
typename Type>
299 template <
typename Type>
302 auto m = std::make_shared<Module>();
311 template<
typename ContainerType>
316 if (
typeid(
typename ContainerType::value_type) ==
typeid(
Boxed_Value)) {
317 return "insert_ref_at";
325 template <
typename ContainerType>
328 auto m = std::make_shared<Module>();
335 template<
typename ContainerType>
338 m.
add(
fun([](ContainerType &container)->
decltype(
auto){
339 if (container.empty()) {
340 throw std::range_error(
"Container empty");
342 return (container.back());
347 m.
add(
fun([](
const ContainerType &container)->
decltype(
auto){
348 if (container.empty()) {
349 throw std::range_error(
"Container empty");
351 return (container.back());
358 typedef void (ContainerType::*push_back)(
const typename ContainerType::value_type &);
359 m.
add(
fun(
static_cast<push_back
>(&ContainerType::push_back)),
361 if (
typeid(
typename ContainerType::value_type) ==
typeid(
Boxed_Value)) {
363 "# Pushes the second value onto the container while making a clone of the value\n"
364 "def push_back(" + type +
" container, x)\n"
366 " if (x.is_var_return_value()) {\n"
367 " x.reset_var_return_value() \n"
368 " container.push_back_ref(x) \n"
370 " container.push_back_ref(clone(x)); \n"
375 return "push_back_ref";
381 m.
add(
fun(&ContainerType::pop_back),
"pop_back");
383 template<
typename ContainerType>
386 auto m = std::make_shared<Module>();
395 template<
typename ContainerType>
398 typedef void (ContainerType::*push_ptr)(
typename ContainerType::const_reference);
399 typedef void (ContainerType::*pop_ptr)();
401 m.
add(
fun([](ContainerType &container)->
decltype(
auto){
402 if (container.empty()) {
403 throw std::range_error(
"Container empty");
405 return (container.front());
411 m.
add(
fun([](
const ContainerType &container)->
decltype(
auto){
412 if (container.empty()) {
413 throw std::range_error(
"Container empty");
415 return (container.front());
422 m.
add(
fun(
static_cast<push_ptr
>(&ContainerType::push_front)),
424 if (
typeid(
typename ContainerType::value_type) ==
typeid(
Boxed_Value)) {
426 "# Pushes the second value onto the front of container while making a clone of the value\n"
427 "def push_front(" + type +
" container, x)\n"
429 " if (x.is_var_return_value()) {\n"
430 " x.reset_var_return_value() \n"
431 " container.push_front_ref(x) \n"
433 " container.push_front_ref(clone(x)); \n"
437 return "push_front_ref";
443 m.
add(
fun(
static_cast<pop_ptr
>(&ContainerType::pop_front)),
"pop_front");
445 template<
typename ContainerType>
448 auto m = std::make_shared<Module>();
456 template<
typename PairType>
461 m.
add(
fun(&PairType::first),
"first");
462 m.
add(
fun(&PairType::second),
"second");
465 m.
add(
constructor<PairType (
const typename PairType::first_type &,
const typename PairType::second_type &)>(), type);
467 template<
typename PairType>
470 auto m = std::make_shared<Module>();
480 template<
typename ContainerType>
485 template<
typename ContainerType>
488 auto m = std::make_shared<Module>();
496 template<
typename ContainerType>
501 typedef size_t (ContainerType::*erase_ptr)(
const typename ContainerType::key_type &);
503 m.
add(
fun(
static_cast<erase_ptr
>(&ContainerType::erase)),
"erase");
509 if (
typeid(
typename ContainerType::mapped_type) ==
typeid(
Boxed_Value)) {
516 template<
typename ContainerType>
519 auto m = std::make_shared<Module>();
527 template<
typename MapType>
532 typedef typename MapType::mapped_type &(MapType::*elem_access)(
const typename MapType::key_type &);
533 typedef const typename MapType::mapped_type &(MapType::*const_elem_access)(
const typename MapType::key_type &)
const;
535 m.
add(
fun(
static_cast<elem_access
>(&MapType::operator[])),
"[]");
537 m.
add(
fun(
static_cast<elem_access
>(&MapType::at)),
"at");
538 m.
add(
fun(
static_cast<const_elem_access
>(&MapType::at)),
"at");
540 if (
typeid(MapType) ==
typeid(std::map<std::string, Boxed_Value>))
543 def Map::`==`(Map rhs) {
544 if ( rhs.size() != this.size() ) {
547 auto r1 = range(this);
548 auto r2 = range(rhs);
551 if (!eq(r1.front().first, r2.front().first) || !eq(r1.front().second, r2.front().second))
571 template<
typename MapType>
574 auto m = std::make_shared<Module>();
581 template<
typename ListType>
595 template<
typename ListType>
598 auto m = std::make_shared<Module>();
606 template<
typename VectorType>
611 m.
add(
fun([](VectorType &container)->
decltype(
auto){
612 if (container.empty()) {
613 throw std::range_error(
"Container empty");
615 return (container.front());
621 m.
add(
fun([](
const VectorType &container)->
decltype(
auto){
622 if (container.empty()) {
623 throw std::range_error(
"Container empty");
625 return (container.front());
644 if (
typeid(VectorType) ==
typeid(std::vector<Boxed_Value>))
647 def Vector::`==`(Vector rhs) {
648 if ( rhs.size() != this.size() ) {
651 auto r1 = range(this);
652 auto r2 = range(rhs);
655 if (!eq(r1.front(), r2.front()))
668 template<
typename VectorType>
671 auto m = std::make_shared<Module>();
678 template<
typename String>
679 void string_type(
const std::string &type, Module& m)
693 m.add(
fun(&String::push_back),
695 if (
typeid(
typename String::value_type) ==
typeid(
Boxed_Value)) {
696 return "push_back_ref";
703 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->find(
f, pos); } ),
"find");
704 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->rfind(
f, pos); } ),
"rfind");
705 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->find_first_of(
f, pos); } ),
"find_first_of");
706 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->find_last_of(
f, pos); } ),
"find_last_of");
707 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->find_last_not_of(
f, pos); } ),
"find_last_not_of");
708 m.add(
fun([](
const String *s,
const String &
f,
size_t pos) {
return s->find_first_not_of(
f, pos); } ),
"find_first_not_of");
710 m.add(
fun([](
String *s,
typename String::value_type c) ->
decltype(
auto) {
return (*s += c); } ),
"+=");
712 m.add(
fun([](
String *s) { s->clear(); } ),
"clear");
713 m.add(
fun([](
const String *s) {
return s->empty(); } ),
"empty");
714 m.add(
fun([](
const String *s) {
return s->size(); } ),
"size");
716 m.add(
fun([](
const String *s) {
return s->c_str(); } ),
"c_str");
717 m.add(
fun([](
const String *s) {
return s->data(); } ),
"data");
718 m.add(
fun([](
const String *s,
size_t pos,
size_t len) {
return s->substr(pos, len); } ),
"substr");
720 template<
typename String>
723 auto m = std::make_shared<Module>();
732 template<
typename FutureType>
733 void future_type(
const std::string &type, Module& m)
737 m.add(
fun([](
const FutureType &t) {
return t.valid(); }),
"valid");
738 m.add(
fun([](FutureType &t) {
return t.get(); }),
"get");
739 m.add(
fun(&FutureType::wait),
"wait");
741 template<
typename FutureType>
744 auto m = std::make_shared<Module>();
Type
Definition Database.hh:9
SM String(std::string s)
Definition Language.hh:977
Definition Containment.hh:34
A wrapper for holding any valid C++ type. All types in ChaiScript are Boxed_Value objects.
Definition boxed_value.hpp:28
Holds a collection of ChaiScript settings which can be applied to the ChaiScript runtime....
Definition dispatchkit.hpp:150
Module & add(Type_Info ti, std::string name)
Definition dispatchkit.hpp:152
Module & eval(const std::string &str)
Definition dispatchkit.hpp:183
void assign(Module &m)
Definition operators.hpp:24
void addition(Module &m)
Definition operators.hpp:144
void assign_sum(Module &m)
Definition operators.hpp:84
Definition bootstrap_stl.hpp:101
size_t count(const T &t_target, const typename T::key_type &t_key)
Definition bootstrap_stl.hpp:104
void insert_ref(T &t_target, const typename T::value_type &t_val)
Definition bootstrap_stl.hpp:116
void insert_at(Type &container, int pos, const typename Type::value_type &v)
Algorithm for inserting at a specific position into a container.
Definition bootstrap_stl.hpp:143
void input_range_type_impl(const std::string &type, Module &m)
Add Bidir_Range support for the given ContainerType.
Definition bootstrap_stl.hpp:125
void erase_at(Type &container, int pos)
Algorithm for erasing a specific position from a container.
Definition bootstrap_stl.hpp:160
void insert(T &t_target, const T &t_other)
Definition bootstrap_stl.hpp:110
Definition bootstrap_stl.hpp:39
void vector_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:589
void assignable_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:226
void map_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:528
void container_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:277
void list_type(const std::string &type, Module &m)
http://www.sgi.com/tech/stl/List.html
Definition bootstrap_stl.hpp:564
void input_range_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:176
void sequence_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:312
void back_insertion_sequence_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:336
void pair_associative_container_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:481
void random_access_container_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:193
void future_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:697
void reservable_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:260
void front_insertion_sequence_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:396
void resizable_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:243
void string_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:643
void unique_associative_container_type(const std::string &, Module &m)
Definition bootstrap_stl.hpp:497
void pair_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:457
void default_constructible_type(const std::string &type, Module &m)
Definition bootstrap_stl.hpp:295
Classes and functions useful for bootstrapping of ChaiScript and adding of new types.
Definition bootstrap.hpp:21
void copy_constructor(const std::string &type, Module &m)
Adds a copy constructor for the given type to the given Model.
Definition bootstrap.hpp:64
void opers_comparison(Module &m)
Add all comparison operators for the templated type. Used during bootstrap, also available to users.
Definition bootstrap.hpp:74
void basic_constructors(const std::string &type, Module &m)
Adds default and copy constructors for the given type.
Definition bootstrap.hpp:94
Namespace chaiscript contains every API call that the average user will be concerned with.
constexpr Type_Info user_type(const T &)
Creates a Type_Info object representing the type passed in.
Definition type_info.hpp:221
Proxy_Function constructor()
Generates a constructor function for use with ChaiScript.
Definition proxy_constructors.hpp:47
Proxy_Function fun(const T &t)
Creates a new Proxy_Function object from a free function, member function or data member.
Definition register_function.hpp:43
constexpr Type_Info user_type()
Creates a Type_Info object representing the templated type.
Definition type_info.hpp:236
std::shared_ptr< Module > ModulePtr
Convenience typedef for Module objects to be added to the ChaiScript runtime.
Definition dispatchkit.hpp:263
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
IterType m_begin
Definition bootstrap_stl.hpp:97
void pop_front()
Definition bootstrap_stl.hpp:59
void pop_back()
Definition bootstrap_stl.hpp:68
Bidir_Range(Container &c)
Definition bootstrap_stl.hpp:49
decltype(auto) front() const
Definition bootstrap_stl.hpp:77
bool empty() const
Definition bootstrap_stl.hpp:54
Container container_type
Definition bootstrap_stl.hpp:47
IterType m_end
Definition bootstrap_stl.hpp:98
decltype(auto) back() const
Definition bootstrap_stl.hpp:86