2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-31 20:32:16 +00:00

Tweaks to accomodate map_indexing_suite

[SVN r19588]
This commit is contained in:
Joel de Guzman
2003-08-14 12:14:25 +00:00
parent 8a1a8342d6
commit 57e58c445b
3 changed files with 71 additions and 18 deletions

View File

@@ -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 <class Index>
bool operator()(PyObject* prox, Index i) const
{
typedef typename Proxy::policies_type policies_type;
Proxy& proxy = extract<Proxy&>(prox)();
return policies_type::
compare_index(extract<Proxy&>(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<Proxy&>(*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<PyObject*>::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<Proxy&> p(*right);
p().set_index(
policies_type::adjust_index(
extract<Proxy&>(*right)().get_index(), from, to, len));
extract<Proxy&>(*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 <class NoSlice>
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<Container, Index, Policies> self_t;
typedef proxy_group<self_t> links_type;
@@ -417,6 +461,13 @@ namespace boost { namespace python { namespace detail {
{
}
template <class NoSlice>
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 <class NoSlice>
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 <class Container, class Index, class Policies>
inline typename Container::value_type*
template <class Container, class Index, class Policies>
inline typename Policies::data_type*
get_pointer(
python::detail::container_element<Container, Index, Policies> const& p)
{

View File

@@ -147,7 +147,7 @@ namespace boost { namespace python {
typedef typename mpl::if_<
mpl::bool_<NoSlice>
, 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_<NoSlice>());
DerivedPolicies::delete_item(container, index);
}

View File

@@ -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)
{