MT::Array< T > Class Template Reference
#include <array.h>
List of all members.
Detailed Description
template<class T>
class MT::Array< T >
Simple array container to store 1-, 2-, 3-dimensional arrays; can buffer more memory than necessary for faster resize; enables non-const reference of subarrays; enables fast memove for elementary types. Please see also the reference for the
array.h header, which contains lots of functions that can be applied on Arrays.
NOTE: interfacing with ordinary C-buffers is simple, e.g. via Array::referTo
(Cbuffer,size) and Array::p
and Array::pp
Definition at line 59 of file array.h.
Public Member Functions
|
-
Array ()
- standard constructor -- this becomes an empty array
-
Array (const Array< T > &a)
- copy constructor
-
Array (uint i)
- constructor with resize
-
Array (uint i, uint j)
- constructor with resize
-
Array (uint i, uint j, uint k)
- constructor with resize
-
Array (const Array< T > &a, uint dim)
- this becomes a reference on a subdimension of
a
-
Array (const Array< T > &a, uint i, uint j)
- this becomes a reference on a subdimension of
a
-
Array (T *p, uint size)
- this becomes a reference on the C-array
p
-
Array (const char *str)
- initialize the array from a string (with operator<<)
-
IFEX (Array(Ex *_ex){ex=_ex;})~Array()
|
-
void clear ()
- frees all memory; this becomes an empty array
-
void resize (uint D0)
- resize 1D array, discard the previous contents
-
void resizeCopy (uint D0)
- resize but copy the previous contents
-
void resizeZero (uint D0)
- resize and initialize with zero
-
void reshape (uint D0)
- reshape the dimensionality (e.g. from 2D to 1D); throw an error if this actually requires to resize the memory
-
void resize (uint D0, uint D1)
-
void resizeCopy (uint D0, uint D1)
-
void reshape (uint D0, uint D1)
-
void resize (uint D0, uint D1, uint D2)
-
void resizeCopy (uint D0, uint D1, uint D2)
-
void reshape (uint D0, uint D1, uint D2)
-
void resize (const Array< T > &a)
- make it the same size as
a
-
void resizeCopy (const Array< T > &a)
-
template<class S> void resize (const Array< S > &a)
- resize to the same size as
a
-
template<class S> void resizeCopy (const Array< S > &a)
-
void makeSparse ()
-
uint memsize ()
- return the size of memory allocated in bytes
|
-
void resizeMEM (uint n, bool copy)
- allocate memory (maybe using fleximem)
-
void freeMEM ()
- free all memory and reset all pointers and sizes
|
-
void append (const T &x)
- append an element to the array -- the array becomes 1D!
-
void append (const Array< T > &x)
- append another array to the array (by copying it) -- the array might become 1D!
-
void append (const T *p, uint n)
- append a C array to the array (by copying it) -- the array might become 1D!
-
void replicate (uint copies)
-
void insert (uint i, const T &x)
- inserts x at the position i -- the array becomes 1D! [only with memMove!]
-
void remove (uint i, uint n=1)
- remove (delete) a subsequence of the array -- the array becomes 1D! [only with memMove!]
-
void removePerm (uint i)
- remove some element by permuting the last element in its place! -- the array becomes 1D!
-
void replace (uint i, uint n, const Array< T > &x)
- replace n elements at pos i by the sequence x -- the array becomes 1D! [only with memMove!]
-
void delRow (uint i)
- deletes the i-th row [must be 2D]
-
void delColumn (uint i)
- deletes the i-th column [must be 2D]
|
-
T & elem (uint i) const
- the
ith
element
-
T & operator() (uint i) const
- 1D reference
-
T & operator() (uint i, uint j) const
- 2D reference
-
T & operator() (uint i, uint j, uint k) const
- 3D reference
-
Array< T > operator[] (uint i) const
- get a subarray; use in conjuction with operator()() to get a reference
-
Array< T > & operator() ()
- convert a subarray into a reference (e.g. a[3]()+=.123)
-
uint maxIndex ()
- the index of the maxium; precondition: the comparision operator > exists for type T
-
void maxIndex (uint &i, uint &j)
- the index of the maxium; precondition: the comparision operator > exists for type T
-
void maxIndex (uint &i, uint &j, uint &k)
- the index of the maxium; precondition: the comparision operator > exists for type T
-
uint minIndex ()
- ...
-
bool contains (T &x)
-
Array< T > sub (uint i, int I) const
- a sub array of a 1D Array (corresponds to matlab [i:I]); when the upper limit I is -1, it is replaced by the max limit (like [i:])
-
Array< T > sub (uint i, int I, uint j, int J) const
- copies a sub array of a 2D Array (corresponds to matlab [i:I,j:J]); when the upper limits I or J are -1, they are replaced by the max limit (like [i:,j:])
-
Array< T > sub (uint i, int I, Array< uint > cols) const
- copies a selection of columns from a 2D array, the first index (rows) runs from i to I (as explained above) while the second index runs over the columns explicitly referred to by cols. (col doesn't have to be ordered or could also contain some columns multiply)
|
-
T ** getCarray ()
- allocates, sets and returns the
Array::pp
pointer (of type T**
)
-
T ** getPointers (Array< T * > &array2d) const
- returns an ordinary 2-dimensional C-pointer to the Array content. Requires the Array<T*> as buffer.
-
T *** getPointers (Array< T ** > &array3d, Array< T * > &array2d) const
- returns an ordinary 3-dimensional C-pointer-array
|
-
Array< T > & operator= (const T v)
- set all elements to value
v
-
Array< T > & operator= (const Array< T > &a)
- copy operator
-
void set (const char *str)
- reads it from the C string (by using std::istringstream)
-
void checkEx () const
-
template<class S> Array< T > & copy (const Array< S > &a)
- generic copy; precondition: operator (T)=(S) exists
-
void setZero (byte zero=0)
- same as memset(p,0,sizeT*N); precondition: memMove is true!
-
void setId (int n=-1)
- becomes the n-dim identity matrix [default: don't change dimension (already has to be squared matrix)]
-
template<class S> void copy (S *buffer, uint D0)
- copies the ordinary C buffer into this array
-
template<class S> void copy (S **buffer, uint D0, uint D1)
- copies the ordinary C buffer into this array
-
template<class S> void copyInto (S *buffer)
- copies this array into an ordinary C buffer !!be sure that buffer has the right size!!
-
template<class S> void copyInto2D (S **buffer)
- copies this array into an ordinary C buffer !!be sure that buffer has the right size!!
-
void referTo (const T *buffer, uint n)
- makes this array a reference to the C buffer
-
void referTo (const Array< T > &a)
- make this array a reference to the array
a
-
void referToSubRange (const Array< T > &a, uint i, int I)
- make this array a subarray reference to
a
-
void referToSubDim (const Array< T > &a, uint dim)
- make this array a subarray reference to
a
-
void referToSubDim (const Array< T > &a, uint i, uint j)
- make this array a subarray reference to
a
-
void redirect (const Array< T > &a, uint i)
-
void takeOver (Array< T > &a)
- takes over the memory buffer from a; afterwards, a is only a reference on the memory
|
|
|
-
void write (std::ostream &os, char *ARRAYSEP=" ", bool binary=false) const
- prototype for operator<<
-
void read (std::istream &is, bool binary=false)
- prototype for operator>>
-
const Array< T > & ioraw () const
- IO-manip: arrays will be streamed as raw (without tags).
-
const Array< T > & ionoraw () const
- IO-manip: arrays will be streamed non-raw (with tags).
-
void readRaw (std::istream &is, uint d1=0, uint d2=0)
- read array from stream without knowing yet the dimensionalities
-
void readRaw (const char *filename, uint d1=0, uint d2=0)
-
void writeRaw (const char *filename)
Public Attributes
-
T * p
- the pointer on the linear memory allocated
-
T * pstop
- end of memory (pstop is already out of the bound)
-
uint N
- number of elements
-
uint nd
- number of dimensions
-
uint d0
- 0th dim
-
uint d1
- 1st dim
-
uint d2
- 2nd dim
-
uint M
- size of allocated memory (may be greater than N)
-
bool reference
- true if this refers to some external memory
-
T ** pp
- C-style 2D pointer (only valid if created with
Array::getCarray!
).
-
MT::Array< uint > * sparse
- to allocate element, column and row index lists (1+d0+d1 lists)
-
bool temp
|
-
bool memMove
- be careful!!!; this option will modify the
Array::resizeCopy
: instead of calling the copy operator= for each element, the memory is moved with the memmove
command - works only if you know what you do ... [default is true for simple types and false for unknown ones]
-
bool flexiMem
- if flexiMem is true (which is default!) the resize method will (1) at the first call allocate the exact amount of memory, (2) at further calls of increasing memory allocate twice the memory needed or (3) at further calls of decreasing memory only free the memory if the new size is smaller than a fourth
Friends
The documentation for this class was generated from the following file:
[]