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.
- Examples:
-
tests/main.cpp.
Definition at line 55 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 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 insert (uint i, const T &x)
-
void remove (uint i, uint n=1)
- remove (delete) a subsequence of the array -- the array becomes 1D! [only with memMove!]
-
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
-
void delColumn (uint i)
- deletes the i-th column
|
-
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 ()
-
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!
-
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 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 memSize
- 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
getCarray!
).
-
bool temp
|
-
bool memMove
- be careful!!!; this option will modify the 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:
[]