IT++ Logo
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
itpp::Array< T > Class Template Reference

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>.
 
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.
 
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 Factoryfactory
 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.
 

Detailed Description

template<class T>
class itpp::Array< T >

General array class.

Author
Tobias Ringstrom and Adam Piatyszek

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

template class Array<type>;

The following example shows how to define an Array of vectors:

vec a = randn(10);
vec b = randn(20);
vec c = randn(30);
Array<vec> my_array(3);
my_array(0) = a;
my_array(1) = b;
my_array(2) = c;

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:

// Initialise an array with three bit vectors
Array<bvec> B = "{[1 0 1] [0 0 1] [1 0 0 0 1]}";
// Declare an Array of Arrays of vectors
Array<Array<ivec> > an_array;
// Assign with an Array containing 2 Arrays,
// the first Array containing [1 2] and
// the second Array containing [3 4 5] and [6 7]
set_array(an_array, "{{[1 2]} {[3 4 5] [6 7]}}");

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).

Definition at line 104 of file array.h.


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

Generated on Sat Jul 6 2013 10:54:30 for IT++ by Doxygen 1.8.2