Image Component Library (ICL)
Public Types | Public Member Functions | Private Attributes | List of all members
icl::utils::Array2D< T > Class Template Reference

Simple 2D-Array class that provides shallow copy per default. More...

#include <Array2D.h>

Public Types

typedef T * iterator
 iterator type (just a T*) More...
 
typedef const T * const_iterator
 const iterator type (just a const T*) More...
 

Public Member Functions

 Array2D ()
 Creates null instance. More...
 
 Array2D (int w, int h)
 Creates an uninitialized matrix of given size. More...
 
 Array2D (const Size &s)
 Creates an uninitialized matrix of given size. More...
 
template<class Init >
 Array2D (int w, int h, Init init)
 Creates an initialized matrix with given initializer. More...
 
template<class Init >
 Array2D (const Size &s, Init init)
 Creates an initialized matrix with given initializer. More...
 
 Array2D (int w, int h, T *data, bool deepCopy=false)
 Creates a matrix of size w x h, using given (optionally shared) data. More...
 
 Array2D (const Size &s, T *data, bool deepCopy=false)
 Creates a matrix of given Size, using given (optionally shared) data. More...
 
 Array2D (int w, int h, const T *data)
 Creates a matrix of size w x h, using given const data (always deep copy) More...
 
 Array2D (const Size &s, const T *data)
 Creates a matrix of given Size using given const data (always deep copy) More...
 
template<class Iterator >
 Array2D (int w, int h, Iterator begin, Iterator end)
 Creates a matrix of size w x h, initialized with content from given range. More...
 
template<class Iterator >
 Array2D (const Size &s, Iterator begin, Iterator end)
 Creates a matrix of size w x h, initialized with content from given range. More...
 
template<class Value >
void fill (Value val)
 fills the matrix with given value More...
 
template<class Iterator >
void assign (Iterator begin, Iterator end)
 Assigns the matrix from given range. More...
 
int getWidth () const
 returns the matrix width More...
 
int getHeight () const
 returns the matrix height More...
 
int getDim () const
 returns the matrix dimension (width*height) More...
 
const SizegetSize () const
 returns the matrix size More...
 
T & operator[] (int idx)
 returns element at given linear index More...
 
const T & operator[] (int idx) const
 returns element at given linear index (const) More...
 
T & operator() (int x, int y)
 returns element at given x,y position More...
 
const T & operator() (int x, int y) const
 returns element at given x,y position (const) More...
 
iterator begin ()
 upper left matrix element iterator More...
 
const_iterator begin () const
 upper left matrix element iterator (const) More...
 
iterator end ()
 upper left matrix element iterator More...
 
const_iterator end () const
 upper left matrix element iterator More...
 
Array2D< T > deepCopy () const
 returns a deep copy of this matrix More...
 
void detach ()
 ensures that the contained data is not shared by other instances More...
 
T * data ()
 returns the data pointer More...
 
const T * data () const
 returns the data pointer (const version) More...
 
const T & minElem (Point *pos=0) const
 returns the minumum element of the matrix (operator < must be defined on T) More...
 
const T & maxElem (Point *pos=0) const
 returns the maximum element of the matrix (operator < must be defined on T) More...
 
void setSize (const Size &size)
 sets a new size More...
 
template<class Init >
void setSize (const Size &size, const Init &init)
 sets size and fills with new entries More...
 

Private Attributes

Size m_size
 current dimension More...
 
SmartArray< T > m_data
 current data More...
 

Detailed Description

template<class T>
class icl::utils::Array2D< T >

Simple 2D-Array class that provides shallow copy per default.

This class replaces the former SimpleMatrix class

In contrast to the DynMatrix<T>-class template, the Array2D is designed for simple 2D data storage. The internal data layout is row-major i.e. the data is stored row-by-row. Array2D instances can be set up to have their own data, that is managed internally using a SmartArray<T> instance, or they can be wrapped around an existing data data pointer. In the latter case, the given data is not copied deeply which implicates that the data must remain valid.

Simplicity

In order to keep the class interface simple, Array2D instances cannot be resized. Simply assign a new instance with new size. Due to the internally used smart pointer, this entails only a very small and constant overhead

Member Typedef Documentation

◆ const_iterator

template<class T>
typedef const T* icl::utils::Array2D< T >::const_iterator

const iterator type (just a const T*)

◆ iterator

template<class T>
typedef T* icl::utils::Array2D< T >::iterator

iterator type (just a T*)

Constructor & Destructor Documentation

