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: 2002/09/13 21:21:31 $
00007   Version:   $Revision: 1.25 $
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 
00044 template <typename TValueType, unsigned int VLength=3>
00045 class FixedArray
00046 {
00047 public:
00049   itkStaticConstMacro(Length, unsigned int, VLength);
00050   
00052   typedef TValueType  ValueType;
00053   
00055   typedef ValueType         CArray[VLength];
00056   
00058   typedef ValueType*        Iterator;
00059 
00061   typedef const ValueType*  ConstIterator;
00062 
00064   class ReverseIterator
00065   {
00066   public:
00067     explicit ReverseIterator(Iterator i): m_Iterator(i) {}
00068     Iterator operator++()        { return --m_Iterator; }
00069     Iterator operator++(int)     { return m_Iterator--; }
00070     Iterator operator--()        { return ++m_Iterator; }
00071     Iterator operator--(int)     { return m_Iterator++; }
00072     Iterator operator->() const  { return (m_Iterator-1); }
00073     ValueType& operator*() const { return *(m_Iterator-1); }
00074   private:
00075     Iterator m_Iterator;
00076   };
00077   
00079   class ConstReverseIterator
00080   {
00081   public:
00082     explicit ConstReverseIterator(ConstIterator i): m_Iterator(i) {}
00083     ConstIterator operator++()         { return --m_Iterator; }
00084     ConstIterator operator++(int)      { return m_Iterator--; }
00085     ConstIterator operator--()         { return ++m_Iterator; }
00086     ConstIterator operator--(int)      { return m_Iterator++; }
00087     ConstIterator operator->() const   { return (m_Iterator-1); }
00088     const ValueType& operator*() const { return *(m_Iterator-1); }
00089   private:
00090     ConstIterator m_Iterator;
00091   };  
00092   
00094   typedef ValueType*        pointer;
00095 
00097   typedef const ValueType*  const_pointer;
00098 
00100   typedef ValueType&        reference;
00101 
00103   typedef const ValueType&  const_reference;
00104   
00105   typedef unsigned int   SizeType;
00106   
00107 public:
00109   FixedArray();
00110   FixedArray(const FixedArray& r);
00111   FixedArray(const ValueType r[VLength]);
00112 
00115   ~FixedArray();
00116   
00118   FixedArray& operator= (const FixedArray& r);
00119   FixedArray& operator= (const ValueType r[VLength]);
00120     
00124   bool operator==(const FixedArray& r ) const;
00125   bool operator!=(const FixedArray& r ) const
00126     { return !operator==(r); }
00127   
00131         reference operator[](short index)                { return m_InternalArray[index]; }
00132   const_reference operator[](short index) const          { return m_InternalArray[index]; }
00133         reference operator[](unsigned short index)       { return m_InternalArray[index]; }
00134   const_reference operator[](unsigned short index) const { return m_InternalArray[index]; }
00135         reference operator[](int index)                  { return m_InternalArray[index]; }
00136   const_reference operator[](int index) const            { return m_InternalArray[index]; }
00137         reference operator[](unsigned int index)         { return m_InternalArray[index]; }
00138   const_reference operator[](unsigned int index) const   { return m_InternalArray[index]; }
00139         reference operator[](long index)                 { return m_InternalArray[index]; }
00140   const_reference operator[](long index) const           { return m_InternalArray[index]; }
00141         reference operator[](unsigned long index)        { return m_InternalArray[index]; }
00142   const_reference operator[](unsigned long index) const  { return m_InternalArray[index]; }
00143   
00145   ValueType* GetDataPointer() { return m_InternalArray; }
00146   const ValueType* GetDataPointer() const { return m_InternalArray; }
00147     
00149   Iterator      Begin();
00150   ConstIterator Begin() const;
00151   Iterator      End();
00152   ConstIterator End() const;
00153   ReverseIterator      rBegin();
00154   ConstReverseIterator rBegin() const;
00155   ReverseIterator      rEnd();
00156   ConstReverseIterator rEnd() const;
00157   SizeType      Size() const;
00158   void Fill(const ValueType&);
00159     
00160 private:
00162   CArray  m_InternalArray;
00163   
00164 public:
00165  
00166   static FixedArray Filled(const ValueType&);
00167 };
00168   
00169 template <typename TValueType, unsigned int VLength>
00170 std::ostream & operator<<(std::ostream &os, const FixedArray<TValueType,VLength> &arr)
00171 {
00172   os << "[";
00173   for (unsigned int i=0; i < VLength - 1; ++i)
00174     {
00175     os << arr[i] << ", ";
00176     }
00177   if (VLength >= 1)
00178     {
00179     os << arr[VLength-1];
00180     }
00181   os << "]" << std::endl;
00182   return os;
00183 }
00184 
00185 } // namespace itk
00186 
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkFixedArray.txx"
00189 #endif
00190 
00191 #endif

Generated at Wed Mar 12 01:12:57 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000