1 /* Copyright 2003-2013 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_RND_INDEX_PTR_ARRAY_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_RND_INDEX_PTR_ARRAY_HPP
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
18 #include <boost/detail/allocator_utilities.hpp>
19 #include <boost/multi_index/detail/auto_space.hpp>
20 #include <boost/multi_index/detail/rnd_index_node.hpp>
21 #include <boost/noncopyable.hpp>
26 namespace multi_index{
30 /* pointer structure for use by random access indices */
32 template<typename Allocator>
33 class random_access_index_ptr_array:private noncopyable
35 typedef random_access_index_node_impl<
36 typename boost::detail::allocator::rebind_to<
43 typedef typename node_impl_type::pointer value_type;
44 typedef typename boost::detail::allocator::rebind_to<
46 >::type::pointer pointer;
48 random_access_index_ptr_array(
49 const Allocator& al,value_type end_,std::size_t sz):
58 std::size_t size()const{return size_;}
59 std::size_t capacity()const{return capacity_;}
64 reserve(capacity_<=10?15:capacity_+capacity_/2);
68 void reserve(std::size_t c)
70 if(c>capacity_)set_capacity(c);
75 if(capacity_>size_)set_capacity(size_);
78 pointer begin()const{return ptrs();}
79 pointer end()const{return ptrs()+size_;}
80 pointer at(std::size_t n)const{return ptrs()+n;}
82 void push_back(value_type x)
85 (*(end()+1))->up()=end()+1;
91 void erase(value_type x)
93 node_impl_type::extract(x->up(),end()+1);
100 (*begin())->up()=begin();
104 void swap(random_access_index_ptr_array& x)
106 std::swap(size_,x.size_);
107 std::swap(capacity_,x.capacity_);
113 std::size_t capacity_;
114 auto_space<value_type,Allocator> spc;
121 void set_capacity(std::size_t c)
123 auto_space<value_type,Allocator> spc1(spc.get_allocator(),c+1);
124 node_impl_type::transfer(begin(),end()+1,spc1.data());
130 template<typename Allocator>
132 random_access_index_ptr_array<Allocator>& x,
133 random_access_index_ptr_array<Allocator>& y)
138 } /* namespace multi_index::detail */
140 } /* namespace multi_index */
142 } /* namespace boost */