mbo::TStaticArray< __ValueType, __MaxSize, __Allocator > Class Template Reference

static sized array of __ValueType More...

#include <TStaticArray.h>

Inheritance diagram for mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >:

Inheritance graph
{mbo::TStaticArrayEx\< __ValueType, __MaxSize, __Allocator \>\n||+ operator[]()\l+ operator[]()\l}
[legend]
Collaboration diagram for mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >:

Collaboration graph
{mbo::allocator\< __ValueType, __ReferenceType \>\n||+ address()\l+ address()\l+ allocate()\l+ deallocate()\l+ construct()\l+ max_size()\l}
[legend]

List of all members.

Public Types

enum  { max_size = __MaxSize }
typedef TStaticArray
< __ValueType, __MaxSize > 
_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

 TStaticArray ()
 TStaticArray (size_type initial_count)
 TStaticArray (size_type initial_count, const value_type &val)
 ~TStaticArray ()
size_type capacity () const
 
Returns:
maximum size of array

size_type size () const
 resize (size_type nNewSize) throw (overflow_error)
void resize (size_type nNewSize, value_type value) throw (overflow_error)
void limit_size (size_type nNewSize)
void reserve (size_type nNewSize) throw (overflow_error)
bool empty () const
bool full () const
const_reference at (size_type index) const throw (out_of_range)
reference at (size_type index) throw (out_of_range)
const_reference operator[] (size_type index) const throw (out_of_range)
reference operator[] (size_type index) throw (out_of_range)
const_reference front () const throw (out_of_range)
reference front () throw (out_of_range)
const_reference back () const throw (out_of_range)
reference back () throw (out_of_range)
void push_back (const_reference value) throw (out_of_range)
void pop_back () throw (out_of_range)
 Delete last element.
bool append (const_reference value)
reference append_element () throw (out_of_range)
void clear ()
const_iterator begin () const
iterator begin ()
const_iterator end () const
iterator end ()
const_iterator final () const
iterator final ()

Protected Types

typedef value_type value_array [__MaxSize]
 Type necessary to have the element array m_acValues as a reference to uninitialized raw memory m_data.
typedef value_arrayvalue_array_ref

Protected Attributes

allocator m_alloc
size_type m_nSize
value_array_ref m_acValues

Classes

class  const_iterator
 constant bidirectional iterator More...
class  iterator
 bidirectional iterator (non const) More...
struct  value_memory
 Type that holds ram memory for one element.


Detailed Description

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
class mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >

static sized array of __ValueType

Template base for static arrays.

The template can hold up to __MaxSize data containers. This value can later be checked by enum max_size. The actual amount of valid or used data can be determined by using size().

Note:
Derived type TStaticArrayEx allows access beyond the last used element using overloaded array access. It will create empty elements as needed using element default constructor.

For debugging purpose under Microsoft Visual Studio you might want to edit the debug helper file 'autoexp.dat' and add the following lines:

This class is distributed under the following license GNU Lesser General Public License, version 2.1.

Definition at line 121 of file TStaticArray.h.


Member Typedef Documentation

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef TStaticArray<__ValueType, __MaxSize> mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::_MyType

type itself

Definition at line 124 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::allocator

allocator type

Definition at line 125 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::size_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::size_type

type used for size and indexing

Definition at line 126 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::value_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::value_type

value type

Definition at line 127 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::reference

reference to value type

Definition at line 128 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::const_reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::const_reference

const reference to value type

Definition at line 129 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::pointer mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::pointer

pointer to value type

Definition at line 130 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::const_pointer mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::const_pointer

const pointer to value type

Definition at line 131 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef __Allocator::difference_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::difference_type

type used to calculate element position distances

Definition at line 132 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef std::reverse_iterator<iterator> mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::reverse_iterator

reverse iterator

See also:
MBO_TSA_STL_ITERATOR

Definition at line 698 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef std::reverse_iterator<const_iterator> mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::const_reverse_iterator

const reverse iterator

See also:
MBO_TSA_STL_ITERATOR

Definition at line 707 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef value_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::value_array[__MaxSize] [protected]

Type necessary to have the element array m_acValues as a reference to uninitialized raw memory m_data.

Definition at line 1031 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
typedef value_array& mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::value_array_ref [protected]

Definition at line 1033 of file TStaticArray.h.


Member Enumeration Documentation

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
anonymous enum

Enumerator:
max_size 

