From 57e58c445b57759073b49f786c931e27b7f7f397 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Thu, 14 Aug 2003 12:14:25 +0000 Subject: [PATCH] Tweaks to accomodate map_indexing_suite [SVN r19588] --- .../indexing/detail/indexing_suite_detail.hpp | 73 +++++++++++++++++-- .../python/suite/indexing/indexing_suite.hpp | 5 +- .../suite/indexing/vector_indexing_suite.hpp | 11 +-- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp index 282916ba..538edda9 100644 --- a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp +++ b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp @@ -28,13 +28,14 @@ namespace boost { namespace python { namespace detail { // This functor compares a proxy and an index. // This is used by proxy_group::first_proxy to // get first proxy with index i. - + template bool operator()(PyObject* prox, Index i) const { typedef typename Proxy::policies_type policies_type; + Proxy& proxy = extract(prox)(); return policies_type:: - compare_index(extract(prox)().get_index(), i); + compare_index(proxy.get_container(), proxy.get_index(), i); } }; @@ -92,9 +93,33 @@ namespace boost { namespace python { namespace detail { BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } + void + erase(index_type i, mpl::false_) + { + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; + // Erase the proxy with index i + replace(i, i, 0); + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; + } + + void + erase(index_type i, mpl::true_) + { + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; + // Erase the proxy with index i + + iterator iter = first_proxy(i); + if (iter != proxies.end() + && extract(*iter)().get_index() == i) + proxies.erase(iter); + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; + } + void erase(index_type from, index_type to) { + // note: this cannot be called when container is not sliceable + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Erase all proxies with indexes from..to replace(from, to, 0); @@ -107,6 +132,8 @@ namespace boost { namespace python { namespace detail { index_type to, typename std::vector::size_type len) { + // note: this cannot be called when container is not sliceable + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Erase all proxies with indexes from..to. // Adjust the displaced indexes such that the @@ -138,8 +165,11 @@ namespace boost { namespace python { namespace detail { { extract p(*right); p().set_index( - policies_type::adjust_index( - extract(*right)().get_index(), from, to, len)); + extract(*right)().get_index() + - (typename Proxy::container_type::difference_type(to) + - from - len) + ); + ++right; } BOOST_PYTHON_INDEXING_CHECK_INVARIANT; @@ -225,6 +255,19 @@ namespace boost { namespace python { namespace detail { links[&container].add(prox); } + template + void erase(Container& container, index_type i, NoSlice no_slice) + { + // Erase the proxy with index i + typename links_t::iterator r = links.find(&container); + if (r != links.end()) + { + r->second.erase(i, no_slice); + if (r->second.size() == 0) + links.erase(r); + } + } + void erase(Container& container, index_type from, index_type to) { @@ -293,7 +336,8 @@ namespace boost { namespace python { namespace detail { public: typedef Index index_type; - typedef typename Container::value_type element_type; + typedef Container container_type; + typedef typename Policies::data_type element_type; typedef Policies policies_type; typedef container_element self_t; typedef proxy_group links_type; @@ -417,6 +461,13 @@ namespace boost { namespace python { namespace detail { { } + template + static void + base_erase_index( + Container& container, Index i, NoSlice no_slice) + { + } + static void base_erase_indexes(Container& container, Index from, Index to) { @@ -466,6 +517,14 @@ namespace boost { namespace python { namespace detail { ContainerElement::get_links().replace(container, from, to, n); } + template + static void + base_erase_index( + Container& container, Index i, NoSlice no_slice) + { + ContainerElement::get_links().erase(container, i, no_slice); + } + static void base_erase_indexes( Container& container, Index from, Index to) @@ -617,8 +676,8 @@ namespace boost { namespace python { namespace detail { }} // namespace python::detail - template - inline typename Container::value_type* + template + inline typename Policies::data_type* get_pointer( python::detail::container_element const& p) { diff --git a/include/boost/python/suite/indexing/indexing_suite.hpp b/include/boost/python/suite/indexing/indexing_suite.hpp index 0cdb10f9..21f240aa 100644 --- a/include/boost/python/suite/indexing/indexing_suite.hpp +++ b/include/boost/python/suite/indexing/indexing_suite.hpp @@ -147,7 +147,7 @@ namespace boost { namespace python { typedef typename mpl::if_< mpl::bool_ - , detail::slice_helper< + , detail::no_slice_helper< Container , DerivedPolicies , proxy_handler @@ -185,6 +185,7 @@ namespace boost { namespace python { static void extension_def(Class& cl) { + // default. // no more extensions } @@ -250,7 +251,7 @@ namespace boost { namespace python { } Index index = DerivedPolicies::convert_index(container, i); - proxy_handler::base_erase_indexes(container, index, index+1); + proxy_handler::base_erase_index(container, index, mpl::bool_()); DerivedPolicies::delete_item(container, index); } diff --git a/include/boost/python/suite/indexing/vector_indexing_suite.hpp b/include/boost/python/suite/indexing/vector_indexing_suite.hpp index f23d55ac..5c575828 100644 --- a/include/boost/python/suite/indexing/vector_indexing_suite.hpp +++ b/include/boost/python/suite/indexing/vector_indexing_suite.hpp @@ -140,7 +140,7 @@ namespace boost { namespace python { } static bool - compare_index(index_type a, index_type b) + compare_index(Container& container, index_type a, index_type b) { return a < b; } @@ -166,14 +166,7 @@ namespace boost { namespace python { throw_error_already_set(); return index_type(); } - - static index_type - adjust_index(index_type current, index_type from, - index_type to, size_type len) - { - return current - (difference_type(to) - from - len); - } - + static void append(Container& container, data_type const& v) {