summaryrefslogtreecommitdiff
path: root/boost/container/detail/multiallocation_chain.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/container/detail/multiallocation_chain.hpp')
-rw-r--r--boost/container/detail/multiallocation_chain.hpp178
1 files changed, 108 insertions, 70 deletions
diff --git a/boost/container/detail/multiallocation_chain.hpp b/boost/container/detail/multiallocation_chain.hpp
index c9952535eb..96f6202671 100644
--- a/boost/container/detail/multiallocation_chain.hpp
+++ b/boost/container/detail/multiallocation_chain.hpp
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@@ -11,7 +11,13 @@
#ifndef BOOST_CONTAINER_DETAIL_MULTIALLOCATION_CHAIN_HPP
#define BOOST_CONTAINER_DETAIL_MULTIALLOCATION_CHAIN_HPP
-#include "config_begin.hpp"
+#if defined(_MSC_VER)
+# pragma once
+#endif
+
+#include <boost/container/detail/config_begin.hpp>
+#include <boost/container/detail/workaround.hpp>
+
#include <boost/container/container_fwd.hpp>
#include <boost/container/detail/utilities.hpp>
#include <boost/container/detail/type_traits.hpp>
@@ -19,7 +25,7 @@
#include <boost/intrusive/slist.hpp>
#include <boost/intrusive/pointer_traits.hpp>
#include <boost/type_traits/make_unsigned.hpp>
-#include <boost/move/move.hpp>
+#include <boost/move/utility_core.hpp>
namespace boost {
namespace container {
@@ -45,30 +51,43 @@ class basic_multiallocation_chain
> slist_impl_t;
slist_impl_t slist_impl_;
- static node & to_node(VoidPointer p)
- { return *static_cast<node*>(static_cast<void*>(container_detail::to_raw_pointer(p))); }
+ typedef typename boost::intrusive::pointer_traits
+ <VoidPointer>::template rebind_pointer<node>::type node_ptr;
+ typedef typename boost::intrusive::
+ pointer_traits<node_ptr> node_ptr_traits;
+
+ static node & to_node(const VoidPointer &p)
+ { return *static_cast<node*>(static_cast<void*>(container_detail::to_raw_pointer(p))); }
+
+ static VoidPointer from_node(node &n)
+ { return node_ptr_traits::pointer_to(n); }
+
+ static node_ptr to_node_ptr(const VoidPointer &p)
+ { return node_ptr_traits::static_cast_from(p); }
BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_multiallocation_chain)
public:
-
- typedef VoidPointer void_pointer;
- typedef typename slist_impl_t::iterator iterator;
- typedef typename slist_impl_t::size_type size_type;
+ typedef VoidPointer void_pointer;
+ typedef typename slist_impl_t::iterator iterator;
+ typedef typename slist_impl_t::size_type size_type;
basic_multiallocation_chain()
: slist_impl_()
{}
+ basic_multiallocation_chain(const void_pointer &b, const void_pointer &before_e, size_type n)
+ : slist_impl_(to_node_ptr(b), to_node_ptr(before_e), n)
+ {}
+
basic_multiallocation_chain(BOOST_RV_REF(basic_multiallocation_chain) other)
- : slist_impl_()
- { slist_impl_.swap(other.slist_impl_); }
+ : slist_impl_(::boost::move(other.slist_impl_))
+ {}
basic_multiallocation_chain& operator=(BOOST_RV_REF(basic_multiallocation_chain) other)
{
- basic_multiallocation_chain tmp(boost::move(other));
- this->swap(tmp);
+ slist_impl_ = ::boost::move(other.slist_impl_);
return *this;
}
@@ -96,37 +115,52 @@ class basic_multiallocation_chain
iterator insert_after(iterator it, void_pointer m)
{ return slist_impl_.insert_after(it, to_node(m)); }
- void push_front(void_pointer m)
- { return slist_impl_.push_front(to_node(m)); }
+ void push_front(const void_pointer &m)
+ { return slist_impl_.push_front(to_node(m)); }
- void push_back(void_pointer m)
+ void push_back(const void_pointer &m)
{ return slist_impl_.push_back(to_node(m)); }
- void pop_front()
- { return slist_impl_.pop_front(); }
-
- void *front()
- { return &*slist_impl_.begin(); }
-
- void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_begin, iterator before_end)
- { slist_impl_.splice_after(after_this, x.slist_impl_, before_begin, before_end); }
+ void_pointer pop_front()
+ {
+ node & n = slist_impl_.front();
+ void_pointer ret = from_node(n);
+ slist_impl_.pop_front();
+ return ret;
+ }
- void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_begin, iterator before_end, size_type n)
- { slist_impl_.splice_after(after_this, x.slist_impl_, before_begin, before_end, n); }
+ void splice_after(iterator after_this, basic_multiallocation_chain &x, iterator before_b, iterator before_e, size_type n)
+ { slist_impl_.splice_after(after_this, x.slist_impl_, before_b, before_e, n); }
void splice_after(iterator after_this, basic_multiallocation_chain &x)
{ slist_impl_.splice_after(after_this, x.slist_impl_); }
- void incorporate_after(iterator after_this, void_pointer begin , iterator before_end)
- { slist_impl_.incorporate_after(after_this, &to_node(begin), &to_node(before_end)); }
+ void erase_after(iterator before_b, iterator e, size_type n)
+ { slist_impl_.erase_after(before_b, e, n); }
- void incorporate_after(iterator after_this, void_pointer begin, void_pointer before_end, size_type n)
- { slist_impl_.incorporate_after(after_this, &to_node(begin), &to_node(before_end), n); }
+ void_pointer incorporate_after(iterator after_this, const void_pointer &b, size_type unit_bytes, size_type num_units)
+ {
+ typedef typename boost::intrusive::pointer_traits<char_ptr> char_pointer_traits;
+ char_ptr elem = char_pointer_traits::static_cast_from(b);
+ if(num_units){
+ char_ptr prev_elem = elem;
+ elem += unit_bytes;
+ for(size_type i = 0; i != num_units-1; ++i, elem += unit_bytes){
+ ::new (container_detail::to_raw_pointer(prev_elem)) void_pointer(elem);
+ prev_elem = elem;
+ }
+ slist_impl_.incorporate_after(after_this, to_node_ptr(b), to_node_ptr(prev_elem), num_units);
+ }
+ return elem;
+ }
+
+ void incorporate_after(iterator after_this, void_pointer b, void_pointer before_e, size_type n)
+ { slist_impl_.incorporate_after(after_this, to_node_ptr(b), to_node_ptr(before_e), n); }
void swap(basic_multiallocation_chain &x)
{ slist_impl_.swap(x.slist_impl_); }
- static iterator iterator_to(void_pointer p)
+ static iterator iterator_to(const void_pointer &p)
{ return slist_impl_t::s_iterator_to(to_node(p)); }
std::pair<void_pointer, void_pointer> extract_data()
@@ -150,72 +184,75 @@ struct cast_functor
template<class MultiallocationChain, class T>
class transform_multiallocation_chain
+ : public MultiallocationChain
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(transform_multiallocation_chain)
+ //transform_multiallocation_chain(const transform_multiallocation_chain &);
+ //transform_multiallocation_chain & operator=(const transform_multiallocation_chain &);
- MultiallocationChain holder_;
typedef typename MultiallocationChain::void_pointer void_pointer;
typedef typename boost::intrusive::pointer_traits
- <void_pointer>::template rebind_pointer<T>::type pointer;
+ <void_pointer> void_pointer_traits;
+ typedef typename void_pointer_traits::template
+ rebind_pointer<T>::type pointer;
+ typedef typename boost::intrusive::pointer_traits
+ <pointer> pointer_traits;
- static pointer cast(void_pointer p)
- {
- return pointer(static_cast<T*>(container_detail::to_raw_pointer(p)));
- }
+ static pointer cast(const void_pointer &p)
+ { return pointer_traits::static_cast_from(p); }
public:
typedef transform_iterator
< typename MultiallocationChain::iterator
- , container_detail::cast_functor <T> > iterator;
- typedef typename MultiallocationChain::size_type size_type;
+ , container_detail::cast_functor <T> > iterator;
+ typedef typename MultiallocationChain::size_type size_type;
transform_multiallocation_chain()
- : holder_()
+ : MultiallocationChain()
{}
transform_multiallocation_chain(BOOST_RV_REF(transform_multiallocation_chain) other)
- : holder_()
- { this->swap(other); }
+ : MultiallocationChain(::boost::move(static_cast<MultiallocationChain&>(other)))
+ {}
transform_multiallocation_chain(BOOST_RV_REF(MultiallocationChain) other)
- : holder_(boost::move(other))
+ : MultiallocationChain(::boost::move(static_cast<MultiallocationChain&>(other)))
{}
transform_multiallocation_chain& operator=(BOOST_RV_REF(transform_multiallocation_chain) other)
{
- transform_multiallocation_chain tmp(boost::move(other));
- this->swap(tmp);
- return *this;
+ return static_cast<MultiallocationChain&>
+ (this->MultiallocationChain::operator=(::boost::move(static_cast<MultiallocationChain&>(other))));
}
-
- void push_front(pointer mem)
+/*
+ void push_front(const pointer &mem)
{ holder_.push_front(mem); }
+ void push_back(const pointer &mem)
+ { return holder_.push_back(mem); }
+
void swap(transform_multiallocation_chain &other_chain)
{ holder_.swap(other_chain.holder_); }
- void splice_after(iterator after_this, transform_multiallocation_chain &x, iterator before_begin, iterator before_end, size_type n)
- { holder_.splice_after(after_this.base(), x.holder_, before_begin.base(), before_end.base(), n); }
-
- void incorporate_after(iterator after_this, void_pointer begin, void_pointer before_end, size_type n)
- { holder_.incorporate_after(after_this.base(), begin, before_end, n); }
-
- void pop_front()
- { holder_.pop_front(); }
-
- pointer front()
- { return cast(holder_.front()); }
+ void splice_after(iterator after_this, transform_multiallocation_chain &x, iterator before_b, iterator before_e, size_type n)
+ { holder_.splice_after(after_this.base(), x.holder_, before_b.base(), before_e.base(), n); }
+ void incorporate_after(iterator after_this, pointer b, pointer before_e, size_type n)
+ { holder_.incorporate_after(after_this.base(), b, before_e, n); }
+*/
+ pointer pop_front()
+ { return cast(this->MultiallocationChain::pop_front()); }
+/*
bool empty() const
{ return holder_.empty(); }
iterator before_begin()
{ return iterator(holder_.before_begin()); }
-
+*/
iterator begin()
- { return iterator(holder_.begin()); }
-
+ { return iterator(this->MultiallocationChain::begin()); }
+/*
iterator end()
{ return iterator(holder_.end()); }
@@ -227,20 +264,21 @@ class transform_multiallocation_chain
void clear()
{ holder_.clear(); }
-
+*/
iterator insert_after(iterator it, pointer m)
- { return iterator(holder_.insert_after(it.base(), m)); }
+ { return iterator(this->MultiallocationChain::insert_after(it.base(), m)); }
- static iterator iterator_to(pointer p)
+ static iterator iterator_to(const pointer &p)
{ return iterator(MultiallocationChain::iterator_to(p)); }
- std::pair<void_pointer, void_pointer> extract_data()
- { return holder_.extract_data(); }
-
- MultiallocationChain extract_multiallocation_chain()
+ std::pair<pointer, pointer> extract_data()
{
- return MultiallocationChain(boost::move(holder_));
+ std::pair<void_pointer, void_pointer> data(this->MultiallocationChain::extract_data());
+ return std::pair<pointer, pointer>(cast(data.first), cast(data.second));
}
+/*
+ MultiallocationChain &extract_multiallocation_chain()
+ { return holder_; }*/
};
}}}