Removed unused helper BoundedArray class
[libcds.git] / cds / details / bounded_array.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H
4 #define CDSLIB_IMPL_BOUNDED_ARRAY_H
5
6 /*
7     Dynamic non-growing array
8
9     Editions:
10         2008.03.08    Maxim.Khiszinsky    Created
11 */
12
13 #include <cds/details/allocator.h>
14 #include <vector>
15 #include <assert.h>
16
17 //@cond
18 namespace cds {
19     namespace details {
20         /// Bounded dynamic array
21         /**
22             The class template is intended for storing fixed-size sequences of objects.
23             Array capacity is constant and cannot be changed after creation of object of the class.
24             It is suitable for managing objects of non-copyable type \p T.
25
26             \par Template parameters
27                 - \p T type of elements
28                 - \p Allocator dynamic memory allocator class (<tt>std::allocator</tt> semantics)
29
30         */
31         template <typename T, class Allocator = CDS_DEFAULT_ALLOCATOR >
32         class bounded_array
33         {
34         public:
35             typedef T value_type ;    ///< value type stored in the array
36             typedef Allocator allocator_type ;  ///< allocator type
37
38             typedef value_type *          iterator          ; ///< item iterator
39             typedef value_type const *    const_iterator    ; ///< item const iterator
40
41         private:
42             typedef cds::details::Allocator< T, allocator_type> allocator_impl;
43
44             value_type *    m_arr;
45             const size_t    m_nCapacity;
46
47         public:
48             /// Default ctor
49             explicit bounded_array(
50                 size_t nCapacity            ///< capacity
51             )
52             : m_arr( allocator_impl().NewArray( nCapacity ) )
53             , m_nCapacity( nCapacity )
54             {}
55
56             ~bounded_array()
57             {
58                 allocator_impl().Delete( m_arr, capacity() );
59             }
60
61             const value_type& operator []( size_t nItem ) const
62             {
63                 assert( nItem < capacity() );
64                 return m_arr[nItem];
65             }
66
67             value_type& operator []( size_t nItem )
68             {
69                 assert( nItem < capacity() );
70                 return m_arr[nItem];
71             }
72
73             size_t   size() const CDS_NOEXCEPT
74             {
75                 return capacity();
76             }
77
78             size_t   capacity() const CDS_NOEXCEPT
79             {
80                 return m_nCapacity;
81             }
82
83             /// Returns pointer to the first item in the array
84             value_type * top() CDS_NOEXCEPT
85             {
86                 return m_arr;
87             }
88
89             /// Get begin iterator
90             const_iterator  begin() const CDS_NOEXCEPT
91             {
92                 return m_arr;
93             }
94             iterator        begin() CDS_NOEXCEPT
95             {
96                 return m_arr;
97             }
98
99             /// Get end iterator
100             const_iterator  end() const CDS_NOEXCEPT
101             {
102                 return begin() + capacity();
103             }
104             iterator        end() CDS_NOEXCEPT
105             {
106                 return begin() + capacity();
107             }
108         };
109
110     }    // namespace details
111 }    // namespace cds
112 //@endcond
113
114 #endif    // #ifndef CDSLIB_IMPL_BOUNDED_ARRAY_H