#include <DetDesc/StaticArray.h>
Collaboration diagram for StaticArray< T, N >:
Public Types | |
typedef T | value_type |
types | |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef T & | reference |
typedef const T & | const_reference |
typedef std::size_t | size_type |
typedef std::ptrdiff_t | difference_type |
Public Member Functions | |
StaticArray () | |
constructor | |
void | push_back (const_reference x) |
add a single element | |
void | clear () |
clear all entries. | |
void | erase (iterator first, iterator last) |
erase a range | |
void | erase (iterator pos) |
erase a single element | |
void | insert (iterator pos, const_reference x) |
insert a single element | |
void | swap (StaticArray< T, N > &rhs) |
swap the contents of this array with that of another one | |
iterator | begin () |
iterator support | |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
reverse_iterator | rbegin () |
reverse iterator support | |
const_reverse_iterator | rbegin () const |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
size_type | size () const |
size and capacity | |
bool | empty () const |
size_type | max_size () const |
size_type | capacity () const |
void | reserve (size_type n) |
reference | operator[] (size_type i) |
element access | |
const_reference | operator[] (size_type i) const |
reference | at (size_type i) |
const_reference | at (size_type i) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
Private Member Functions | |
void | testcapacity (size_type newsize) const |
throw an exception if the capacity is not large enough to hold 'newsize' elements | |
Private Attributes | |
T | m_data [N] |
size_type | m_size |
elements |
It has a bit the look and feel of a std::vector, but with fixed capacity. Note that it does not call destructors or placement new, so it probably only works for basic types. The interface is also not entirely complete (e.g. no assignment, insert, or resize), but that can easily be changed when needed.
Note that there is also a more official implementation of this idea, namely the "alps/fixed_capacity_vector.h". I hope that that will make it to boost one day.
Definition at line 25 of file StaticArray.h.
typedef T StaticArray< T, N >::value_type |
typedef T* StaticArray< T, N >::iterator |
Definition at line 31 of file StaticArray.h.
typedef const T* StaticArray< T, N >::const_iterator |
Definition at line 32 of file StaticArray.h.
typedef std::reverse_iterator<iterator> StaticArray< T, N >::reverse_iterator |
Definition at line 33 of file StaticArray.h.
typedef std::reverse_iterator<const_iterator> StaticArray< T, N >::const_reverse_iterator |
Definition at line 34 of file StaticArray.h.
typedef T& StaticArray< T, N >::reference |
Definition at line 35 of file StaticArray.h.
typedef const T& StaticArray< T, N >::const_reference |
Definition at line 36 of file StaticArray.h.
typedef std::size_t StaticArray< T, N >::size_type |
Definition at line 37 of file StaticArray.h.
typedef std::ptrdiff_t StaticArray< T, N >::difference_type |
Definition at line 38 of file StaticArray.h.
StaticArray< T, N >::StaticArray | ( | ) | [inline] |
iterator StaticArray< T, N >::begin | ( | ) | [inline] |
const_iterator StaticArray< T, N >::begin | ( | ) | const [inline] |
iterator StaticArray< T, N >::end | ( | ) | [inline] |
const_iterator StaticArray< T, N >::end | ( | ) | const [inline] |
reverse_iterator StaticArray< T, N >::rbegin | ( | ) | [inline] |
reverse iterator support
Definition at line 56 of file StaticArray.h.
00056 { return reverse_iterator(end()) ; }
const_reverse_iterator StaticArray< T, N >::rbegin | ( | ) | const [inline] |
reverse_iterator StaticArray< T, N >::rend | ( | ) | [inline] |
const_reverse_iterator StaticArray< T, N >::rend | ( | ) | const [inline] |
size_type StaticArray< T, N >::size | ( | ) | const [inline] |
bool StaticArray< T, N >::empty | ( | ) | const [inline] |
size_type StaticArray< T, N >::max_size | ( | ) | const [inline] |
size_type StaticArray< T, N >::capacity | ( | ) | const [inline] |
void StaticArray< T, N >::reserve | ( | size_type | n | ) | [inline] |
reference StaticArray< T, N >::operator[] | ( | size_type | i | ) | [inline] |
const_reference StaticArray< T, N >::operator[] | ( | size_type | i | ) | const [inline] |
reference StaticArray< T, N >::at | ( | size_type | i | ) | [inline] |
const_reference StaticArray< T, N >::at | ( | size_type | i | ) | const [inline] |
reference StaticArray< T, N >::front | ( | ) | [inline] |
const_reference StaticArray< T, N >::front | ( | ) | const [inline] |
reference StaticArray< T, N >::back | ( | ) | [inline] |
const_reference StaticArray< T, N >::back | ( | ) | const [inline] |
void StaticArray< T, N >::push_back | ( | const_reference | x | ) | [inline] |
add a single element
Definition at line 84 of file StaticArray.h.
00084 { testcapacity(m_size+1) ; at(m_size++) = x ; }
void StaticArray< T, N >::clear | ( | ) | [inline] |
clear all entries.
note: no desctrutors called.
Definition at line 87 of file StaticArray.h.
00087 { m_size = 0 ; }
void StaticArray< T, N >::erase | ( | iterator | first, | |
iterator | last | |||
) | [inline] |
void StaticArray< T, N >::erase | ( | iterator | pos | ) | [inline] |
erase a single element
Definition at line 101 of file StaticArray.h.
00101 { return erase(pos,pos+1) ; }
void StaticArray< T, N >::insert | ( | iterator | pos, | |
const_reference | x | |||
) | [inline] |
insert a single element
Definition at line 104 of file StaticArray.h.
00104 { 00105 testcapacity(m_size+1) ; 00106 for(iterator next = pos; next<end(); ++next) *(next+1) = *(next) ; 00107 ++m_size ; 00108 *pos = x ; 00109 }
void StaticArray< T, N >::swap | ( | StaticArray< T, N > & | rhs | ) | [inline] |
void StaticArray< T, N >::testcapacity | ( | size_type | newsize | ) | const [inline, private] |
throw an exception if the capacity is not large enough to hold 'newsize' elements
Definition at line 119 of file StaticArray.h.
00119 { 00120 if( newsize > N ) 00121 throw GaudiException("DetDesc/StaticArray: trying to add data beyond maximum capacity of this container.\n Please increase the max_size template parameter.","DetDesc/StaticArray overflow", StatusCode::FAILURE) ; 00122 }
T StaticArray< T, N >::m_data[N] [private] |
Definition at line 125 of file StaticArray.h.
size_type StaticArray< T, N >::m_size [private] |