Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

dolfin::Array< T > Class Template Reference

DON'T USE ARRAY. USE NEWARRAY INSTEAD. WILL REPLACE ARRAY IN FUTURE VERSIONS. More...

#include <Array.h>

Inheritance diagram for dolfin::Array< T >:

Inheritance graph
[legend]
Collaboration diagram for dolfin::Array< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Array ()
 Create an empty array of size zero.

 Array (int size)
 Create an empty array of given size.

 ~Array ()
 Destructor.

void init (int new_size)
 Initialise array to given size.

void resize (int new_size)
 Resize to an array of given size (keeping old elements).

void clear ()
 Clear array.

T & operator() (int i) const
 Indexing.

void operator= (const T &element)
 Set all elements equal to given element.

int size () const
 Return size of array.

bool empty () const
 Check if array is empty.

bool contains (const T &element)
 Check if the array contains a given element.

T & max () const
 Return the maximum element.

void remove (const T &element)
 Remove given element (first one matching).

void swap (int i, int j)
 Swap two elements.

Iterator begin () const
 Return an iterator to the beginning of the array.

void reset ()
 --- Special functions --- Assign 0 to all elements

void setsize (int new_size)
 Set size of array (useful in combination with init() or resize()).

void init ()
 Initialize array to previously specified size and assign 0 to all elements.

int add (T element)
 Add element to next available position.

void resize ()
 Remove empty elements.


Friends

class Iterator

Detailed Description

template<class T>
class dolfin::Array< T >

DON'T USE ARRAY. USE NEWARRAY INSTEAD. WILL REPLACE ARRAY IN FUTURE VERSIONS.

An Array is a list of constant size that can be used to store (often short) sets of data.

Array is constructed to use minimal storage. Only the size of the list and the elements themselves are stored.

In addition to working as a standard array (which can do only indexing), the Array class has a couple of special purpose functions that can be used to add elements dynamically. These should be used with caution! Consider using the List class instead. The add() functions adds a new element at the first empty position. A position is empty if for that element the operator ! returns true. An example:

Array<Node*> nodes(5); // Create array of length 5 nodes.reset(); // Assign 0 to all pointers while ( ... ) { // if ( nodes.add(node) != -1 ) { // Add node and check if full nodes.resize(2*nodes.size()); // If full, resize ... nodes.add(node); // ... and try again } // } //

If you want a list to which you can dynamically add elements, you should probably use the List class (for reasonably small sets of data) or the Table class (for large sets of data). Sometimes, however, an Array may be preferred even in a case where elements need to be added dynamically, for instance when a large number of such Arrays are needed (to save memory).

Note that iterators don't skip empty positions. Note also that to use the Array class in this way, the element class needs to implement the two operators

void operator= (int) (assignment to zero) bool operator! () (check if empty)

These two operators work naturally for pointers.


Constructor & Destructor Documentation

template<class T>
dolfin::Array< T >::Array  ) 
 

Create an empty array of size zero.

template<class T>
dolfin::Array< T >::Array int  size  ) 
 

Create an empty array of given size.

template<class T>
dolfin::Array< T >::~Array  ) 
 

Destructor.


Member Function Documentation

template<class T>
int dolfin::Array< T >::add element  ) 
 

Add element to next available position.

template<class T>
Array< T >::Iterator dolfin::Array< T >::begin  )  const
 

Return an iterator to the beginning of the array.

template<class T>
void dolfin::Array< T >::clear  ) 
 

Clear array.

template<class T>
bool dolfin::Array< T >::contains const T &  element  ) 
 

Check if the array contains a given element.

template<class T>
bool dolfin::Array< T >::empty  )  const
 

Check if array is empty.

template<class T>
void dolfin::Array< T >::init  ) 
 

Initialize array to previously specified size and assign 0 to all elements.

template<class T>
void dolfin::Array< T >::init int  new_size  ) 
 

Initialise array to given size.

template<class T>
T & dolfin::Array< T >::max  )  const
 

Return the maximum element.

template<class T>
T & dolfin::Array< T >::operator() int  i  )  const
 

Indexing.

template<class T>
void dolfin::Array< T >::operator= const T &  element  ) 
 

Set all elements equal to given element.

template<class T>
void dolfin::Array< T >::remove const T &  element  ) 
 

Remove given element (first one matching).

template<class T>
void dolfin::Array< T >::reset  ) 
 

--- Special functions --- Assign 0 to all elements

template<class T>
void dolfin::Array< T >::resize  ) 
 

Remove empty elements.

template<class T>
void dolfin::Array< T >::resize int  new_size  ) 
 

Resize to an array of given size (keeping old elements).

template<class T>
void dolfin::Array< T >::setsize int  new_size  ) 
 

Set size of array (useful in combination with init() or resize()).

template<class T>
int dolfin::Array< T >::size  )  const
 

Return size of array.

template<class T>
void dolfin::Array< T >::swap int  i,
int  j
 

Swap two elements.


Friends And Related Function Documentation

template<class T>
friend class Iterator [friend]
 


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


Documentation automatically generated with Doxygen on 10 Sep 2004.