diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index a1f9cbf..d910c26 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -36,16 +36,6 @@ namespace chaiscript { } - Bidir_Range(typename Container::iterator itr) - : m_begin(itr), m_end(itr) - { - } - - Bidir_Range(const std::pair &t_p) - : m_begin(t_p.first), m_end(t_p.second) - { - } - bool empty() const { return m_begin == m_end; @@ -118,20 +108,10 @@ namespace chaiscript ModulePtr input_range_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) { m->add(user_type >(), type + "_Range"); - m->add(user_type > >(), type + "_Retro_Range"); - m->add(user_type(), type+"_Iterator"); copy_constructor >(type + "_Range", m); - copy_constructor > >(type + "_Retro_Range", m); m->add(constructor (ContainerType &)>(), "range"); - m->add(constructor (typename ContainerType::iterator)>(), "range"); - - typedef std::pair ItrPair; - - m->add(constructor (const ItrPair &)>(), "range"); - - m->add(user_type(), type+"_Iterator_Pair"); m->add(fun(&Bidir_Range::empty), "empty"); m->add(fun(&Bidir_Range::pop_front), "pop_front"); @@ -139,16 +119,6 @@ namespace chaiscript m->add(fun(&Bidir_Range::pop_back), "pop_back"); m->add(fun(&Bidir_Range::back), "back"); - m->add(fun(&Retro >::empty), "empty"); - m->add(fun(&Retro >::pop_front), "pop_front"); - m->add(fun(&Retro >::front), "front"); - m->add(fun(&Retro >::pop_back), "pop_back"); - m->add(fun(&Retro >::back), "back"); - - m->add(constructor > (const Bidir_Range &)>(), "retro"); - - - return m; } @@ -176,8 +146,6 @@ namespace chaiscript //to throw an exception in an out of bounds condition. m->add( fun(boost::function(static_cast(&ContainerType::at))), "[]"); - m->add( - fun(boost::function(static_cast(&ContainerType::operator[]))), "at"); return m; } @@ -204,7 +172,6 @@ namespace chaiscript assignable_type(type, m); m->add(fun(&ContainerType::size), "size"); - m->add(fun(&ContainerType::max_size), "max_size"); m->add(fun(&ContainerType::empty), "empty"); m->add(fun(&ContainerType::clear), "clear"); @@ -443,7 +410,6 @@ namespace chaiscript reversible_container_type(type, m); associative_container_type(type, m); - m->add(fun(static_cast(&ContainerType::equal_range)), "equal_range"); return m; } diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 092e106..8b6514b 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -9,7 +9,7 @@ //Note, the expression "[x,y]" in "collate" is parsed as two separate expressions //by C++, so CODE_STRING, takes two expressions and adds in the missing comma -#define CODE_STRING(x, y) #x ", " #y +#define CODE_STRING(x, y, z) #x ", " #y ", " #z #define chaiscript_prelude CODE_STRING(\ def new(x) { eval(type_name(x))(); } \ @@ -52,13 +52,27 @@ def insert_at(container, pos, x) { container.insert_ref_at(pos, clone(x)); } \n\ # Returns the reverse of the given container\n\ def reverse(container) {\ var retval = new(container); \ - var r = retro(range(container)); \ + var r = range(container); \ while (!r.empty()) { \ - retval.push_back(r.front()); \ - r.pop_front(); \ + retval.push_back(r.back()); \ + r.pop_back(); \ } \ retval; \ } \ +# Returns true if the object is a retro object\n\ +def is_retro(r) { call_exists(count, r, "data_type") && r.count("data_type") == 1 && r["data_type"] == "retro" }\n\ +# Creates a retro from a retro by returning the original range\n\ +def retro(r) : is_retro(r) { clone(r["data"]) }\n\ +# Creates a retro range from a range\n\ +def retro(r) : call_exists(empty, r) && call_exists(pop_front, r) && call_exists(pop_back, r) && call_exists(back, r) && call_exists(front, r) { var m = ["data_type":"retro", "data":r]; }\n\ +# Returns the first value of a retro\n\ +def front(r) : is_retro(r) { back(r["data"]) }\n\ +# Returns the last value of a retro\n\ +def back(r) : is_retro(r) { front(r["data"]) }\n\ +# Moves the back iterator of a retro towards the front by one \n\ +def pop_back(r) : is_retro(r) { pop_front(r["data"]) }\n\ +# Moves the front iterator of a retro towards the back by one \n\ +def pop_front(r) : is_retro(r) { pop_back(r["data"]) } \n\ # Performs the second value function over the container first value\n\ def for_each(container, func) : call_exists(range, container) { \ var range = range(container); \