Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFixedArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFixedArray.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/01/30 18:19:21 $
00007   Version:   $Revision: 1.27 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkFixedArray_h
00018 #define __itkFixedArray_h
00019 
00020 #include "itkMacro.h"
00021 
00022 namespace itk
00023 {
00024 
00031 template <typename TVector>
00032 struct GetVectorDimension
00033 {
00034   itkStaticConstMacro(VectorDimension, unsigned int, TVector::Dimension);
00035 }; 
00036 
00037 
00038   
00058 template <typename TValueType, unsigned int VLength=3>
00059 class FixedArray
00060 {
00061 public:
00063   itkStaticConstMacro(Length, unsigned int, VLength);
00064   
00066   itkStaticConstMacro(Dimension, unsigned int, VLength);
00067   
00069   typedef TValueType  ValueType;
00070   
00072   typedef ValueType         CArray[VLength];
00073   
00075   typedef ValueType*        Iterator;
00076 
00078   typedef const ValueType*  ConstIterator;
00079 
00081   class ReverseIterator
00082   {
00083   public:
00084     explicit ReverseIterator(Iterator i): m_Iterator(i) {}
00085     Iterator operator++()        { return --m_Iterator; }
00086     Iterator operator++(int)     { return m_Iterator--; }
00087     Iterator operator--()        { return ++m_Iterator; }
00088     Iterator operator--(int)     { return m_Iterator++; }
00089     Iterator operator->() const  { return (m_Iterator-1); }
00090     ValueType& operator*() const { return *(m_Iterator-1); }
00091   private:
00092     Iterator m_Iterator;
00093   };
00094   
00096   class ConstReverseIterator
00097   {
00098   public:
00099     explicit ConstReverseIterator(ConstIterator i): m_Iterator(i) {}
00100     ConstIterator operator++()         { return --m_Iterator; }
00101     ConstIterator operator++(int)      { return m_Iterator--; }
00102     ConstIterator operator--()         { return ++m_Iterator; }
00103     ConstIterator operator--(int)      { return m_Iterator++; }
00104     ConstIterator operator->() const   { return (m_Iterator-1); }
00105     const ValueType& operator*() const { return *(m_Iterator-1); }
00106   private:
00107     ConstIterator m_Iterator;
00108   };  
00109   
00111   typedef ValueType*        pointer;
00112 
00114   typedef const ValueType*  const_pointer;
00115 
00117   typedef ValueType&        reference;
00118 
00120   typedef const ValueType&  const_reference;
00121   
00122   typedef unsigned int   SizeType;
00123   
00124 public:
00126   FixedArray();
00127   FixedArray(const FixedArray& r);
00128   FixedArray(const ValueType r[VLength]);
00129 
00132   ~FixedArray();
00133   
00135   FixedArray& operator= (const FixedArray& r);
00136   FixedArray& operator= (const ValueType r[VLength]);
00137     
00141   bool operator==(const FixedArray& r ) const;
00142   bool operator!=(const FixedArray& r ) const
00143     { return !operator==(r); }
00144   
00148         reference operator[](short index)                { return m_InternalArray[index]; }
00149   const_reference operator[](short index) const          { return m_InternalArray[index]; }
00150         reference operator[](unsigned short index)       { return m_InternalArray[index]; }
00151   const_reference operator[](unsigned short index) const { return m_InternalArray[index]; }
00152         reference operator[](int index)                  { return m_InternalArray[index]; }
00153   const_reference operator[](int index) const            { return m_InternalArray[index]; }
00154         reference operator[](unsigned int index)         { return m_InternalArray[index]; }
00155   const_reference operator[](unsigned int index) const   { return m_InternalArray[index]; }
00156         reference operator[](long index)                 { return m_InternalArray[index]; }
00157   const_reference operator[](long index) const           { return m_InternalArray[index]; }
00158         reference operator[](unsigned long index)        { return m_InternalArray[index]; }
00159   const_reference operator[](unsigned long index) const  { return m_InternalArray[index]; }
00160   
00162   ValueType* GetDataPointer() { return m_InternalArray; }
00163   const ValueType* GetDataPointer() const { return m_InternalArray; }
00164     
00166   Iterator      Begin();
00167   ConstIterator Begin() const;
00168   Iterator      End();
00169   ConstIterator End() const;
00170   ReverseIterator      rBegin();
00171   ConstReverseIterator rBegin() const;
00172   ReverseIterator      rEnd();
00173   ConstReverseIterator rEnd() const;
00174   SizeType      Size() const;
00175   void Fill(const ValueType&);
00176     
00177 private:
00179   CArray  m_InternalArray;
00180   
00181 public:
00182  
00183   static FixedArray Filled(const ValueType&);
00184 };
00185   
00186 template <typename TValueType, unsigned int VLength>
00187 std::ostream & operator<<(std::ostream &os, const FixedArray<TValueType,VLength> &arr)
00188 {
00189   os << "[";
00190   for (unsigned int i=0; i < VLength - 1; ++i)
00191     {
00192     os << arr[i] << ", ";
00193     }
00194   if (VLength >= 1)
00195     {
00196     os << arr[VLength-1];
00197     }
00198   os << "]" << std::endl;
00199   return os;
00200 }
00201 
00202 } // namespace itk
00203 
00204 #ifndef ITK_MANUAL_INSTANTIATION
00205 #include "itkFixedArray.txx"
00206 #endif
00207 
00208 #endif

Generated at Fri May 21 01:14:47 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000