Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Array
[Global data and functions]


Detailed Description

Global utilities for arrays.

#include <qgarlib/array.H>

They include:


Global functions about array indexes

template<class T>
int qgar::qgMinElement (const T *const anArray, int aSize)
 Return the index of the minimum element of an array.
template<class T>
int qgar::qgMinElement (const T *const anArray, int aFirstIdx, int aLastIdx)
 Return the index of the minimum element of a subrange of an array.
template<class T>
int qgar::qgMaxElement (const T *const anArray, int aSize)
 Return the index of the maximum element of an array.
template<class T>
int qgar::qgMaxElement (const T *const anArray, int aFirstIdx, int aLastIdx)
 Return the index of the maximum element of a subrange of an array.
template<class T>
int qgar::qgFind (const T *const anArray, int aSize, T aValue)
 Return the index of a value in an array.
template<class T>
int qgar::qgFind (const T *const anArray, int aFirstIdx, int aLastIdx, T aValue)
 Return the index of a value in a subrange of an array.

Global functions for array initialization

template<class T>
void qgar::qgFill (T *anArray, int aSize, T aValue)
 Set all elements of an array to a value.
template<class T>
void qgar::qgFill (T *anArray, int aFirstIdx, int aLastIdx, T aValue)
 Set each element of a subrange of an array.
template<class T>
void qgar::qgMemSet (T *anArray, int aSize)
 Set all bytes of an array to 0.
template<class T>
void qgar::qgMemSet (T *anArray, int aFirstIdx, int aLastIdx)
 Set all bytes of an array to 0.

Global mapping functions on arrays

template<class T>
void qgar::qgForEach (T *const aSource, T *aDest, int aSize, T(*anOperation)(const T &, const T &))
 Apply a function to pairs of elements from two arrays.
template<class T>
void qgar::qgForEach (T *const aSource, T *aDest, int aFirstIdx, int aLastIdx, T(*anOperation)(const T &, const T &))
 Apply a given function to pairs of elements from a subrange of two arrays.


Function Documentation

template<class T>
void qgar::qgFill T *  anArray,
int  aFirstIdx,
int  aLastIdx,
aValue
 

Set each element of a subrange of an array.

The subrange is defined as [aFirstIdx, aLastIdx].

Parameters:
anArray an array
aFirstIdx lower index of the elements to be set
aLastIdx upper index of the elements to be set
aValue value to set
Warning:
The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx].

Definition at line 286 of file array.H.

template<class T>
void qgar::qgFill T *  anArray,
int  aSize,
aValue
[inline]
 

Set all elements of an array to a value.

Parameters:
anArray an array
aSize size of the array
aValue value to assign to each element of the array
Warning:
The behavior of the function is undefined in case of wrong size.

Definition at line 262 of file array.H.

Referenced by qgar::ContrastEnhancedImage::ContrastEnhancedImage(), qgar::GenImage< T, CheckPolicy >::copyBox(), qgar::GenMask1d< T >::GenMask1d(), qgar::GenMask2d< T >::GenMask2d(), and qgar::NiblackBinaryImage::NiblackBinaryImage().

template<class T>
int qgar::qgFind const T *const   anArray,
int  aFirstIdx,
int  aLastIdx,
aValue
 

Return the index of a value in a subrange of an array.

The subrange is defined as [aFirstIdx, aLastIdx]. The function returns -1 if the value is not found.

Parameters:
anArray an array
aFirstIdx lower index of the elements to be examined
aLastIdx upper index of the elements to be examined
aValue a value to be searched in the array
Warning:
  • Operator '=' must be defined for objects of type T
  • The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx]

Definition at line 221 of file array.H.

template<class T>
int qgar::qgFind const T *const   anArray,
int  aSize,
aValue
 

Return the index of a value in an array.

Return -1 if the value is not found in the array.

Parameters:
anArray an array
aSize size of the array
aValue a value to be searched in the array
Warning:
  • Operator '=' must be defined for objects of type T
  • The behavior of the function is undefined in case of wrong size

Definition at line 196 of file array.H.

