ModulePtr container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { m->add(fun<size_t (const ContainerType *)>([](const ContainerType *a) { return a->size(); } ), "size"); m->add(fun<bool (const ContainerType *)>([](const ContainerType *a) { return a->empty(); } ), "empty"); m->add(fun<void (ContainerType *)>([](ContainerType *a) { a->clear(); } ), "clear"); return m; }
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { m->add(fun( std::function<size_t (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size"); m->add(fun( std::function<bool (const ContainerType *)>( [](const ContainerType *a) { return a->empty(); } ) ), "empty"); m->add(fun( std::function<void (ContainerType *)>( [](ContainerType *a) { a->clear(); } ) ), "clear"); return m; }
ModulePtr back_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>()) { typedef typename ContainerType::reference (ContainerType::*backptr)(); m->add(fun(static_cast<backptr>(&ContainerType::back)), "back"); typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &); m->add(fun(static_cast<push_back>(&ContainerType::push_back)), [&]()->std::string{ if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { m->eval( "# Pushes the second value onto the container while making a clone of the value\n" "def push_back(" + type + " container, x)\n" "{ \n" " if (x.is_var_return_value()) {\n" " x.reset_var_return_value() \n" " container.push_back_ref(x) \n" " } else { \n" " container.push_back_ref(clone(x)); \n" " }\n" "} \n" ); return "push_back_ref"; } else { return "push_back"; } }()); m->add(fun(&ContainerType::pop_back), "pop_back"); return m; }
ModulePtr front_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>()) { typedef typename ContainerType::reference (ContainerType::*front_ptr)(); typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const; typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference); typedef void (ContainerType::*pop_ptr)(); m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)), [&]()->std::string{ if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { m->eval( "# Pushes the second value onto the front of container while making a clone of the value\n" "def push_front(" + type + " container, x)\n" "{ \n" " if (x.is_var_return_value()) {\n" " x.reset_var_return_value() \n" " container.push_front_ref(x) \n" " } else { \n" " container.push_front_ref(clone(x)); \n" " }\n" "} \n" ); return "push_front_ref"; } else { return "push_front"; } }()); m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front"); return m; }
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { boost::function<int (const ContainerType *)> f = detail::return_int(&ContainerType::size); m->add(fun(f), "size"); m->add(fun<bool (ContainerType::*)() const>(&ContainerType::empty), "empty"); m->add(fun<void (ContainerType::*)()>(&ContainerType::clear), "clear"); return m; }
ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { std::string insert_name; if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { insert_name = "insert_ref_at"; } else { insert_name = "insert_at"; } m->add(fun(&detail::insert_at<ContainerType>), insert_name); m->add(fun(&detail::erase_at<ContainerType>), "erase_at"); return m; }
ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { m->add(fun(&detail::insert_at<ContainerType>), []()->std::string{ if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { return "insert_ref_at"; } else { return "insert_at"; } }()); m->add(fun(&detail::erase_at<ContainerType>), "erase_at"); return m; }
ModulePtr pair_type(const std::string &type, ModulePtr m = std::make_shared<Module>()) { m->add(user_type<PairType>(), type); typename PairType::first_type PairType::* f = &PairType::first; typename PairType::second_type PairType::* s = &PairType::second; m->add(fun(f), "first"); m->add(fun(s), "second"); basic_constructors<PairType>(type, m); m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type); return m; }
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); typedef typename ContainerType::const_reference(ContainerType::*constindexoper)(size_t) const; //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. m->add( fun(boost::function<typename ContainerType::reference (ContainerType *, int)> (boost::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]"); m->add( fun(boost::function<typename ContainerType::const_reference (const ContainerType *, int)> (boost::mem_fn(static_cast<constindexoper>(&ContainerType::at)))), "[]"); return m; }
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) { m->add(user_type<MapType>(), type); typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &); m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]"); container_type<MapType>(type, m); assignable_type<MapType>(type, m); unique_associative_container_type<MapType>(type, m); pair_associative_container_type<MapType>(type, m); input_range_type<MapType>(type, m); return m; }
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { //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. m->add( fun( [](ContainerType &c, int index) -> typename ContainerType::reference { return c.at(index); }), "[]"); m->add( fun( [](const ContainerType &c, int index) -> typename ContainerType::const_reference { return c.at(index); }), "[]"); return m; }
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { // cppcheck-suppress syntaxError typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); //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. m->add( fun(std::function<typename ContainerType::reference (ContainerType *, int)> (std::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]"); m->add( fun<typename ContainerType::const_reference (const ContainerType *, int)>( [](const ContainerType *c, int index) -> typename ContainerType::const_reference { return c->at(index); }), "[]"); return m; }
ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { typedef typename ContainerType::reference (ContainerType::*backptr)(); m->add(fun(static_cast<backptr>(&ContainerType::back)), "back"); std::string push_back_name; if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { push_back_name = "push_back_ref"; } else { push_back_name = "push_back"; } typedef void (ContainerType::*pushback)(const typename ContainerType::value_type &); m->add(fun(static_cast<pushback>(&ContainerType::push_back)), push_back_name); m->add(fun(&ContainerType::pop_back), "pop_back"); return m; }
ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { typedef typename ContainerType::reference (ContainerType::*backptr)(); m->add(fun(static_cast<backptr>(&ContainerType::back)), "back"); typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &); m->add(fun(static_cast<push_back>(&ContainerType::push_back)), []()->std::string{ if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { return "push_back_ref"; } else { return "push_back"; } }()); m->add(fun(&ContainerType::pop_back), "pop_back"); return m; }
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module())) { typedef typename ContainerType::reference (ContainerType::*frontptr)(); typedef void (ContainerType::*pushptr)(typename ContainerType::const_reference); typedef void (ContainerType::*popptr)(); m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front"); std::string push_front_name; if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { push_front_name = "push_front_ref"; } else { push_front_name = "push_front"; } m->add(fun(static_cast<pushptr>(&ContainerType::push_front)), push_front_name); m->add(fun(static_cast<popptr>(&ContainerType::pop_front)), "pop_front"); return m; }
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { m->add(fun(detail::count<ContainerType>), "count"); typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &); m->add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase"); m->add(fun(&detail::insert<ContainerType>), "insert"); std::string insert_name; if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) { insert_name = "insert_ref"; } else { insert_name = "insert"; } m->add(fun(&detail::insert_ref<ContainerType>), insert_name); return m; }
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = std::make_shared<Module>()) { typedef typename ContainerType::reference (ContainerType::*front_ptr)(); typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const; typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference); typedef void (ContainerType::*pop_ptr)(); m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)), []()->std::string{ if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { return "push_front_ref"; } else { return "push_front"; } }()); m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front"); return m; }
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>()) { m->add(fun(detail::count<ContainerType>), "count"); typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &); m->add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase"); m->add(fun(&detail::insert<ContainerType>), "insert"); m->add(fun(&detail::insert_ref<ContainerType>), []()->std::string{ if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) { return "insert_ref"; } else { return "insert"; } }()); return m; }
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) { m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(detail::return_int(&ContainerType::count))), "count"); typedef size_t (ContainerType::*erase)(const typename ContainerType::key_type &); erase eraseptr(&ContainerType::erase); m->add(fun(boost::function<int (ContainerType *, const typename ContainerType::key_type &)>(detail::return_int(eraseptr))), "erase"); m->add(fun(&detail::insert<ContainerType>), "insert"); std::string insert_name; if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) { insert_name = "insert_ref"; } else { insert_name = "insert"; } m->add(fun(&detail::insert_ref<ContainerType>), insert_name); return m; }
ModulePtr list_type(const std::string &type, ModulePtr m = std::make_shared<Module>()) { m->add(user_type<ListType>(), type); front_insertion_sequence_type<ListType>(type, m); back_insertion_sequence_type<ListType>(type, m); sequence_type<ListType>(type, m); container_type<ListType>(type, m); default_constructible_type<ListType>(type, m); assignable_type<ListType>(type, m); input_range_type<ListType>(type, m); return m; }
ModulePtr vector_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) { m->add(user_type<VectorType>(), type); typedef typename VectorType::reference (VectorType::*frontptr)(); m->add(fun(static_cast<frontptr>(&VectorType::front)), "front"); back_insertion_sequence_type<VectorType>(type, m); sequence_type<VectorType>(type, m); random_access_container_type<VectorType>(type, m); container_type<VectorType>(type, m); default_constructible_type<VectorType>(type, m); assignable_type<VectorType>(type, m); input_range_type<VectorType>(type, m); if (typeid(VectorType) == typeid(std::vector<Boxed_Value>)) { m->eval("def Vector::`==`(rhs) : type_match(rhs, this) { \ if ( rhs.size() != this.size() ) { \ return false; \ } else { \ var r1 = range(this); \ var r2 = range(rhs); \ while (!r1.empty()) \ { \ if (!eq(r1.front(), r2.front())) \ { \ return false; \ } \ r1.pop_front(); \ r2.pop_front(); \ } \ return true; \ } \ }");
ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = std::make_shared<Module>()) { m->add(user_type<Bidir_Type>(), type + "_Range"); copy_constructor<Bidir_Type>(type + "_Range", m); m->add(constructor<Bidir_Type (typename Bidir_Type::container_type &)>(), "range_internal"); m->add(fun(&Bidir_Type::empty), "empty"); m->add(fun(&Bidir_Type::pop_front), "pop_front"); m->add(fun(&Bidir_Type::front), "front"); m->add(fun(&Bidir_Type::pop_back), "pop_back"); m->add(fun(&Bidir_Type::back), "back"); return m; }
ModulePtr right_shift(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&right_shift<T, const T &, const T &>), ">>"); return m; }
ModulePtr remainder(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&remainder<T, const T &, const T &>), "%"); return m; }
ModulePtr multiplication(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&multiplication<T, const T &, const T &>), "*"); return m; }
ModulePtr left_shift(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&left_shift<T, const T &, const T &>), "<<"); return m; }
ModulePtr division(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&division<T, const T &, const T &>), "/"); return m; }
ModulePtr bitwise_or(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&bitwise_or<T, const T &, const T &>), "|"); return m; }
ModulePtr bitwise_compliment(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&bitwise_compliment<T, const T &>), "~"); return m; }
ModulePtr bitwise_and(ModulePtr m = ModulePtr(new Module())) { m->add(fun(&bitwise_and<T, const T &, const T &>), "&"); return m; }