VTK
dox/Common/Core/vtkTypedDataArrayIterator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkTypedDataArrayIterator.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00032 #ifndef __vtkTypedDataArrayIterator_h
00033 #define __vtkTypedDataArrayIterator_h
00034 
00035 #include <iterator> // For iterator traits
00036 
00037 #include "vtkTypedDataArray.h" // For vtkTypedDataArray
00038 
00039 template<class Scalar>
00040 class vtkTypedDataArrayIterator
00041 {
00042 public:
00043   typedef std::random_access_iterator_tag iterator_category;
00044   typedef Scalar value_type;
00045   typedef std::ptrdiff_t difference_type;
00046   typedef Scalar& reference;
00047   typedef Scalar* pointer;
00048 
00049   vtkTypedDataArrayIterator()
00050     : Data(NULL), Index(0) {}
00051 
00052   explicit vtkTypedDataArrayIterator(vtkTypedDataArray<Scalar> *arr,
00053                                      const vtkIdType index = 0)
00054     : Data(arr),
00055       Index(index)
00056   {
00057   }
00058 
00059   vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
00060     : Data(o.Data),
00061       Index(o.Index)
00062   {
00063   }
00064 
00065   vtkTypedDataArrayIterator&
00066   operator=(vtkTypedDataArrayIterator<Scalar> o)
00067   {
00068     std::swap(this->Data, o.Data);
00069     std::swap(this->Index, o.Index);
00070     return *this;
00071   }
00072 
00073   bool operator==(const vtkTypedDataArrayIterator<Scalar> &o) const
00074   {
00075     return this->Data == o.Data && this->Index == o.Index;
00076   }
00077 
00078   bool operator!=(const vtkTypedDataArrayIterator<Scalar> &o) const
00079   {
00080     return this->Data == o.Data && this->Index != o.Index;
00081   }
00082 
00083   bool operator>(const vtkTypedDataArrayIterator<Scalar> &o) const
00084   {
00085     return this->Data == o.Data && this->Index > o.Index;
00086   }
00087 
00088   bool operator>=(const vtkTypedDataArrayIterator<Scalar> &o) const
00089   {
00090     return this->Data == o.Data && this->Index >= o.Index;
00091   }
00092 
00093   bool operator<(const vtkTypedDataArrayIterator<Scalar> &o) const
00094   {
00095     return this->Data == o.Data && this->Index < o.Index;
00096   }
00097 
00098   bool operator<=(const vtkTypedDataArrayIterator<Scalar> &o) const
00099   {
00100     return this->Data == o.Data && this->Index <= o.Index;
00101   }
00102 
00103   Scalar& operator*()
00104   {
00105     return this->Data->GetValueReference(this->Index);
00106   }
00107 
00108   Scalar* operator->() const
00109   {
00110     return &this->Data->GetValueReference(this->Index);
00111   }
00112 
00113   Scalar& operator[](const difference_type &n)
00114   {
00115     return this->Data->GetValueReference(this->Index + n);
00116   }
00117 
00118   vtkTypedDataArrayIterator& operator++()
00119   {
00120     ++this->Index;
00121     return *this;
00122   }
00123 
00124   vtkTypedDataArrayIterator& operator--()
00125   {
00126     --this->Index;
00127     return *this;
00128   }
00129 
00130   vtkTypedDataArrayIterator operator++(int)
00131   {
00132     return vtkTypedDataArrayIterator(this->Data, this->Index++);
00133   }
00134 
00135   vtkTypedDataArrayIterator operator--(int)
00136   {
00137     return vtkTypedDataArrayIterator(this->Data, this->Index--);
00138   }
00139 
00140   vtkTypedDataArrayIterator operator+(const difference_type& n) const
00141   {
00142     return vtkTypedDataArrayIterator(this->Data, this->Index + n);
00143   }
00144 
00145   vtkTypedDataArrayIterator operator-(const difference_type& n) const
00146   {
00147     return vtkTypedDataArrayIterator(this->Data, this->Index - n);
00148   }
00149 
00150   difference_type operator-(const vtkTypedDataArrayIterator& other) const
00151   {
00152     return this->Index - other.Index;
00153   }
00154 
00155   vtkTypedDataArrayIterator& operator+=(const difference_type& n)
00156   {
00157     this->Index += n;
00158     return *this;
00159   }
00160 
00161   vtkTypedDataArrayIterator& operator-=(const difference_type& n)
00162   {
00163     this->Index -= n;
00164     return *this;
00165   }
00166 
00167 private:
00168   vtkTypedDataArray<Scalar> *Data;
00169   vtkIdType Index;
00170 };
00171 
00172 #endif // __vtkTypedDataArrayIterator_h
00173 
00174 // VTK-HeaderTest-Exclude: vtkTypedDataArrayIterator.h