The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

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

Array Class Template Reference

#include <Array.h>

List of all members.

Public Types

enum  { array_dims = N }
typedef const T * const_iterator
typedef const T * const_pointer
typedef const T & const_reference
typedef ptrdiff_t difference_type
typedef T * iterator
typedef T * pointer
typedef T & reference
typedef size_t size_type
typedef T value_type

Public Member Functions

 Array (const Array< T, N > &A)
 Array (const ArraySize< N > &Dimensions, const T &Init=T())
 Array (const unsigned int *Dimensions, const T &Init=T())
 Array ()
const_iterator begin () const
iterator begin ()
void clear ()
unsigned int dimensions () const
bool empty () const
const_iterator end () const
iterator end ()
const RefArray< N > GetRefArray () const
RefArray< N > GetRefArray ()
Array< T, N > & operator= (const Array< T, N > &A)
const RefArray< N-1 > operator[] (size_type Index) const
RefArray< N-1 > operator[] (size_type Index)
bool resize (const ArraySize< N > &Dimensions, const T &Init=T(), bool PreserveElems=false)
bool resize (const unsigned int *Dimensions, const T &Init=T(), bool PreserveElems=false)
size_type size (unsigned int Dim) const
size_type size () const
void swap (Array< T, N > &A)
 ~Array ()

Protected Member Functions

void copy (const Array< T, N > &A, const T &Init=T())
void initialize (const T &Init=T())

Private Attributes

size_type m_nArrayElements
size_type m_NDimensions [N]
T * m_pArrayElements
size_type m_SubArrayLen [N]

Friends

bool operator== (const Array< T, N > &A, const Array< T, N > &B)

template<typename T, unsigned int N>
class Array< T, N >


Member Typedef Documentation

typedef const T* const_iterator
 

Definition at line 326 of file Array.h.

typedef const T* const_pointer
 

Definition at line 324 of file Array.h.

typedef const T& const_reference
 

Definition at line 322 of file Array.h.

typedef ptrdiff_t difference_type
 

Definition at line 328 of file Array.h.

typedef T* iterator
 

Definition at line 325 of file Array.h.

typedef T* pointer
 

Definition at line 323 of file Array.h.

typedef T& reference
 

Definition at line 321 of file Array.h.

typedef size_t size_type
 

Definition at line 327 of file Array.h.

typedef T value_type
 

Definition at line 320 of file Array.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
array_dims 

Definition at line 331 of file Array.h.

00331 { array_dims = N };


Constructor & Destructor Documentation

Array  )  [inline]
 

Array const unsigned int *  Dimensions,
const T &  Init = T()
[inline, explicit]
 

Array const ArraySize< N > &  Dimensions,
const T &  Init = T()
[inline, explicit]
 

Array const Array< T, N > &  A  )  [inline]
 

~Array  )  [inline]
 


Member Function Documentation

const_iterator begin  )  const [inline]
 

Definition at line 496 of file Array.h.

00496 { return m_pArrayElements; }

iterator begin  )  [inline]
 

Definition at line 495 of file Array.h.

Referenced by operator==().

00495 { return m_pArrayElements; }

void clear  )  [inline]
 

Definition at line 473 of file Array.h.

00474    { 
00475       delete [] m_pArrayElements; 
00476       m_pArrayElements=NULL; 
00477       m_nArrayElements=0;
00478 
00479       std::fill(m_NDimensions,m_NDimensions+N,0);
00480       std::fill(m_SubArrayLen,m_SubArrayLen+N,0);
00481    }

void copy const Array< T, N > &  A,
const T &  Init = T()
[inline, protected]
 

Definition at line 533 of file Array.h.

References Array::RefArray::copy(), i, Array::RefArray::initialize(), and size().

Referenced by resize().

00534    {
00535         size_type below=std::_MIN(size(1),A.size(1));
00536         size_type above=size(1);
00537 
00538         // Copy the elements we can copy
00539         for (size_type i=0;i<below;i++) 
00540             (*this)[i].copy(A[i],Init);
00541 
00542         // Reset the elements we can't copy
00543         for (size_type j=below;j<above;j++)
00544             (*this)[j].initialize(Init);
00545    }

Here is the call graph for this function:

unsigned int dimensions  )  const [inline]
 

Definition at line 514 of file Array.h.

00514 { return N; } 

bool empty  )  const [inline]
 

Definition at line 511 of file Array.h.

00511 { return m_nArrayElements==0; }

const_iterator end  )  const [inline]
 

Definition at line 498 of file Array.h.

00498 { return m_pArrayElements+m_nArrayElements; }

iterator end  )  [inline]
 

Definition at line 497 of file Array.h.

Referenced by operator==().

00497 { return m_pArrayElements+m_nArrayElements; }

const RefArray<N> GetRefArray  )  const [inline]
 

Definition at line 416 of file Array.h.

00417    {  
00418       assert(m_pArrayElements);
00419       return RefArray<N>(m_pArrayElements,m_NDimensions,m_SubArrayLen);
00420    }

RefArray<N> GetRefArray  )  [inline]
 

Definition at line 409 of file Array.h.

00410    {  
00411       assert(m_pArrayElements);
00412       return RefArray<N>(m_pArrayElements,m_NDimensions,m_SubArrayLen);
00413    }

void initialize const T &  Init = T()  )  [inline, protected]
 

