#include <TDynamicArray.h>
Public Types | |
typedef TDynamicArray < __ValueType, __Allocator, __MinSize, __Append > | _MyType |
typedef __Allocator | allocator |
typedef __Allocator::size_type | size_type |
typedef __Allocator::value_type | value_type |
typedef __Allocator::reference | reference |
typedef __Allocator::const_reference | const_reference |
typedef __Allocator::pointer | pointer |
typedef __Allocator::const_pointer | const_pointer |
typedef __Allocator::difference_type | difference_type |
typedef std::reverse_iterator < iterator > | reverse_iterator |
typedef std::reverse_iterator < const_iterator > | const_reverse_iterator |
Public Member Functions | |
TDynamicArray (size_type nMinSize=__MinSize, size_type nAppend=__Append, size_type nMaxSize=0) throw ( bad_alloc ) | |
TDynamicArray (const TDynamicArray &oth) throw ( bad_alloc ) | |
TDynamicArray & | operator= (const TDynamicArray &oth) throw ( bad_alloc ) |
virtual | ~TDynamicArray () throw ( logic_error ) |
size_type | size () const |
bool | empty () const |
size_type | capacity () const |
size_type | max_size () const |
size_type | append () const |
const_reference | operator[] (size_type index) const throw ( out_of_range ) |
reference | operator[] (size_type index) throw ( out_of_range ) |
const_reference | at (size_type index) const throw ( out_of_range ) |
reference | at (size_type index) throw ( out_of_range ) |
const_reference | back () const throw ( out_of_range ) |
reference | back () throw ( out_of_range ) |
const_reference | front () const throw ( out_of_range ) |
reference | front () throw ( out_of_range ) |
void | push_front (const_reference value) throw ( bad_alloc , overflow_error ) |
void | pop_front () throw ( out_of_range ) |
void | push_back (const_reference value) throw ( bad_alloc , overflow_error ) |
void | pop_back () throw ( out_of_range ) |
const_iterator | begin () const |
iterator | begin () |
const_iterator | end () const |
iterator | end () |
const_reverse_iterator | rbegin () const |
reverse_iterator | rbegin () |
const_reverse_iterator | rend () const |
reverse_iterator | rend () |
void | assign (size_type count, const_reference val) |
template<class InputIterator> | |
void | assign (InputIterator first, InputIterator end) |
void | erase (size_t where) |
iterator | erase (iterator where) |
iterator | erase (iterator first, iterator end) |
void | clear () |
reserve (size_type nNewCapacity) throw ( bad_alloc , overflow_error ) | |
void | resize (size_type nNewSize) throw ( bad_alloc , overflow_error ) |
void | resize (size_type nNewSize, value_type value) throw ( bad_alloc , overflow_error ) |
void | limit_size (size_type nNewSize) |
Protected Member Functions | |
void | check_resize () throw ( bad_alloc , overflow_error ) |
void | delete_at (size_type nPos) throw ( out_of_range ) |
void | insert_at (size_type nPos, const_reference value) throw ( out_of_range ) |
Protected Attributes | |
allocator | m_alloc |
size_type | m_nSize |
size_type | m_nCapacity |
size_type | m_nAppend |
size_type | m_nMaxSize |
pointer | m_acValues |
Classes | |
class | const_iterator |
constant bidirectional iterator More... | |
class | iterator |
bidirectional iterator (non const) More... |
Template base for dynamic arrays.
The type __ValueType has no restriction whatsoever. The allocator must be derived from reallocator.
Complexity:
front()
, back()
, operator[](size_type)
: O(1) push_front()
, pop_front()
: O(n) push_back()
, pop_back()
: O(1) erase(size_type)
, erase(iterator)
: O(1)+ erase(iterator,iterator)
: O(n)+ assign()
: O(n+m)+resize()
: O(n+m)+Here + denotes some memory copy operation. Value n is the current number of elements and m is the number of elements to insert or remove.
Definition at line 133 of file TDynamicArray.h.
typedef TDynamicArray<__ValueType, __Allocator, __MinSize, __Append> mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::_MyType |
type itself
Definition at line 137 of file TDynamicArray.h.
typedef __Allocator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::allocator |
allocator type
Definition at line 138 of file TDynamicArray.h.
typedef __Allocator::size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::size_type |
type used for size and indexing
Definition at line 139 of file TDynamicArray.h.
typedef __Allocator::value_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::value_type |
value type
Definition at line 140 of file TDynamicArray.h.
typedef __Allocator::reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::reference |
reference to value type
Definition at line 141 of file TDynamicArray.h.
typedef __Allocator::const_reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::const_reference |
const
reference to value type
Definition at line 142 of file TDynamicArray.h.
typedef __Allocator::pointer mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::pointer |
pointer to value type
Definition at line 143 of file TDynamicArray.h.
typedef __Allocator::const_pointer mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::const_pointer |
const
pointer to value type
Definition at line 144 of file TDynamicArray.h.
typedef __Allocator::difference_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::difference_type |
type used to calculate element position distances
Definition at line 145 of file TDynamicArray.h.
typedef std::reverse_iterator<iterator> mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::reverse_iterator |
typedef std::reverse_iterator<const_iterator> mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::const_reverse_iterator |
const
reverse iterator
Definition at line 698 of file TDynamicArray.h.
mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::TDynamicArray | ( | size_type | nMinSize = __MinSize , |
|
size_type | nAppend = __Append , |
|||
size_type | nMaxSize = 0 | |||
) | throw ( bad_alloc ) [inline, explicit] |
Default constructor
If nAppend is set to 0 then nSize specifies the maximum size of the array.
nMinSize | initial element capacity | |
nAppend | number of elements to append if size exceeds | |
nMaxSize | maximum capacity (zero results in the theoretical limit specified by the allocator). |
bad_alloc | if no memory could be allocated |
Definition at line 713 of file TDynamicArray.h.
00723 : m_alloc() 00724 , m_nSize(0) 00725 , m_nCapacity(nMinSize) 00726 , m_nAppend( nAppend) 00727 , m_nMaxSize( nMaxSize ? nMaxSize : m_alloc.max_size()) 00728 , m_acValues(0L) 00729 { 00730 if (m_nCapacity)
mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::TDynamicArray | ( | const TDynamicArray< __ValueType, __Allocator, __MinSize, __Append > & | oth | ) | throw ( bad_alloc ) [inline] |
copy constructor
oth | array to copy from |
bad_alloc | if no memory could be allocated |
Definition at line 737 of file TDynamicArray.h.
00743 : m_alloc(oth.m_alloc) 00744 , m_nSize(0) 00745 , m_nCapacity(0) 00746 , m_nAppend( oth.append())
virtual mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::~TDynamicArray | ( | ) | throw ( logic_error ) [inline, virtual] |
Free all allocated elements
logic_error | if the element space was not cleared and freed. |
Definition at line 763 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::clear().
TDynamicArray& mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator= | ( | const TDynamicArray< __ValueType, __Allocator, __MinSize, __Append > & | oth | ) | throw ( bad_alloc ) [inline] |
assignment operator
oth | array to copy from |
bad_alloc | if no memory could be allocated |
Definition at line 753 of file TDynamicArray.h.
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::size | ( | ) | const [inline] |
Definition at line 771 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::limit_size().
bool mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::empty | ( | ) | const [inline] |
Definition at line 778 of file TDynamicArray.h.
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::capacity | ( | ) | const [inline] |
Definition at line 785 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign().
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::max_size | ( | ) | const [inline] |
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::append | ( | ) | const [inline] |
Definition at line 799 of file TDynamicArray.h.
const_reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[] | ( | size_type | index | ) | const throw ( out_of_range ) [inline] |
index | of element to access (read only) |
const
reference to value at specified index out_of_range | if index is invalid |
Definition at line 808 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_acValues, mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nSize, and mbo_tda_throw_if_not.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::at().
reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[] | ( | size_type | index | ) | throw ( out_of_range ) [inline] |
index | of element to access (read/write) |
out_of_range | if index is invalid |
Definition at line 818 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_acValues, mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nSize, and mbo_tda_throw_if_not.
const_reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::at | ( | size_type | index | ) | const throw ( out_of_range ) [inline] |
index | of element to access (read only) |
const
reference to value at specified index out_of_range | if index is invalid |
Definition at line 828 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[]().
reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::at | ( | size_type | index | ) | throw ( out_of_range ) [inline] |
index | of element to access (read/write) |
out_of_range | if index is invalid |
Definition at line 837 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[]().
const_reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::back | ( | ) | const throw ( out_of_range ) [inline] |
const
reference to first element out_of_range | if size() == 0 |
Definition at line 845 of file TDynamicArray.h.
reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::back | ( | ) | throw ( out_of_range ) [inline] |
out_of_range | if size() == 0 |
Definition at line 854 of file TDynamicArray.h.
const_reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::front | ( | ) | const throw ( out_of_range ) [inline] |
const
reference to last element out_of_range | if size() == 0 |
Definition at line 863 of file TDynamicArray.h.
reference mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::front | ( | ) | throw ( out_of_range ) [inline] |
out_of_range | if size() == 0 |
Definition at line 872 of file TDynamicArray.h.
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::push_front | ( | const_reference | value | ) | throw ( bad_alloc , overflow_error ) [inline] |
Append new data at beginning of array.
value | new data to append |
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 884 of file TDynamicArray.h.
00890 { 00891 check_resize(); 00892 00893 if (m_nSize) 00894 { 00895 m_alloc.move(m_alloc.address(m_acValues[1]), m_alloc.address(m_acValues[0]), m_nSize);
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::pop_front | ( | ) | throw ( out_of_range ) [inline] |
Drops the first element
out_of_range | if size() == 0 |
Definition at line 900 of file TDynamicArray.h.
00906 { 00907 mbo_tda_throw_if_not(out_of_range, m_nSize > 0); 00908 00909 delete_at(0); 00910
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::push_back | ( | const_reference | value | ) | throw ( bad_alloc , overflow_error ) [inline] |
Append new data at end of array.
value | new data to append |
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 918 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign().
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::pop_back | ( | ) | throw ( out_of_range ) [inline] |
Drops the last element
out_of_range | if size() == 0 |
Definition at line 928 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::limit_size().
const_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::begin | ( | ) | const [inline] |
iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::begin | ( | ) | [inline] |
const_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::end | ( | ) | const [inline] |
Definition at line 951 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::rbegin().
iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::end | ( | ) | [inline] |
Definition at line 958 of file TDynamicArray.h.
const_reverse_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::rbegin | ( | ) | const [inline] |
const
reverse iterator initialized to first (last in array) element Definition at line 968 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::end().
reverse_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::rbegin | ( | ) | [inline] |
Definition at line 976 of file TDynamicArray.h.
const_reverse_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::rend | ( | ) | const [inline] |
Definition at line 984 of file TDynamicArray.h.
reverse_iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::rend | ( | ) | [inline] |
Definition at line 992 of file TDynamicArray.h.
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign | ( | size_type | count, | |
const_reference | val | |||
) | [inline] |
Clear and assign a number of elements
count | number of elements to assign | |
val | value of new elements |
Definition at line 1002 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::capacity(), mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::clear(), mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::push_back(), and mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::reserve().
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign | ( | InputIterator | first, | |
InputIterator | end | |||
) | [inline] |
Clear and assign from iterators
first | start of sequence to assign to array | |
end | element beyond seqence (first element not to assign or end) |
Definition at line 1020 of file TDynamicArray.h.
01026 { 01027 clear(); 01028 if (static_cast<size_type>(end - first) > capacity()) 01029 { 01030 reserve(end - first); 01031 } 01032 while(first != end)
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::erase | ( | size_t | where | ) | [inline] |
Delete a single element from the array
where | index of element to delete |
Definition at line 1039 of file TDynamicArray.h.
01045 { 01046 mbo_tda_throw_if_not(logic_error, where < m_nSize); 01047 if (where == 0) 01048 { 01049 pop_front(); 01050 } 01051 else if (where + 1 == m_nSize) 01052 { 01053 pop_back(); 01054 } 01055 else 01056 { 01057 delete_at(where); 01058 01059 if (--m_nSize)
iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::erase | ( | iterator | where | ) | [inline] |
Delete a single element from the array
where | iterator designating the element to delete |
Definition at line 1066 of file TDynamicArray.h.
iterator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::erase | ( | iterator | first, | |
iterator | end | |||
) | [inline] |
first | start of element range to remove | |
end | element beyond range to delete |
Definition at line 1077 of file TDynamicArray.h.
01083 { 01084 size_type nLength = end - first; 01085 01086 if (nLength == 1) 01087 { 01088 return erase(first); 01089 } 01090 else if (nLength) 01091 { 01092 size_type nStart = first - begin(); 01093 size_type nPos = nStart + nLength; 01094 01095 while(nPos > nStart) 01096 { 01097 delete_at(--nPos); 01098 } 01099 01100 m_nSize -= nLength; 01101 01102 if (m_nSize) 01103 {
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::clear | ( | ) | [inline] |
Destruct all elements and free the element space and set m_nCapacity to zero.
Definition at line 1110 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign(), and mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::~TDynamicArray().
01116 { 01117 while(m_nSize) 01118 { 01119 m_alloc.destroy(m_alloc.address(m_acValues[--m_nSize])); 01120 } 01121 if (m_acValues) 01122 {
mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::reserve | ( | size_type | nNewCapacity | ) | throw ( bad_alloc , overflow_error ) [inline] |
Set new capacity. Value must be greater than or equal size().
nNewCapacity | new maximum number of elements |
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 1131 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::assign().
01137 { 01138 mbo_tda_throw_if_not(overflow_error, nNewCapacity >= m_nSize && nNewCapacity <= max_size()); 01139 01140 pointer pNewValues = m_alloc.reallocate(m_acValues, m_nCapacity, nNewCapacity); 01141
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::resize | ( | size_type | nNewSize | ) | throw ( bad_alloc , overflow_error ) [inline] |
Fill the array with default values until its size is greater than or equal to a new size. If the new size is less than the current size then the back elements are deleted until the size equals the new size.
nNewSize | new size of the array |
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 1152 of file TDynamicArray.h.
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::resize | ( | size_type | nNewSize, | |
value_type | value | |||
) | throw ( bad_alloc , overflow_error ) [inline] |
Fill the array with a given values until its size is greater than or equal to a new size. If the new size is less than the current size then the back elements are deleted until the size equals the new size.
nNewSize | new size of the array | |
value | new value to append if necessary |
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 1167 of file TDynamicArray.h.
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::limit_size | ( | size_type | nNewSize | ) | [inline] |
Ensure current size is equal or below a given limit
nNewSize | maximum size after call |
Definition at line 1183 of file TDynamicArray.h.
References mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::pop_back(), and mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::size().
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::check_resize | ( | ) | throw ( bad_alloc , overflow_error ) [inline, protected] |
Check whether adding a new element requires array reallocation. If necessary do so.
bad_alloc | if no memory could be allocated | |
overflow_error | if no elements can be appended |
Definition at line 1199 of file TDynamicArray.h.
01205 { 01206 if (m_nSize == m_nCapacity) 01207 {
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::delete_at | ( | size_type | nPos | ) | throw ( out_of_range ) [inline, protected] |
Delete an element at a given position (no destruction)
nPos | position to delete |
out_of_range | if nPos is invalid |
Definition at line 1216 of file TDynamicArray.h.
void mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::insert_at | ( | size_type | nPos, | |
const_reference | value | |||
) | throw ( out_of_range ) [inline, protected] |
Insert an element to a given position (use assignment)
nPos | position to insert at | |
value | element to insert |
out_of_range | if nPos is invalid |
Definition at line 1230 of file TDynamicArray.h.
allocator mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_alloc [protected] |
element allocator
Definition at line 1236 of file TDynamicArray.h.
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nSize [protected] |
current size (number of used or valid elements)
Definition at line 1237 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[]().
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nCapacity [protected] |
current max size (m_nCapacity >= m_nSize)
Definition at line 1238 of file TDynamicArray.h.
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nAppend [protected] |
number of elements added out of element space
Definition at line 1239 of file TDynamicArray.h.
size_type mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_nMaxSize [protected] |
maximum allowed capacity
Definition at line 1240 of file TDynamicArray.h.
pointer mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::m_acValues [protected] |
element storage (array)
Definition at line 1241 of file TDynamicArray.h.
Referenced by mbo::TDynamicArray< __ValueType, __Allocator, __MinSize, __Append >::operator[]().
Hosted on code.google.com | © Marcus Börger | Generated on Fri Jan 18 21:21:14 2008 for MBO-lib by ![]() |