1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
// Boost.Geometry Index
//
// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
//
// Use, modification and distribution is subject to 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)
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_PUSHABLE_ARRAY_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_PUSHABLE_ARRAY_HPP
#include <boost/array.hpp>
#include <boost/geometry/index/detail/assert.hpp>
namespace boost { namespace geometry { namespace index { namespace detail {
template <typename Element, size_t Capacity>
class pushable_array
{
typedef typename boost::array<Element, Capacity> array_type;
public:
typedef typename array_type::value_type value_type;
typedef typename array_type::size_type size_type;
typedef typename array_type::iterator iterator;
typedef typename array_type::const_iterator const_iterator;
typedef typename array_type::reverse_iterator reverse_iterator;
typedef typename array_type::const_reverse_iterator const_reverse_iterator;
typedef typename array_type::reference reference;
typedef typename array_type::const_reference const_reference;
inline pushable_array()
: m_size(0)
{}
inline explicit pushable_array(size_type s)
: m_size(s)
{
BOOST_GEOMETRY_INDEX_ASSERT(s <= Capacity, "size too big");
}
inline void resize(size_type s)
{
BOOST_GEOMETRY_INDEX_ASSERT(s <= Capacity, "size too big");
m_size = s;
}
inline void reserve(size_type /*s*/)
{
//BOOST_GEOMETRY_INDEX_ASSERT(s <= Capacity, "size too big");
// do nothing
}
inline Element & operator[](size_type i)
{
BOOST_GEOMETRY_INDEX_ASSERT(i < m_size, "index of the element outside the container");
return m_array[i];
}
inline Element const& operator[](size_type i) const
{
BOOST_GEOMETRY_INDEX_ASSERT(i < m_size, "index of the element outside the container");
return m_array[i];
}
inline Element const& front() const
{
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_size, "there are no elements in the container");
return m_array.front();
}
inline Element & front()
{
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_size, "there are no elements in the container");
return m_array.front();
}
inline Element const& back() const
{
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_size, "there are no elements in the container");
return *(begin() + (m_size - 1));
}
inline Element & back()
{
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_size, "there are no elements in the container");
return *(begin() + (m_size - 1));
}
inline iterator begin()
{
return m_array.begin();
}
inline iterator end()
{
return m_array.begin() + m_size;
}
inline const_iterator begin() const
{
return m_array.begin();
}
inline const_iterator end() const
{
return m_array.begin() + m_size;
}
inline reverse_iterator rbegin()
{
return reverse_iterator(end());
}
inline reverse_iterator rend()
{
return reverse_iterator(begin());
}
inline const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
inline const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
inline void clear()
{
m_size = 0;
}
inline void push_back(Element const& v)
{
BOOST_GEOMETRY_INDEX_ASSERT(m_size < Capacity, "can't further increase the size of the container");
m_array[m_size] = v;
++m_size;
}
inline void pop_back()
{
BOOST_GEOMETRY_INDEX_ASSERT(0 < m_size, "there are no elements in the container");
--m_size;
}
inline bool empty() const
{
return m_size == 0;
}
inline size_t size() const
{
return m_size;
}
inline size_t capacity() const
{
return Capacity;
}
private:
boost::array<Element, Capacity> m_array;
size_type m_size;
};
}}}} // namespace boost::geometry::index::detail
#endif // BOOST_GEOMETRY_INDEX_DETAIL_PUSHABLE_ARRAY_HPP
|