Definition at line 754 of file TStaticArray.h.

00755 {


Constructor & Destructor Documentation

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::TStaticArray (  )  [inline]

default constructor sets size to zero

Definition at line 714 of file TStaticArray.h.

00720         : m_nSize(0)

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::TStaticArray ( size_type  initial_count  )  [inline, explicit]

construct with initial amount of default elements

Definition at line 723 of file TStaticArray.h.

00723     {
00724     }
00725 
00728     explicit TStaticArray(_IN size_type initial_count)
00729         : m_nSize(0)
00730         , m_acValues(reinterpret_cast<value_array_ref>(m_acData))
00731         , m_alloc()
00732     {
00733         mbo_tsa_throw_if_not(out_of_range, initial_count <= __MaxSize);

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::TStaticArray ( size_type  initial_count,
const value_type val 
) [inline]

construct with initial amount of specified elements

Definition at line 737 of file TStaticArray.h.

00743         : m_nSize(0)
00744         , m_acValues(reinterpret_cast<value_array_ref>(m_acData))
00745         , m_alloc()
00746     {
00747         mbo_tsa_throw_if_not(out_of_range, initial_count <= __MaxSize);

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::~TStaticArray (  )  [inline]

Definition at line 749 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::append().

00749         {
00750             append(val);
00751         }
00752     }

Here is the call graph for this function:

mbo::TStaticArray::append


Member Function Documentation

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
size_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::capacity (  )  const [inline]

Returns:
maximum size of array

Definition at line 758 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::max_size.

00759          { max_size = __MaxSize };
00760 

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
size_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::size (  )  const [inline]

Returns:
the number of currently used or valid elements

Definition at line 765 of file TStaticArray.h.

Referenced by mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::limit_size().

00771     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::resize ( size_type  nNewSize  )  throw (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.

Parameters:
nNewSize new size of the array
Exceptions:
bad_alloc if no memory could be allocated
overflow_error if no elements can be appended

Definition at line 779 of file TStaticArray.h.

00785     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::resize ( size_type  nNewSize,
value_type  value 
) throw (overflow_error) [inline]

Fill the array with a given value 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.

Parameters:
nNewSize new size of the array
value new value to append if necessary
Exceptions:
bad_alloc if no memory could be allocated
overflow_error if no elements can be appended

Definition at line 794 of file TStaticArray.h.

00800     {
00801         if (nNewSize > max_size)
00802         {
00803             nNewSize = max_size;
00804             throw str::overflow_error("New size exceeds maximum size");
00805         }
00806         while(size() < nNewSize)
00807         {
00808             push_back(value);
00809         }

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::limit_size ( size_type  nNewSize  )  [inline]

Ensure current size is equal or below a given limit

Parameters:
nNewSize maximum size after call

Definition at line 815 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::pop_back(), and mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::size().

00821     {

Here is the call graph for this function:

mbo::TStaticArray::pop_backmbo::TStaticArray::size

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::reserve ( size_type  nNewSize  )  throw (overflow_error) [inline]

Parameters:
nNewSize new reserved size. Actually this is only present for compatibility.
Exceptions:
overflow_error if nNewSize > max_size

Definition at line 828 of file TStaticArray.h.

00834     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
bool mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::empty (  )  const [inline]

Returns:
whether the array is empty (e.g. size() == 0).

Definition at line 835 of file TStaticArray.h.

00841     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
bool mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::full (  )  const [inline]

Returns:
whether no more elements can be stored

Definition at line 842 of file TStaticArray.h.

00848     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::at ( size_type  index  )  const throw (out_of_range) [inline]

Parameters:
index of element to access
Returns:
const reference to value at specified index
Exceptions:
out_of_range if size() == 0

Definition at line 851 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_acValues, mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_nSize, and mbo_tsa_throw_if_not.

00857     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::at ( size_type  index  )  throw (out_of_range) [inline]

Parameters:
index of element to access
Returns:
reference to value at specified index
Exceptions:
out_of_range if index is invalid

Definition at line 861 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_acValues, mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_nSize, and mbo_tsa_throw_if_not.

00867     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::operator[] ( size_type  index  )  const throw (out_of_range) [inline]

Parameters:
index of element to access
Returns:
const reference to value at specified index
Exceptions:
out_of_range if size() == 0

Definition at line 871 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_acValues, mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_nSize, and mbo_tsa_throw_if_not.

00877     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::operator[] ( size_type  index  )  throw (out_of_range) [inline]

Parameters:
index of element to access
Returns:
reference to value at specified index
Exceptions:
out_of_range if index is invalid

Definition at line 881 of file TStaticArray.h.

References mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_acValues, mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_nSize, and mbo_tsa_throw_if_not.

00887     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::front (  )  const throw (out_of_range) [inline]

Returns:
const reference to first element
Exceptions:
out_of_range if size() == 0

Definition at line 890 of file TStaticArray.h.

00896     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::front (  )  throw (out_of_range) [inline]

Returns:
reference to first element
Exceptions:
out_of_range if size() == 0

Definition at line 899 of file TStaticArray.h.

00905     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::back (  )  const throw (out_of_range) [inline]

Returns:
const reference to last element
Exceptions:
out_of_range if size() == 0

Definition at line 908 of file TStaticArray.h.

00914     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::back (  )  throw (out_of_range) [inline]

Returns:
reference to last element
Exceptions:
out_of_range if size() == 0

Definition at line 917 of file TStaticArray.h.

00923     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::push_back ( const_reference  value  )  throw (out_of_range) [inline]

Append new data to end of array.

Parameters:
value new data to append
Exceptions:
out_of_range if size() >= __MaxSize

Definition at line 928 of file TStaticArray.h.

00934     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::pop_back (  )  throw (out_of_range) [inline]

Delete last element.

Exceptions:
out_of_range if size() == 0

Definition at line 937 of file TStaticArray.h.

Referenced by mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::limit_size().

00943     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
bool mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::append ( const_reference  value  )  [inline]

Append new data set if possible.

Parameters:
value new data to append
Returns:
whether data was appended

Definition at line 948 of file TStaticArray.h.

Referenced by mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::~TStaticArray().

00954     {
00955         if (m_nSize < max_size)
00956         {
00957             m_alloc.construct(m_alloc.address(m_acValues[m_nSize++]), value);
00958             return true;
00959         }

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
reference mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::append_element (  )  throw (out_of_range) [inline]

Returns:
reference to next element
Exceptions:
out_of_range if size() >= maxSize()

Definition at line 964 of file TStaticArray.h.

Referenced by mbo::TStaticArrayEx< __ValueType, __MaxSize, __Allocator >::operator[]().

00970     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
void mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::clear (  )  [inline]

remove all elements

Definition at line 973 of file TStaticArray.h.

00979     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::begin (  )  const [inline]

Returns:
const iterator initialized to first element

Definition at line 983 of file TStaticArray.h.

00989     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::begin (  )  [inline]

Returns:
iterator initialized to first element

Definition at line 990 of file TStaticArray.h.

00996     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::end (  )  const [inline]

Returns:
const iterator that points beyond the end of the used elements

Definition at line 997 of file TStaticArray.h.

01003     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::end (  )  [inline]

Returns:
iterator that points beyond the end of the used elements

Definition at line 1004 of file TStaticArray.h.

01010     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
const_iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::final (  )  const [inline]

Returns:
const iterator that points beyond the last element
Note:
this does not care about uninitialized elements

Definition at line 1012 of file TStaticArray.h.

01018     {

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
iterator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::final (  )  [inline]

Returns:
iterator that points beyond the last element
Note:
this does not care about uninitialized elements

Definition at line 1020 of file TStaticArray.h.

01026     {


Member Data Documentation

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
allocator mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_alloc [protected]

element allocator

Definition at line 1037 of file TStaticArray.h.

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
size_type mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_nSize [protected]

current size (number of used or valid elements)

Definition at line 1038 of file TStaticArray.h.

Referenced by mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::at(), mbo::TStaticArrayEx< __ValueType, __MaxSize, __Allocator >::operator[](), and mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::operator[]().

template<class __ValueType, size_t __MaxSize, class __Allocator = std::allocator<__ValueType>>
value_array_ref mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::m_acValues [protected]

element storage

Definition at line 1039 of file TStaticArray.h.

Referenced by mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::at(), mbo::TStaticArrayEx< __ValueType, __MaxSize, __Allocator >::operator[](), and mbo::TStaticArray< __ValueType, __MaxSize, __Allocator >::operator[]().


The documentation for this class was generated from the following file:
  Hosted on code.google.com  
© Marcus Börger
Generated on Fri Jan 18 21:21:14 2008 for MBO-lib by doxygen 1.5.4