array< T > Class Template Reference

Template class for an Array of type T based on a STL vector. More...

#include <array.h>

Inheritance diagram for array< T >:
vector carray< T >

List of all members.

Public Member Functions

template<>
string * printToString ()
Constructors

 array ()
 Default constructor.
 array (int32 size)
 Constructor: allocate size elements.
 array (T val, int32 size)
 Constructor: fill size elements with val.
 array (const array &ar2)
 Copy constructor.
 array (const T *ar2, int32 size)
 constructor with T* array.
 array (const string &str)
 string constructor
 array (const string &str, int32 &pos)
 string constructor with position in string
 ~array ()
 Destructor.
Vector wrapper functions

T & operator[] (int32 idx)
 access element at index idx
const T & operator[] (int32 idx) const
 access element at index idx
T & front ()
 access element at index idx
const T & front () const
 access element at index idx
T & back ()
 access element at index idx
const T & back () const
 access element at index idx
int32 size () const
 access element at index idx
void insert (int32 idx, int32 len, const T &val)
 access element at index idx
void erase (int32 idx, int32 len)
 access element at index idx
Operations on complete array

string * printToString ()
 prints the array to string
void print ()
 prints the array to stdout
string * toString ()
 creates a string containing a copy of the array data
void appendToString (string &str)
 appends a copy of the array data to a string
template<class T2 >
array< T2 > * convertTo ()
 convert into array of different type
Array copy & paste, etc.

array< T > * copy ()
 return a copy of the array
void put (const array &ar2)
 Put new data in current array.
void put (const array &ar2, int32 idx)
void put (const array &ar2, int32 idx, int32 len)
void put (T val, int32 idx)
 Put a single value in current array.
void fill (T val)
 Fill the array with a single value.
void fill (T val, int32 idx)
 Fill part of the array with a single value.
void fill (T val, int32 idx, int32 len)
void replace (const array &ar2)
 Replace this array by new data.
void replace (const array &ar2, int32 idx)
 Replace part of a array by new data.
void replace (const array &ar2, int32 idx, int32 len)
void replaceFill (T val, int32 num)
 Replace the array by num values.
void replaceFill (T val, int32 num, int32 idx)
 Replace part of the array by num values.
void replaceFill (T val, int32 num, int32 idx, int32 len)
void selectFill (T val, array< int32 > &idxs)
 fill elements indexed by idxs array with val
template<class T2 >
void selectPut (const array< T2 > &ar2, array< int32 > &idxs)
 fill elements indexed by idxs array with elements from ar2
array< T > * selectGet (array< int32 > &idxs)
 get values of current array indexed by idxs
void del (int32 idx, int32 len)
 return a copy of the array
void crop (int32 idx, int32 len)
 return a copy of the array
Array inspection

int32 find (T val)
 Find position of a specific value.
int32 find (T val, int32 idx)
int32 findNe (T val)
 Find position of a value not equal to the specific value.
int32 findNe (T val, int32 idx)
at (int32 idx)
 Return element at specified position.
max ()
 maximum value of the array
min ()
 minimum value of the array
array< int32 > * which ()
 returns indices of non-zero elements
array< int32 > * whichEq (T val)
 returns indices of elements equal to val
array< int32 > * whichLt (T val)
 returns indices of elements less than val
array< int32 > * whichLe (T val)
 returns indices of elements less than or equal to val
array< int32 > * whichGt (T val)
 returns indices of elements greater than val
array< int32 > * whichGe (T val)
 returns indices of elements greater than or equal to val
component wise operations

int32 nz ()
 number of non-zero elements
void scale (T mult)
 multiply all components by mult
template<class T2 >
void add (array< T2 > &ar2)
 add second array component by component
template<class T2 >
void add (array< T2 > &ar2, T mult)
 add second array multiplied by mult component by component
template<class T2 >
void sub (array< T2 > &ar2)
 subtract second array component by component
template<class T2 >
bool isSubsetOf (array< T2 > &ar2)
 true if current array has zeros wherever ar2 has zeroes
template<class T2 >
bool isSetEq (array< T2 > &ar2)
 combine arrays using AND operator
template<class T2 >
void AND (array< T2 > &ar2)
 combine arrays using AND operator