template<class T>
void qgar::qgForEach T *const   aSource,
T *  aDest,
int  aFirstIdx,
int  aLastIdx,
T(*)(const T &, const T &)  anOperation
 

Apply a given function to pairs of elements from a subrange of two arrays.

  • The two arguments and the result of the function must have the same type as the elements of the arrays.
  • For each index in the range [aFirstIdx, aLastIdx], the function is applied to the elements at current index i in both arrays: anOperation(aSource[i], aDest[i]). The value returned by the function is then stored at the current index in the destination array.

Parameters:
aSource source array (not modified)
aDest destination array (modified)
aFirstIdx lower index of the elements to be used
aLastIdx upper index of the elements to be used
anOperation operation to apply to the elements of the arrays
Warning:
The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx] or in case of overlaping arrays.

Definition at line 414 of file array.H.

template<class T>
void qgar::qgForEach T *const   aSource,
T *  aDest,
int  aSize,
T(*)(const T &, const T &)  anOperation
[inline]
 

Apply a function to pairs of elements from two arrays.

  • Both arrays must have the same size.
  • The two arguments and the result of the function must have the same type as the elements of the arrays.
  • For each index in the range determined by the given size, the function is applied to the elements at current index i in both arrays: anOperation(aSource[i], aDest[i]). The value returned by the function is then stored at the current index in the destination array.

Parameters:
aSource source array (not modified)
aDest destination array (modified)
aSize size of the arrays
anOperation operation to apply to the elements of the arrays
Warning:
The behavior of the function is undefined in case of wrong size or in case of overlaping arrays.

Definition at line 379 of file array.H.

template<class T>
int qgar::qgMaxElement const T *const   anArray,
int  aFirstIdx,
int  aLastIdx
 

Return the index of the maximum element of a subrange of an array.

The subrange is defined as [aFirstIdx, aLastIdx].

Parameters:
anArray an array
aFirstIdx lower index of the elements to be examined
aLastIdx upper index of the elements to be examined
Warning:
  • Operator '<' must be defined for objects of type T
  • The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx]

Definition at line 161 of file array.H.

template<class T>
int qgar::qgMaxElement const T *const   anArray,
int  aSize
 

Return the index of the maximum element of an array.

Parameters:
anArray an array
aSize size of the array
Warning:
  • Operator '>' must be defined for objects of type T
  • The behavior of the function is undefined in case of wrong size

Definition at line 137 of file array.H.

template<class T>
void qgar::qgMemSet T *  anArray,
int  aFirstIdx,
int  aLastIdx
[inline]
 

Set all bytes of an array to 0.

The subrange is defined as [aFirstIdx, aLastIdx]. The operation is performed using a low level memset.

Parameters:
anArray array to be set
aFirstIdx lower index of the elements to be set
aLastIdx upper index of the elements to be set
Warning:
The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx].

Definition at line 337 of file array.H.

template<class T>
void qgar::qgMemSet T *  anArray,
int  aSize
[inline]
 

Set all bytes of an array to 0.

The operation is performed using a low level memset.

Parameters:
anArray array to be set
aSize size of the array
Warning:
The behavior of the function is undefined in case of wrong size.

Definition at line 313 of file array.H.

Referenced by qgar::TTBinaryImage::TTBinaryImage().

template<class T>
int qgar::qgMinElement const T *const   anArray,
int  aFirstIdx,
int  aLastIdx
 

Return the index of the minimum element of a subrange of an array.

The subrange is defined as [aFirstIdx, aLastIdx].

Parameters:
anArray an array
aFirstIdx lower index of the elements to be examined
aLastIdx upper index of the elements to be examined
Warning:
  • Operator '<' must be defined on objects of type T
  • The behavior of the function is undefined in case of wrong range [aFirstIdx, aLastIdx]

Definition at line 105 of file array.H.

template<class T>
int qgar::qgMinElement const T *const   anArray,
int  aSize
[inline]
 

Return the index of the minimum element of an array.

Parameters:
anArray an array
aSize size of the array
Warning:
  • Operator '<' must be defined for objects of type T
  • The behavior of the function is undefined in case of wrong size

Definition at line 80 of file array.H.