◆ Array2D() [1/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( )
inline

Creates null instance.

◆ Array2D() [2/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( int  w,
int  h 
)
inline

Creates an uninitialized matrix of given size.

◆ Array2D() [3/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( const Size s)
inline

Creates an uninitialized matrix of given size.

◆ Array2D() [4/11]

template<class T>
template<class Init >
icl::utils::Array2D< T >::Array2D ( int  w,
int  h,
Init  init 
)
inline

Creates an initialized matrix with given initializer.

◆ Array2D() [5/11]

template<class T>
template<class Init >
icl::utils::Array2D< T >::Array2D ( const Size s,
Init  init 
)
inline

Creates an initialized matrix with given initializer.

◆ Array2D() [6/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( int  w,
int  h,
T *  data,
bool  deepCopy = false 
)
inline

Creates a matrix of size w x h, using given (optionally shared) data.

◆ Array2D() [7/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( const Size s,
T *  data,
bool  deepCopy = false 
)
inline

Creates a matrix of given Size, using given (optionally shared) data.

◆ Array2D() [8/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( int  w,
int  h,
const T *  data 
)
inline

Creates a matrix of size w x h, using given const data (always deep copy)

◆ Array2D() [9/11]

template<class T>
icl::utils::Array2D< T >::Array2D ( const Size s,
const T *  data 
)
inline

Creates a matrix of given Size using given const data (always deep copy)

◆ Array2D() [10/11]

template<class T>
template<class Iterator >
icl::utils::Array2D< T >::Array2D ( int  w,
int  h,
Iterator  begin,
Iterator  end 
)
inline

Creates a matrix of size w x h, initialized with content from given range.

◆ Array2D() [11/11]

template<class T>
template<class Iterator >
icl::utils::Array2D< T >::Array2D ( const Size s,
Iterator  begin,
Iterator  end 
)
inline

Creates a matrix of size w x h, initialized with content from given range.

Member Function Documentation

◆ assign()

template<class T>
template<class Iterator >
void icl::utils::Array2D< T >::assign ( Iterator  begin,
Iterator  end 
)
inline

Assigns the matrix from given range.

◆ begin() [1/2]

template<class T>
iterator icl::utils::Array2D< T >::begin ( )
inline

upper left matrix element iterator

◆ begin() [2/2]

template<class T>
const_iterator icl::utils::Array2D< T >::begin ( ) const
inline

upper left matrix element iterator (const)

◆ data() [1/2]

template<class T>
T* icl::utils::Array2D< T >::data ( )
inline

returns the data pointer

◆ data() [2/2]

template<class T>
const T* icl::utils::Array2D< T >::data ( ) const
inline

returns the data pointer (const version)

◆ deepCopy()

template<class T>
Array2D<T> icl::utils::Array2D< T >::deepCopy ( ) const
inline

returns a deep copy of this matrix

◆ detach()

template<class T>
void icl::utils::Array2D< T >::detach ( )
inline

ensures that the contained data is not shared by other instances

This method ensure exclusive access to the internal data. I.e. If the data is used by another Array2D instance. This is also true for the shared-data mode, which behaves exactly like the non-shared data mode except that the data-pointer is finally not deleted

◆ end() [1/2]

template<class T>
iterator icl::utils::Array2D< T >::end ( )
inline

upper left matrix element iterator

◆ end() [2/2]

template<class T>
const_iterator icl::utils::Array2D< T >::end ( ) const
inline

upper left matrix element iterator

◆ fill()

template<class T>
template<class Value >
void icl::utils::Array2D< T >::fill ( Value  val)
inline

fills the matrix with given value

◆ getDim()

template<class T>
int icl::utils::Array2D< T >::getDim ( ) const
inline

returns the matrix dimension (width*height)

◆ getHeight()

template<class T>
int icl::utils::Array2D< T >::getHeight ( ) const
inline

returns the matrix height

◆ getSize()

template<class T>
const Size& icl::utils::Array2D< T >::getSize ( ) const
inline

returns the matrix size

◆ getWidth()

template<class T>
int icl::utils::Array2D< T >::getWidth ( ) const
inline

returns the matrix width

◆ maxElem()

template<class T>
const T& icl::utils::Array2D< T >::maxElem ( Point pos = 0) const
inline

returns the maximum element of the matrix (operator < must be defined on T)

If the optional argument pos is given and it is not 0, *pos is set to the maximum elements x,y position in the matrix

◆ minElem()

template<class T>
const T& icl::utils::Array2D< T >::minElem ( Point pos = 0) const
inline

returns the minumum element of the matrix (operator < must be defined on T)

If the optional argument pos is given and it is not 0, *pos is set to the minimum elements x,y position in the matrix

◆ operator()() [1/2]

template<class T>
T& icl::utils::Array2D< T >::operator() ( int  x,
int  y 
)
inline

returns element at given x,y position

◆ operator()() [2/2]

template<class T>
const T& icl::utils::Array2D< T >::operator() ( int  x,
int  y 
) const
inline

returns element at given x,y position (const)

◆ operator[]() [1/2]

template<class T>
T& icl::utils::Array2D< T >::operator[] ( int  idx)
inline

returns element at given linear index

◆ operator[]() [2/2]

template<class T>
const T& icl::utils::Array2D< T >::operator[] ( int  idx) const
inline

returns element at given linear index (const)

◆ setSize() [1/2]

template<class T>
void icl::utils::Array2D< T >::setSize ( const Size size)
inline

sets a new size

If the current size doesn't differ from the new size, nothing is done

◆ setSize() [2/2]

template<class T>
template<class Init >
void icl::utils::Array2D< T >::setSize ( const Size size,
const Init &  init 
)
inline

sets size and fills with new entries

If the current size doesn't differ from the new size, only the content is overwritte with init

Member Data Documentation

◆ m_data

template<class T>
SmartArray<T> icl::utils::Array2D< T >::m_data
private

current data

◆ m_size

template<class T>
Size icl::utils::Array2D< T >::m_size
private

current dimension


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