template<class T2 >
int32 ANDnz (array< T2 > &ar2)
 size of cutset
template<class T2 >
void OR (array< T2 > &ar2)
 combine arrays using OR operator
template<class T2 >
int32 ORnz (array< T2 > &ar2)
 size of set union
template<class T2 >
void subSet (array< T2 > &ar2)
 substract(boolean) ar2 from current array
template<class T2 >
int32 subSetnz (array< T2 > &ar2)
 size of set substraction (substract(boolean) ar2 from current array)

Protected Member Functions

void _set (const array &ar2, int32 idx, int32 len)
 internal method copying data from a different array to the current array
void _fill (T val, int32 idx, int32 len)
 internal method writing single values in the array
void _arrange (int32 idx, int32 &len, int32 srclen, bool repl)
 internal method reserving the place in the current array

Detailed Description

template<class T>
class array< T >

Template class for an Array of type T based on a STL vector.

Provides routines for manipulating the vector, inlcuding arithmetical (i.e. adding) and logical (i.e. AND, OR) and set operations. Contains routines to insert and overwrite data without using iterators.


Constructor & Destructor Documentation

template<class T >
array< T >::array (  )  [inline]

Default constructor.

template<class T >
array< T >::array ( int32  size  )  [inline]

Constructor: allocate size elements.

template<class T>
array< T >::array ( val,
int32  size 
) [inline]

Constructor: fill size elements with val.

template<class T>
array< T >::array ( const array< T > &  ar2  )  [inline]

Copy constructor.

template<class T>
array< T >::array ( const T *  ar2,
int32  size 
) [inline]

constructor with T* array.

template<class T>
array< T >::array ( const string &  str  )  [inline]

string constructor

template<class T>
array< T >::array ( const string &  str,
int32 pos 
) [inline]

string constructor with position in string

template<class T >
array< T >::~array (  )  [inline]

Destructor.


Member Function Documentation

template<class T >
void array< T >::_arrange ( int32  idx,
int32 len,
int32  srclen,
bool  repl 
) [inline, protected]

internal method reserving the place in the current array

Parameters:
idx index at which new data should be placed
len length of the part in current array that should be replaced (by reference - may be changed)
srclen length of the new data
repl true if the new data should replace the old part or false if this should overwrite

Note: len is always set to srclen, indicating that in the arranged array len=srclen elements are to be written

template<class T>
void array< T >::_fill ( val,
int32  idx,
int32  len 
) [inline, protected]

internal method writing single values in the array

Parameters:
val value with which part of the array should be filled
idx index at which new data should be placed
len length of the part in current array that should be filled

Fills len elements with val from index idx on. The length of the current array should already be arranged acordingly.

template<class T >
void array< T >::_set ( const array< T > &  ar2,
int32  idx,
int32  len 
) [inline, protected]

internal method copying data from a different array to the current array

Parameters:
ar2 array containing the data to read from
idx index at which the copied data should be placed
len length of the part in current array that should be filled

Fills len elements with data from ar2 from position idx in the current array. The length of the current array should already be arranged accordingly.

template<class T>
template<class T2 >
void array< T >::add ( array< T2 > &  ar2,
mult 
) [inline]

add second array multiplied by mult component by component

template<class T >
template<class T2 >
void array< T >::add ( array< T2 > &  ar2  )  [inline]

add second array component by component

template<class T >
template<class T2 >
void array< T >::AND ( array< T2 > &  ar2  )  [inline]

combine arrays using AND operator

template<class T >
template<class T2 >
int32 array< T >::ANDnz ( array< T2 > &  ar2  )  [inline]

size of cutset

template<class T >
void array< T >::appendToString ( string &  str  )  [inline]

appends a copy of the array data to a string

template<class T >
T array< T >::at ( int32  idx  )  [inline]

Return element at specified position.

Parameters:
idx index of queried element

returns reference to original element

