1 /* Copyright 2003-2007 Joaquín M López Muñoz.
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
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
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/prevent_eti.hpp>
21 #include <boost/multi_index/detail/rnd_index_node.hpp>
22 #include <boost/noncopyable.hpp>
27 namespace multi_index{
31 /* pointer structure for use by random access indices */
33 template<typename Allocator>
34 class random_access_index_ptr_array:private noncopyable
36 typedef typename prevent_eti<
38 random_access_index_node_impl<
39 typename boost::detail::allocator::rebind_to<
44 >::type node_impl_type;
47 typedef typename node_impl_type::pointer value_type;
48 typedef typename prevent_eti<
50 typename boost::detail::allocator::rebind_to<
53 >::type::pointer pointer;
55 random_access_index_ptr_array(
56 const Allocator& al,value_type end_,std::size_t size):
65 std::size_t size()const{return size_;}
66 std::size_t capacity()const{return capacity_;}
71 reserve(capacity_<=10?15:capacity_+capacity_/2);
75 void reserve(std::size_t c)
78 auto_space<value_type,Allocator> spc1(spc.get_allocator(),c+1);
79 node_impl_type::transfer(begin(),end()+1,spc1.data());
85 pointer begin()const{return ptrs();}
86 pointer end()const{return ptrs()+size_;}
87 pointer at(std::size_t n)const{return ptrs()+n;}
89 void push_back(value_type x)
92 (*(end()+1))->up()=end()+1;
98 void erase(value_type x)
100 node_impl_type::extract(x->up(),end()+1);
107 (*begin())->up()=begin();
111 void swap(random_access_index_ptr_array& x)
113 std::swap(size_,x.size_);
114 std::swap(capacity_,x.capacity_);
120 std::size_t capacity_;
121 auto_space<value_type,Allocator> spc;
129 template<typename Allocator>
131 random_access_index_ptr_array<Allocator>& x,
132 random_access_index_ptr_array<Allocator>& y)
137 } /* namespace multi_index::detail */
139 } /* namespace multi_index */
141 } /* namespace boost */