vtf-logo

SimplexIterator.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__geom_mesh_iss_SimplexIterator_h__)
00009 #define __geom_mesh_iss_SimplexIterator_h__
00010 
00011 // If we are debugging the whole geom package.
00012 #if defined(DEBUG_geom) && !defined(DEBUG_SimplexIterator)
00013 #define DEBUG_SimplexIterator
00014 #endif
00015 
00016 #include <iterator>
00017 
00018 BEGIN_NAMESPACE_GEOM
00019 
00020 
00021 // CONTINUE: Make this a nested class.  It is only used through the 
00022 // IndSimpSet::simplex_const_iterator type.
00023 
00025 
00030 template<class ISS>
00031 class SimplexIterator :
00032   public std::iterator<std::random_access_iterator_tag,
00033                        typename ISS::Simplex,
00034                        std::ptrdiff_t,
00035                        const typename ISS::Simplex*,
00036                        const typename ISS::Simplex&> {
00037   //
00038   // Private types.
00039   //
00040 
00041 private:
00042   
00043   typedef std::iterator<std::random_access_iterator_tag,
00044                         typename ISS::Simplex,
00045                         std::ptrdiff_t,
00046                         const typename ISS::Simplex*,
00047                         const typename ISS::Simplex&> Base;
00048 
00049   //
00050   // Public types.
00051   //
00052 
00053 public:
00054 
00056   typedef typename Base::iterator_category iterator_category;
00058   typedef typename Base::value_type value_type;
00060   typedef typename Base::difference_type difference_type;
00062   typedef typename Base::pointer pointer;
00064   typedef typename Base::reference reference;
00065 
00067   typedef ISS IssType;
00068 
00069   //
00070   // Member data.
00071   //
00072 
00073 private:
00074 
00075   int _index;
00076   mutable value_type _simplex;
00077   const IssType& _iss;
00078 
00079   //
00080   // Not implemented.
00081   //
00082 
00083 private:
00084 
00085   // Default constructor not implemented.
00086   SimplexIterator();
00087 
00088 public:
00089 
00090   //--------------------------------------------------------------------------
00092 
00093 
00095 
00098   SimplexIterator(const IssType& iss) :
00099     Base(),
00100     _index(0),
00101     _simplex(),
00102     _iss(iss)
00103   {}
00104 
00106   SimplexIterator(const SimplexIterator& other) :
00107     Base(),
00108     _index(other._index),
00109     _simplex(),
00110     _iss(other._iss)
00111   {}    
00112 
00114   SimplexIterator&
00115   operator=(const SimplexIterator& other)
00116   {
00117     if (&other != this) {
00118       _index = other._index;
00119     }
00120     return *this;
00121   }
00122 
00124   ~SimplexIterator()
00125   {}
00126 
00128   //--------------------------------------------------------------------------
00130 
00131 
00133   reference
00134   operator*() const {
00135     // Update the simplex.
00136     update(_index);
00137     // Then return a constant reference to it.
00138     return _simplex;
00139   }
00140 
00142   pointer
00143   operator->() const {
00144     // Update the simplex.
00145     update(_index);
00146     // Then return a constant reference to it.
00147     return &_simplex;
00148   }
00149 
00151   SimplexIterator&
00152   operator++() { 
00153     ++_index; 
00154     return *this; 
00155   }
00156       
00158 
00162   SimplexIterator
00163   operator++(int) {
00164     SimplexIterator x(*this); 
00165     ++*this;
00166     return x;
00167   }
00168 
00170   //--------------------------------------------------------------------------
00172 
00173 
00175   SimplexIterator&
00176   operator--() { 
00177     --_index; 
00178     return *this; 
00179   }
00180       
00182 
00186   SimplexIterator
00187   operator--(int) {
00188     SimplexIterator x(*this); 
00189     --*this;
00190     return x;
00191   }
00192       
00194   //--------------------------------------------------------------------------
00196 
00197 
00199   reference
00200   operator[](const difference_type n) const { 
00201     // Update the simplex with the requested offset value.
00202     update(_index + n);
00203     // Then return a constant reference to it.
00204     return _simplex;
00205   }
00206   
00208   SimplexIterator&
00209   operator+=(const difference_type n) { 
00210     _index += n; 
00211     return *this; 
00212   }
00213 
00215 
00218   SimplexIterator
00219   operator+(const difference_type n) const { 
00220     SimplexIterator x(*this); 
00221     x += n;
00222     return x;
00223   }
00224       
00226   SimplexIterator&
00227   operator-=(const difference_type n) { 
00228     _index -= n; 
00229     return *this; 
00230   }
00231 
00233 
00236   SimplexIterator
00237   operator-(const difference_type n) const { 
00238     SimplexIterator x(*this); 
00239     x -= n;
00240     return x;
00241   }
00242 
00244   int
00245   getBase() const {
00246     return _index;
00247   }
00248 
00250 
00251   //
00252   // Private member functions
00253   //
00254 
00255 private:
00256 
00257   // Update the simplex for the current index.
00258   void
00259   update(const int index) const {
00260     for (int m = 0; m != IssType::M + 1; ++m) {
00261       _simplex[m] = _iss.getSimplexVertex(index, m);
00262     }
00263   }
00264 };
00265 
00266 
00267 //
00268 // Forward iterator requirements
00269 //
00270 
00271 
00273 template<class ISS>
00274 inline 
00275 bool
00276 operator==(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00277   return x.getBase() == y.getBase(); 
00278 }
00279 
00280 
00282 template<class ISS>
00283 inline 
00284 bool
00285 operator!=(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00286   return !(x == y);
00287 }
00288 
00289 
00290 //
00291 // Random access iterator requirements
00292 //
00293 
00294 
00296 template<class ISS>
00297 inline 
00298 bool 
00299 operator<(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00300   return x.getBase() < y.getBase(); 
00301 }
00302 
00303 
00305 template<class ISS>
00306 inline 
00307 bool
00308 operator>(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00309   return x.getBase() > y.getBase(); 
00310 }
00311 
00312 
00314 template<class ISS>
00315 inline 
00316 bool
00317 operator<=(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00318   return x.getBase() <= y.getBase(); 
00319 }
00320 
00321 
00323 template<class ISS>
00324 inline 
00325 bool
00326 operator>=(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00327   return x.getBase() >= y.getBase(); 
00328 }
00329 
00330 
00332 template<class ISS>
00333 inline 
00334 typename SimplexIterator<ISS>::difference_type
00335 operator-(const SimplexIterator<ISS>& x, const SimplexIterator<ISS>& y) { 
00336   return x.getBase() - y.getBase(); 
00337 }
00338 
00339 
00341 template<class ISS>
00342 inline 
00343 SimplexIterator<ISS>
00344 operator+(typename SimplexIterator<ISS>::difference_type n,
00345           const SimplexIterator<ISS>& i) { 
00346   SimplexIterator<ISS> x(i); 
00347   x += n;
00348   return x;
00349 }
00350 
00351 END_NAMESPACE_GEOM
00352 
00353 #endif

Generated on Fri Aug 24 12:55:58 2007 for Computational Geometry Package by  doxygen 1.4.7