template<class T >
const T & array< T >::back (  )  const [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
T & array< T >::back (  )  [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
template<class T2 >
array< T2 > * array< T >::convertTo (  )  [inline]

convert into array of different type

template<class T >
array< T > * array< T >::copy (  )  [inline]

return a copy of the array

template<class T >
void array< T >::crop ( int32  idx,
int32  len 
) [inline]

return a copy of the array

template<class T >
void array< T >::del ( int32  idx,
int32  len 
) [inline]

return a copy of the array

template<class T >
void array< T >::erase ( int32  idx,
int32  len 
) [inline]

access element at index idx

Parameters:
idx element index to access
template<class T>
void array< T >::fill ( val,
int32  idx,
int32  len 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
val value with which part of the array should be filled
idx index at which ar2 should be placed
len length of the part which should be replaced

Everything from idx to idx+len of the array is filled with val. The length of the array is changed if idx+len is larger than the current len.

template<class T>
void array< T >::fill ( val,
int32  idx 
) [inline]

Fill part of the array with a single value.

Parameters:
val value with which part of the array should be filled
idx index at which ar2 should be placed

Everything from idx to the end of the array is filled with val.

template<class T>
void array< T >::fill ( val  )  [inline]

Fill the array with a single value.

Parameters:
val value with which part of the array should be filled
idx index at which ar2 should be placed

Everything from the beginning to the end of the array is filled with val.

template<class T>
int32 array< T >::find ( val,
int32  idx 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
val value to be looked for

Returns the index of the first element after or at position idx with value val in the array. Returns -1 of val is not found.

template<class T>
int32 array< T >::find ( val  )  [inline]

Find position of a specific value.

Parameters:
val value to be looked for

Returns the index of the first element with value val in the array. Returns -1 of val is not found.

template<class T>
int32 array< T >::findNe ( val,
int32  idx 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
val value to be looked for

Returns the index of the first element after or at position idx whose value is not val in the array. Returns -1 of value!=val is not found.

template<class T>
int32 array< T >::findNe ( val  )  [inline]

Find position of a value not equal to the specific value.

Parameters:
val value to be looked for

Returns the index of the first element whose value is not val in the array. Returns -1 of value!=val is not found.

template<class T >
const T & array< T >::front (  )  const [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
T & array< T >::front (  )  [inline]

access element at index idx

Parameters:
idx element index to access
template<class T>
void array< T >::insert ( int32  idx,
int32  len,
const T &  val 
) [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
template<class T2 >
bool array< T >::isSetEq ( array< T2 > &  ar2  )  [inline]

combine arrays using AND operator

template<class T >
template<class T2 >
bool array< T >::isSubsetOf ( array< T2 > &  ar2  )  [inline]

true if current array has zeros wherever ar2 has zeroes

template<class T >
T array< T >::max (  )  [inline]

maximum value of the array

Note: returns (T) 0 if length of array is 0, so check length beforehand

template<class T >
T array< T >::min (  )  [inline]

minimum value of the array

Note: returns (T) 0 if length of array is 0, so check length beforehand

template<class T >
int32 array< T >::nz (  )  [inline]

number of non-zero elements

template<class T >
const T & array< T >::operator[] ( int32  idx  )  const [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
T & array< T >::operator[] ( int32  idx  )  [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
template<class T2 >
void array< T >::OR ( array< T2 > &  ar2  )  [inline]

combine arrays using OR operator

template<class T >
template<class T2 >
int32 array< T >::ORnz ( array< T2 > &  ar2  )  [inline]

size of set union

template<class T >
void array< T >::print (  )  [inline]

prints the array to stdout

Note: This only works for certain types T

template<>
string * array< double >::printToString (  )  [inline]

Reimplemented in carray< T >.

template<class T >
string * array< T >::printToString (  )  [inline]

prints the array to string

Note: This only works for certain types T

Reimplemented in carray< T >.

template<class T>
void array< T >::put ( val,
int32  idx 
) [inline]

Put a single value in current array.

Parameters:
val value to be set
idx index at which the value should be placed

Put one element of value val at position idx. The length of the array is changed if idx >= length of current array.

template<class T >
void array< T >::put ( const array< T > &  ar2,
int32  idx,
int32  len 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
ar2 array containing the data to replace
idx index at which ar2 should be placed
len length of the part which should be replaced

Array ar2 is put at position idx of the this array, overwriting the current content (up to len elements). The length of this array is increased if idx+len is larger that the current length. In the current array, len elements are reserved even if the length of ar2 is shorter.

template<class T >
void array< T >::put ( const array< T > &  ar2,
int32  idx 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
ar2 array containing the data to replace
idx index at which ar2 should be placed

Array ar2 is put at position idx of the this array, overwriting the current content. The length of this array is increased if len(ar2)+idx is larger than the current array.

template<class T >
void array< T >::put ( const array< T > &  ar2  )  [inline]

Put new data in current array.

Parameters:
ar2 array containing the new data

Array ar2 is put at position 0 of the this array, overwriting the current content. The length of this array is increased if ar2 is larger than the current array.

template<class T >
void array< T >::replace ( const array< T > &  ar2,
int32  idx,
int32  len 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
ar2 array containing the data to replace
idx index at which ar2 should be placed
len length of the part which should be replaced

Note: everything from idx to idx+len of the array is replaced by ar2. The length of the array is changed accordingly.

template<class T >
void array< T >::replace ( const array< T > &  ar2,
int32  idx 
) [inline]

Replace part of a array by new data.

Parameters:
ar2 array containing the data to replace
idx index at which ar2 should be placed

Note: everything from idx to the end of the array is replaced by ar2. The length of the array is changed acordingly.

template<class T >
void array< T >::replace ( const array< T > &  ar2  )  [inline]

Replace this array by new data.

Parameters:
ar2 array containing the data to replace

Note: This array is replaced by ar2. The length of the array is now the length of ar2.

template<class T>
void array< T >::replaceFill ( val,
int32  num,
int32  idx,
int32  len 
) [inline]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
val value with which part of the array should be filled
num number of values to be inserted
idx index at which ar2 should be placed
len length of the part which should be replaced

Everything from idx to idx+len of the array is replaced by num values. The length of the array is changed acordingly.

template<class T>
void array< T >::replaceFill ( val,
int32  num,
int32  idx 
) [inline]

Replace part of the array by num values.

Parameters:
val value with which part of the array should be filled
num number of values to be inserted
idx index at which ar2 should be placed

everything from idx to the end of the array is replaced by num values. The length of the array is changed acordingly.

template<class T>
void array< T >::replaceFill ( val,
int32  num 
) [inline]

Replace the array by num values.

Parameters:
val value with which part of the array should be filled
num number of values to be inserted

Everything from the beginning to the end of the array is replaced by num values val. The length of the array will be num.

template<class T>
void array< T >::scale ( mult  ) 

multiply all components by mult

template<class T>
void array< T >::selectFill ( val,
array< int32 > &  idxs 
) [inline]

fill elements indexed by idxs array with val

template<class T >
array< T > * array< T >::selectGet ( array< int32 > &  idxs  )  [inline]

get values of current array indexed by idxs

template<class T >
template<class T2 >
void array< T >::selectPut ( const array< T2 > &  ar2,
array< int32 > &  idxs 
) [inline]

fill elements indexed by idxs array with elements from ar2

template<class T >
int32 array< T >::size (  )  const [inline]

access element at index idx

Parameters:
idx element index to access
template<class T >
template<class T2 >
void array< T >::sub ( array< T2 > &  ar2  )  [inline]

subtract second array component by component

template<class T >
template<class T2 >
void array< T >::subSet ( array< T2 > &  ar2  )  [inline]

substract(boolean) ar2 from current array

template<class T >
template<class T2 >
int32 array< T >::subSetnz ( array< T2 > &  ar2  )  [inline]

size of set substraction (substract(boolean) ar2 from current array)

template<class T >
string * array< T >::toString (  )  [inline]

creates a string containing a copy of the array data

template<class T >
array< int32 > * array< T >::which (  )  [inline]

returns indices of non-zero elements

template<class T>
array< int32 > * array< T >::whichEq ( val  )  [inline]

returns indices of elements equal to val

template<class T>
array< int32 > * array< T >::whichGe ( val  )  [inline]

returns indices of elements greater than or equal to val

template<class T>
array< int32 > * array< T >::whichGt ( val  )  [inline]

returns indices of elements greater than val

template<class T>
array< int32 > * array< T >::whichLe ( val  )  [inline]

returns indices of elements less than or equal to val

template<class T>
array< int32 > * array< T >::whichLt ( val  )  [inline]

returns indices of elements less than val


The documentation for this class was generated from the following file:
Generated on Tue May 3 16:06:08 2011 for Scopes C++ Core by  doxygen 1.6.3