Array< T > Class Template Reference

A generic, inflatable array. More...

#include <array.h>

List of all members.

Public Member Functions

 Array ()
 Array (Array &array)
 ~Array ()
void copy (const Array &array)
 Makes this array to hold a copy of another one.
void free ()
 Removes all elements from the array.
void set_append_only (bool append_only)
 Sets or resets the append-only mode. In append-only mode new elements are only added to the end of the array. This can be useful eg. when refining all elements of a mesh in which case the newly added elements must not be processed again by the for-loop. Normally this option should be off.
T * add ()
 Adds a new item to the array: either it is appended at the end or an unused item is reused.
void remove (int id)
 Removes the given item from the array, ie., marks it as unused. Note that the array is never physically shrinked. This should not be a problem, since meshes tend to grow rather than become smaller.
void force_size (int size)
 Cleans the array and reserves space for up to 'size' items. This is a special-purpose function, used for loading the array from file.
void post_load_scan (int start=0)
 Counts the items in the array and registers unused items. This is a special-purpose function, used after loading the array from file.
void skip_slot ()
 Adds an unused item at the end of the array and skips its ID forever. This is a special-purpose function used to create empty element slots.
int get_size () const
int get_num_items () const
T & get_item (int id) const
T & operator[] (int id) const

Protected Member Functions

 H2D_API_USED_STL_VECTOR (T *)
 H2D_API_USED_STL_VECTOR (int)

Protected Attributes

std::vector< T * > pages
std::vector< int > unused
int size
int nitems
bool append_only

Static Protected Attributes

static const int H2D_PAGE_BITS = 10
static const int H2D_PAGE_SIZE = 1 << H2D_PAGE_BITS
static const int H2D_PAGE_MASK = H2D_PAGE_SIZE-1

Detailed Description

template<class T>
class Array< T >

A generic, inflatable array.

This class is a generic dynamic array for storing nodes and elements of a mesh. All items contained in the array are assigned a unique id number. Internally, a list of unused items is maintained. Unused items (and their id numbers) are reused when new items are added to the array. The type 'T' must contain the members 'id' and 'unused' in order to be usable by this class.


Constructor & Destructor Documentation

template<class T>
Array< T >::Array (  )  [inline]
template<class T>
Array< T >::Array ( Array< T > &  array  )  [inline]
template<class T>
Array< T >::~Array (  )  [inline]

Member Function Documentation

template<class T>
T* Array< T >::add (  )  [inline]

Adds a new item to the array: either it is appended at the end or an unused item is reused.

Returns:
A reference to the newly allocated item of the array. The item is assigned an id and its used flag is set to 1.
template<class T>
void Array< T >::copy ( const Array< T > &  array  )  [inline]

Makes this array to hold a copy of another one.

template<class T>
void Array< T >::force_size ( int  size  )  [inline]

Cleans the array and reserves space for up to 'size' items. This is a special-purpose function, used for loading the array from file.

template<class T>
void Array< T >::free (  )  [inline]

Removes all elements from the array.

template<class T>
T& Array< T >::get_item ( int  id  )  const [inline]
template<class T>
int Array< T >::get_num_items (  )  const [inline]
template<class T>
int Array< T >::get_size (  )  const [inline]
template<class T>
Array< T >::H2D_API_USED_STL_VECTOR ( int   )  [protected]
template<class T>
Array< T >::H2D_API_USED_STL_VECTOR ( T *   )  [protected]
template<class T>
T& Array< T >::operator[] ( int  id  )  const [inline]
template<class T>
void Array< T >::post_load_scan ( int  start = 0  )  [inline]

Counts the items in the array and registers unused items. This is a special-purpose function, used after loading the array from file.

template<class T>
void Array< T >::remove ( int  id  )  [inline]

Removes the given item from the array, ie., marks it as unused. Note that the array is never physically shrinked. This should not be a problem, since meshes tend to grow rather than become smaller.

Parameters:
id [in] Item id number.
template<class T>
void Array< T >::set_append_only ( bool  append_only  )  [inline]

Sets or resets the append-only mode. In append-only mode new elements are only added to the end of the array. This can be useful eg. when refining all elements of a mesh in which case the newly added elements must not be processed again by the for-loop. Normally this option should be off.

template<class T>
void Array< T >::skip_slot (  )  [inline]

Adds an unused item at the end of the array and skips its ID forever. This is a special-purpose function used to create empty element slots.


Member Data Documentation

template<class T>
bool Array< T >::append_only [protected]
template<class T>
const int Array< T >::H2D_PAGE_BITS = 10 [static, protected]
template<class T>
const int Array< T >::H2D_PAGE_MASK = H2D_PAGE_SIZE-1 [static, protected]
template<class T>
const int Array< T >::H2D_PAGE_SIZE = 1 << H2D_PAGE_BITS [static, protected]
template<class T>
int Array< T >::nitems [protected]
template<class T>
std::vector<T*> Array< T >::pages [protected]
template<class T>
int Array< T >::size [protected]
template<class T>
std::vector<int> Array< T >::unused [protected]

The documentation for this class was generated from the following file:
Generated on Sat Jun 5 15:17:43 2010 for Hermes2D Library: Real Version by  doxygen 1.6.3