General array class. More...
#include <itpp/base/array.h>
Public Member Functions | |
Array (const Factory &f=DEFAULT_FACTORY) | |
Default constructor. An element factory f can be specified. | |
Array (int n, const Factory &f=DEFAULT_FACTORY) | |
Create an Array of size n . An element factory f can be specified. | |
Array (const Array< T > &a, const Factory &f=DEFAULT_FACTORY) | |
Copy constructor. An element factory f can be specified. | |
Array (const std::string &values, const Factory &f=DEFAULT_FACTORY) | |
Create an Array from string. An element factory f can be specified. | |
Array (const char *values, const Factory &f=DEFAULT_FACTORY) | |
Create an Array from char*. An element factory f can be specified. | |
virtual | ~Array () |
Destructor. | |
T & | operator() (int i) |
Get the i element. | |
const T & | operator() (int i) const |
Get the i element. | |
const Array< T > | operator() (int i1, int i2) const |
Sub-array from element i1 to element i2 . | |
const Array< T > | operator() (const Array< int > &indices) const |
Sub-array with the elements given by the integer Array. | |
Array< T > | left (int n) const |
Get n left elements of the array. | |
Array< T > | right (int n) const |
Get n right elements of the array. | |
Array< T > | mid (int pos, int n) const |
Get n elements of the array starting from pos . | |
Array< T > & | operator= (const T &e) |
Assignment operator. | |
Array< T > & | operator= (const Array< T > &a) |
Assignment operator. | |
Array< T > & | operator= (const char *values) |
Assignment operator. | |
int | size () const |
Returns the number of data elements in the array object. | |
int | length () const |
Returns the number of data elements in the array object. | |
void | set_size (int n, bool copy=false) |
Resizing an Array<T>. | |
void | set_length (int n, bool copy=false) |
Resizing an Array<T>. | |
T | shift_right (const T &e) |
Shift in data at position 0. Return data from the last position. | |
const Array< T > | shift_right (const Array< T > &a) |
Shift in array at position 0. Return data from the last position. | |
T | shift_left (const T &e) |
Shift in data at the last position. Return data from position 0. | |
const Array< T > | shift_left (const Array< T > &a) |
Shift in array at the last position. Return data from position 0. | |
void | swap (int i, int j) |
Swap elements i and j. | |
void | set_subarray (int i1, int i2, const Array< T > &a) |
Set the subarray defined by indicies i1 to i2 to Array<T> a. | |
void | set_subarray (int i1, int i2, const T &t) |
Set the subarray defined by indicies i1 to i2 the element value t. | |
Protected Member Functions | |
void | alloc (int n) |
Allocate storage for an array of length n . | |
void | free () |
Free the storage space allocated by the array. | |
bool | in_range (int i) const |
Check whether index i is in the allowed range. | |
Protected Attributes | |
int | ndata |
The current number of elements in the Array. | |
T * | data |
A pointer to the data area. | |
const Factory & | factory |
Element factory (by default set to DEFAULT_FACTORY) | |
Friends | |
const Array< T > | concat (const Array< T > &a1, const T &e) |
Append element e to the end of the Array a . | |
const Array< T > | concat (const T &e, const Array< T > &a) |
Concat element e to the beginning of the Array a . | |
const Array< T > | concat (const Array< T > &a1, const Array< T > &a2) |
Concat Arrays a1 and a2 . | |
const Array< T > | concat (const Array< T > &a1, const Array< T > &a2, const Array< T > &a3) |
Concat Arrays a1 , a2 and a3 . | |
General array class.
This class is a general linear array class for arbitrary types. The operations and functions are the same as for the vector Vec
class (except for the arithmetics).
For rarely used types you will need to instantiate the class by
The following example shows how to define an Array of vectors:
For types T with istream operator>>
defined special constructor or operator=
or set_array
functions (see Related Functions) can be used to assign a string literal to an Array. The string literal has the same format that is used by the istream/ostream operators:
By default, Array elements are created using the default constructor for the element type. This can be changed by specifying a suitable Factory in the Array constructor call (see Detailed Description for Factory).
Generated on Sat Jul 6 2013 10:54:30 for IT++ by Doxygen 1.8.2