![]() |
#include <Array.h>
Inheritance diagram for dolfin::Array< T >:
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 |
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.
|
Create an empty array of size zero.
|
|
Create an empty array of given size.
|
|
Destructor.
|
|
Add element to next available position.
|
|
Return an iterator to the beginning of the array.
|
|
Clear array.
|
|
Check if the array contains a given element.
|
|
Check if array is empty.
|
|
Initialize array to previously specified size and assign 0 to all elements.
|
|
Initialise array to given size.
|
|
Return the maximum element.
|
|
Indexing.
|
|
Set all elements equal to given element.
|
|
Remove given element (first one matching).
|
|
--- Special functions --- Assign 0 to all elements
|
|
Remove empty elements.
|
|
Resize to an array of given size (keeping old elements).
|
|
Set size of array (useful in combination with init() or resize()).
|
|
Return size of array.
|
|
Swap two elements.
|
|
|
Documentation automatically generated with Doxygen on 10 Sep 2004.