Definition at line 548 of file Array.h.

References end.

Referenced by resize().

00549    {
00550       std::fill(begin(),end(),Init);
00551    }

Array<T,N>& operator= const Array< T, N > &  A  )  [inline]
 

Definition at line 484 of file Array.h.

00485    {
00486       if (&A!=this) // For efficiency 
00487       {
00488         Array<T,N> Temp(A);
00489         swap(Temp);
00490       }
00491       return *this;
00492    }

const RefArray<N-1> operator[] size_type  Index  )  const [inline]
 

Definition at line 400 of file Array.h.

00401    {  
00402       assert(m_pArrayElements);
00403       assert(Index<m_NDimensions[0]);
00404       return RefArray<N-1>(&m_pArrayElements[Index*m_SubArrayLen[0]],
00405                             m_NDimensions+1,m_SubArrayLen+1);
00406    }

RefArray<N-1> operator[] size_type  Index  )  [inline]
 

Definition at line 391 of file Array.h.

00392    {  
00393       assert(m_pArrayElements);
00394       assert(Index<m_NDimensions[0]);
00395       return RefArray<N-1>(&m_pArrayElements[Index*m_SubArrayLen[0]],
00396                             m_NDimensions+1,m_SubArrayLen+1);
00397    }

bool resize const ArraySize< N > &  Dimensions,
const T &  Init = T(),
bool  PreserveElems = false
[inline]
 

Definition at line 465 of file Array.h.

References ArraySize::Vect().

00466    {
00467       unsigned int Dims[N];
00468       std::copy(Dimensions.Vect().begin(),Dimensions.Vect().end(),Dims);
00469       return resize(Dims,Init,PreserveElems);
00470    }

Here is the call graph for this function:

bool resize const unsigned int *  Dimensions,
const T &  Init = T(),
bool  PreserveElems = false
[inline]
 

Definition at line 425 of file Array.h.

References copy(), i, initialize(), k, m_nArrayElements, m_NDimensions, m_pArrayElements, and m_SubArrayLen.

00426    {
00427       assert(Dimensions);
00428       
00429       Array<T,N> Temp; 
00430 
00431       // Calculate all the information you need to use the array
00432       Temp.m_nArrayElements=1;
00433       for (int i=0;i<N;i++)     
00434       {
00435          if (Dimensions[i]==0) 
00436             return false; // Check that no dimension was zero 
00437          Temp.m_nArrayElements*=Dimensions[i]; 
00438          Temp.m_NDimensions[i]=Dimensions[i];
00439          Temp.m_SubArrayLen[i]=1;              
00440          for (int k=N-1;k>i;k--)
00441             Temp.m_SubArrayLen[i]*=Dimensions[k];
00442       }  
00443 
00444       // Allocate new elements, let exception propagate 
00445       Temp.m_pArrayElements=new T[Temp.m_nArrayElements];
00446  
00447       // Some compilers might not throw exception if allocation fails
00448       if (!Temp.m_pArrayElements) 
00449           return false;
00450 
00451       // Copy the elements from the previous array if requested
00452       if (PreserveElems && !empty())
00453           Temp.copy(*this,Init);
00454       // Otherwise initialize them to the specified value
00455       else 
00456           Temp.initialize(Init);
00457 
00458       // Now swap this object with the temporary
00459       swap(Temp);
00460 
00461       return true; 
00462    }

Here is the call graph for this function:

size_type size unsigned int  Dim  )  const [inline]
 

Definition at line 504 of file Array.h.

00505    {  
00506       assert(Dim>=1 && Dim<=N); 
00507       return m_NDimensions[Dim-1];  
00508    }

size_type size  )  const [inline]
 

Definition at line 501 of file Array.h.

Referenced by copy().

00501 { return m_nArrayElements; }

void swap Array< T, N > &  A  )  [inline]
 

Definition at line 517 of file Array.h.

References m_nArrayElements, m_NDimensions, m_pArrayElements, and m_SubArrayLen.

00518    {
00519       std::swap(m_pArrayElements,A.m_pArrayElements); 
00520       std::swap(m_nArrayElements,A.m_nArrayElements); 
00521 
00522       std::swap_ranges(m_NDimensions,m_NDimensions+N,A.m_NDimensions);
00523       std::swap_ranges(m_SubArrayLen,m_SubArrayLen+N,A.m_SubArrayLen);
00524    }


Friends And Related Function Documentation

bool operator== const Array< T, N > &  A,
const Array< T, N > &  B
[friend]
 

Definition at line 560 of file Array.h.

00561 {
00562    return std::equal(A.m_NDimensions,A.m_NDimensions+N,B.m_NDimensions)
00563        && std::equal(A.begin(),A.end(),B.begin());
00564 }


Member Data Documentation

size_type m_nArrayElements [private]
 

Definition at line 336 of file Array.h.

Referenced by resize(), and swap().

size_type m_NDimensions[N] [private]
 

Definition at line 338 of file Array.h.

Referenced by operator==(), resize(), and swap().

T* m_pArrayElements [private]
 

Definition at line 335 of file Array.h.

Referenced by resize(), and swap().

size_type m_SubArrayLen[N] [private]
 

Definition at line 339 of file Array.h.

Referenced by resize(), and swap().


The documentation for this class was generated from the following file:
Generated on Mon Nov 8 17:08:29 2004 for MPT by  doxygen 1.3.9.1