IT++ Logo Newcom Logo

itpp::Array< T > Class Template Reference

General array class. More...

#include <itpp/base/array.h>

List of all members.

Public Member Functions

 Array (const Factory &f=DEFAULT_FACTORY)
 Default constructor. An element factory f can be specified.
 Array (const 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)
 Copy constructor.
 Array (const Array< T > &a, const Factory &f)
 Constructor, similar to the copy constructor, but also takes an element factory f as argument.
virtual ~Array ()
 Destructor.
T & operator() (const int i)
 Get the i element.
const T & operator() (const int i) const
 Get the i element.
const Array< T > operator() (const int i1, const 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 > & operator= (const T &e)
 Assignment operator.
Array< T > & operator= (const Array< T > &a)
 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 (const int n, const bool copy=false)
 Resizing an Array<T>.
void set_length (const int n, const bool copy=false)
 Resizing an Array<T>.
shift_right (const T e)
 Shift in data at position 0. return data at last position.
const Array< T > shift_right (const Array< T > &a)
 Shift in array at position 0. return data at last position.
shift_left (const T e)
 Shift in data at position Ndata()-1. return data at last position.
const Array< T > shift_left (const Array< T > &a)
 Shift in array at position Ndata()-1. return data at last position.
void swap (const int i, const 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

bool in_range (const int i)
 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 (set to DEFAULT_FACTORY to use T default constructors only).

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.

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const Array< T > &a)
 Output stream for Array<T>. T must have ostream operator<< defined.
std::istream & operator>> (std::istream &is, Array< T > &a)
 Input stream for Array<T>. T must have istream operator>> defined.
void set_array (Array< T > &a, const char *values)
 Assign a C-style string to an Array<T>. T must have istream operator>> defined.
void set_array (Array< T > &a, const std::string &str)
 Assign a string to an Array<T>. T must have istream operator>> defined.


Detailed Description

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

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

    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, the set_array functions (see Related Functions) can be used to assign a string literal to an Array, with the same format that is used by the istream/ostream operators:

    // 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, the 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 97 of file array.h.


Constructor & Destructor Documentation

template<class T>
itpp::Array< T >::Array ( const Factory f = DEFAULT_FACTORY  )  [inline, explicit]

Default constructor. An element factory f can be specified.

Definition at line 179 of file array.h.

References itpp::Array< T >::data, and itpp::Array< T >::ndata.

template<class T>
itpp::Array< T >::Array ( const int  n,
const Factory f = DEFAULT_FACTORY 
) [inline]

Create an Array of size n. An element factory f can be specified.

Definition at line 186 of file array.h.

template<class T>
itpp::Array< T >::Array ( const Array< T > &  a  )  [inline]

Copy constructor.

Definition at line 192 of file array.h.

References itpp::Array< T >::data, and itpp::Array< T >::ndata.

template<class T>
itpp::Array< T >::Array ( const Array< T > &  a,
const Factory f 
) [inline]

Constructor, similar to the copy constructor, but also takes an element factory f as argument.

Definition at line 200 of file array.h.

References itpp::Array< T >::data, and itpp::Array< T >::ndata.

template<class T>
itpp::Array< T >::~Array (  )  [inline, virtual]

Destructor.

Definition at line 208 of file array.h.


Member Function Documentation

template<class T>
T& itpp::Array< T >::operator() ( const int  i  )  [inline]

Get the i element.

Definition at line 112 of file array.h.

template<class T>
const T& itpp::Array< T >::operator() ( const int  i  )  const [inline]

Get the i element.

Definition at line 115 of file array.h.

template<class T>
const Array< T > itpp::Array< T >::operator() ( const int  i1,
const int  i2 
) const [inline]

Sub-array from element i1 to element i2.

Definition at line 237 of file array.h.

References itpp::Array< T >::data, it_assert0, and itpp::Array< T >::ndata.

template<class T>
const Array< T > itpp::Array< T >::operator() ( const Array< int > &  indices  )  const [inline]

Sub-array with the elements given by the integer Array.

Definition at line 251 of file array.h.

References itpp::Array< T >::data, it_assert0, itpp::Array< T >::ndata, and itpp::Array< T >::size().

template<class T>
Array< T > & itpp::Array< T >::operator= ( const T &  e  )  [inline]

Assignment operator.

Definition at line 275 of file array.h.

References itpp::Array< T >::data, itpp::Array< T >::ndata, and itpp::Array< T >::set_size().

template<class T>
Array< T > & itpp::Array< T >::operator= ( const Array< T > &  a  )  [inline]

Assignment operator.

Definition at line 264 of file array.h.

References itpp::Array< T >::data, itpp::Array< T >::ndata, and itpp::Array< T >::set_size().

template<class T>
int itpp::Array< T >::size (  )  const [inline]

Returns the number of data elements in the array object.

Definition at line 137 of file array.h.

Referenced by itpp::TDL_Channel::calc_frequency_response(), itpp::TDL_Channel::calc_impulse_response(), itpp::concat(), itpp::TDL_Channel::init(), itpp::Parser::init(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile::low_level_read_lo(), itpp::it_file::low_level_write(), itpp::lshift_fix(), itpp::GFX::operator *=(), itpp::Array< T >::operator()(), itpp::GFX::operator+=(), itpp::Array< T >::operator>>(), itpp::Circular_Buffer< T >::put(), itpp::rshift_fix(), itpp::set_fix(), itpp::GF::set_size(), itpp::to(), itpp::unfix(), and itpp::TDL_Channel::~TDL_Channel().

template<class T>
int itpp::Array< T >::length (  )  const [inline]

Returns the number of data elements in the array object.

Definition at line 139 of file array.h.

Referenced by itpp::gmmtrain(), itpp::kmeans(), itpp::kmeansiter(), itpp::lbg(), and itpp::vqtrain().

template<class T>
void itpp::Array< T >::set_size ( const int  n,
const bool  copy = false 
) [inline]

Resizing an Array<T>.

Definition at line 286 of file array.h.

References itpp::Array< T >::data, itpp::min(), and itpp::Array< T >::ndata.

Referenced by itpp::TDL_Channel::calc_frequency_response(), itpp::TDL_Channel::calc_impulse_response(), itpp::Channel_Specification::discretize(), itpp::TDL_Channel::generate(), itpp::Circular_Buffer< T >::get(), itpp::Selective_Repeat_ARQ_Sender::get_link_packets(), itpp::GFX::GFX(), itpp::TDL_Channel::init(), itpp::Parser::init(), itpp::lbg(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile::low_level_read_lo(), itpp::GFX::operator *=(), itpp::GFX::operator+=(), itpp::Array< T >::operator=(), itpp::operator>>(), itpp::Array< T >::operator>>(), itpp::Circular_Buffer< T >::peek(), itpp::Circular_Buffer< T >::peek_reverse(), itpp::Newton_Search::search(), itpp::GFX::set(), itpp::Channel_Specification::set_channel_profile(), itpp::GFX::set_degree(), itpp::TDL_Channel::set_doppler_spectrum(), itpp::set_fix(), itpp::Convolutional_Code::set_generator_polynomials(), itpp::Array< DOPPLER_SPECTRUM >::set_length(), itpp::Selective_Repeat_ARQ_Receiver::set_parameters(), itpp::Selective_Repeat_ARQ_Sender::set_parameters(), itpp::GF::set_size(), and itpp::TDL_Channel::TDL_Channel().

template<class T>
void itpp::Array< T >::set_length ( const int  n,
const bool  copy = false 
) [inline]

Resizing an Array<T>.

Definition at line 143 of file array.h.

template<class T>
T itpp::Array< T >::shift_right ( const T  e  )  [inline]

Shift in data at position 0. return data at last position.

Definition at line 309 of file array.h.

References itpp::Array< T >::data, it_assert1, and itpp::Array< T >::ndata.

template<class T>
const Array< T > itpp::Array< T >::shift_right ( const Array< T > &  a  )  [inline]

Shift in array at position 0. return data at last position.

Definition at line 324 of file array.h.

References itpp::Array< T >::data, it_assert1, and itpp::Array< T >::ndata.

template<class T>
T itpp::Array< T >::shift_left ( const T  e  )  [inline]

Shift in data at position Ndata()-1. return data at last position.

Definition at line 341 of file array.h.

References itpp::Array< T >::data, and itpp::Array< T >::ndata.

template<class T>
const Array< T > itpp::Array< T >::shift_left ( const Array< T > &  a  )  [inline]

Shift in array at position Ndata()-1. return data at last position.

Definition at line 353 of file array.h.

References itpp::Array< T >::data, it_assert1, and itpp::Array< T >::ndata.

template<class T>
void itpp::Array< T >::swap ( const int  i,
const int  j 
) [inline]

Swap elements i and j.

Definition at line 372 of file array.h.

References itpp::Array< T >::data, itpp::Array< T >::in_range(), and it_assert1.

template<class T>
void itpp::Array< T >::set_subarray ( int  i1,
int  i2,
const Array< T > &  a 
) [inline]

Set the subarray defined by indicies i1 to i2 to Array<T> a.

Definition at line 382 of file array.h.

References itpp::Array< T >::data, itpp::Array< T >::in_range(), it_assert1, and itpp::Array< T >::ndata.

template<class T>
void itpp::Array< T >::set_subarray ( int  i1,
int  i2,
const T  t 
) [inline]

Set the subarray defined by indicies i1 to i2 the element value t.

Definition at line 395 of file array.h.

References itpp::Array< T >::data, itpp::Array< T >::in_range(), it_assert1, and itpp::Array< T >::ndata.

template<class T>
bool itpp::Array< T >::in_range ( const int  i  )  [inline, protected]

Check whether index i is in the allowed range.

Definition at line 163 of file array.h.

Referenced by itpp::Array< T >::set_subarray(), and itpp::Array< T >::swap().


Friends And Related Function Documentation

template<class T>
const Array<T> concat ( const Array< T > &  a1,
const T  e 
) [friend]

Append element e to the end of the Array a.

template<class T>
const Array<T> concat ( const T  e,
const Array< T > &  a 
) [friend]

Concat element e to the beginning of the Array a.

template<class T>
const Array<T> concat ( const Array< T > &  a1,
const Array< T > &  a2 
) [friend]

Concat Arrays a1 and a2.

template<class T>
const Array<T> concat ( const Array< T > &  a1,
const Array< T > &  a2,
const Array< T > &  a3 
) [friend]

Concat Arrays a1, a2 and a3.

template<class T>
std::ostream & operator<< ( std::ostream &  os,
const Array< T > &  a 
) [related]

Output stream for Array<T>. T must have ostream operator<< defined.

Definition at line 471 of file array.h.

template<class T>
std::istream & operator>> ( std::istream &  is,
Array< T > &  a 
) [related]

Input stream for Array<T>. T must have istream operator>> defined.

Definition at line 488 of file array.h.

References itpp::Array< T >::set_size(), and itpp::Array< T >::size().

template<class T>
void set_array ( Array< T > &  a,
const char *  values 
) [related]

Assign a C-style string to an Array<T>. T must have istream operator>> defined.

Definition at line 524 of file array.h.

Referenced by itpp::Array< T >::set_array().

template<class T>
void set_array ( Array< T > &  a,
const std::string &  str 
) [related]

Assign a string to an Array<T>. T must have istream operator>> defined.

Definition at line 535 of file array.h.

References itpp::Array< T >::set_array().


Member Data Documentation

template<class T>
int itpp::Array< T >::ndata [protected]

The current number of elements in the Array.

Definition at line 165 of file array.h.

Referenced by itpp::Array< T >::Array(), itpp::Array< DOPPLER_SPECTRUM >::in_range(), itpp::Array< DOPPLER_SPECTRUM >::length(), itpp::Array< T >::operator()(), itpp::Array< DOPPLER_SPECTRUM >::operator()(), itpp::Array< T >::operator=(), itpp::Array< T >::set_size(), itpp::Array< T >::set_subarray(), itpp::Array< T >::shift_left(), itpp::Array< T >::shift_right(), and itpp::Array< DOPPLER_SPECTRUM >::size().

template<class T>
T* itpp::Array< T >::data [protected]

A pointer to the data area.

Definition at line 167 of file array.h.

Referenced by itpp::Array< T >::Array(), itpp::Array< T >::operator()(), itpp::Array< DOPPLER_SPECTRUM >::operator()(), itpp::Array< T >::operator=(), itpp::Array< T >::set_size(), itpp::Array< T >::set_subarray(), itpp::Array< T >::shift_left(), itpp::Array< T >::shift_right(), and itpp::Array< T >::swap().

template<class T>
const Factory& itpp::Array< T >::factory [protected]

Element factory (set to DEFAULT_FACTORY to use T default constructors only).

Definition at line 169 of file array.h.


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

Generated on Wed Apr 18 11:23:39 2007 for IT++ by Doxygen 1.5.2