HermesCommon  2.0
Hermes::Hermes2D::Array< TYPE > Class Template Reference

A generic, inflatable array. More...

#include <array.h>

Public Member Functions

 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)
 
int add (TYPE item)
 Wrapper function for Hermes::vector::add() for compatibility purposes.
 
TYPE * add ()
 
void remove (int id)
 
int first (int idx=0)
 
int next (int idx=0)
 
int last (int idx=INT_MAX)
 
int prev (int idx=INT_MAX)
 
bool exists (int idx)
 Checks whether an element exists at position idx.
 
void force_size (int size)
 
void post_load_scan (int start=0)
 
void skip_slot ()
 
int get_size () const
 
int get_num_items () const
 
TYPE & get (int id) const
 
TYPE & operator[] (int id) const
 

Protected Attributes

Hermes::vector< TYPE * > pages
 
Hermes::vector< int > unused
 
int size
 
int nitems
 
bool append_only
 

Static Protected Attributes

static const int HERMES_PAGE_BITS = 10
 
static const int HERMES_PAGE_SIZE = 1 << HERMES_PAGE_BITS
 
static const int HERMES_PAGE_MASK = HERMES_PAGE_SIZE-1
 

Detailed Description

template<class TYPE>
class Hermes::Hermes2D::Array< TYPE >

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 'TYPE' must contain the members 'id' and 'unused' in order to be usable by this class.

Todo:
Is this dimension independent?

Definition at line 40 of file array.h.

Member Function Documentation

template<class TYPE >
TYPE* Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 114 of file array.h.

Referenced by Hermes::Hermes2D::Array< TYPE >::add().

template<class TYPE >
int Hermes::Hermes2D::Array< TYPE >::first ( int  idx = 0)
inline

Get the first index that is present and is equal to or greater than the passed idx. Typically used to begin an iteration over all indices present in the array.

Parameters
[in]idxOptional, default value 0 (finds the first present index).
Returns
  • First index present in the array that is equal or greater than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 161 of file array.h.

template<class TYPE >
void Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 235 of file array.h.

template<class TYPE >
int Hermes::Hermes2D::Array< TYPE >::last ( int  idx = INT_MAX)
inline

Get the last index present in the array that is equal to or less than the passed idx. Typically used to begin a reverse iteration over all indices present in the array.

Parameters
[in]idxOptional, default value (Word_t) -1 (finds the last index present in the array).
Returns
  • Last index present in the array that is equal or less than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 195 of file array.h.

template<class TYPE >
int Hermes::Hermes2D::Array< TYPE >::next ( int  idx = 0)
inline

Get the first index that is present and is greater than the passed idx. Typically used to continue an iteration over all indices present in the array.

Parameters
[in]idxIndex whose succesor we want to find. Optional, default value 0.
Returns
  • First idx present in the array that is greater than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 178 of file array.h.

template<class TYPE >
void Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 251 of file array.h.

template<class TYPE >
int Hermes::Hermes2D::Array< TYPE >::prev ( int  idx = INT_MAX)
inline

Get the last index present in the array that is less than the passed idx. Typically used to continue a reverse iteration over all indices present in the array.

Parameters
[in]idxIndex whose predecessor we want to find. Optional, default value (Word_t) -1.
Returns
  • Last index present in the array that is less than the passed idx (if found),
  • INVALID_IDX (if not found).

Definition at line 213 of file array.h.

template<class TYPE >
void Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 143 of file array.h.

template<class TYPE >
void Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 97 of file array.h.

template<class TYPE >
void Hermes::Hermes2D::Array< TYPE >::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.

Definition at line 261 of file array.h.

Member Data Documentation


The documentation for this class was generated from the following file: