Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

iterators_template.hh

00001 //== CLASS DEFINITION =========================================================
00002 
00003               
00008 template <class Mesh>
00009 class IteratorT
00010 {
00011 public:
00012   
00013 
00014   //--- Typedefs ---
00015 
00016   typedef TargetType           value_type;
00017   typedef TargetHandle         value_handle;
00018 
00019 #if IsConst
00020   typedef const value_type&    reference;
00021   typedef const value_type*    pointer;
00022   typedef const Mesh*          mesh_ptr;
00023   typedef const Mesh&          mesh_ref;
00024 #else
00025   typedef value_type&          reference;
00026   typedef value_type*          pointer;
00027   typedef Mesh*                mesh_ptr;
00028   typedef Mesh&                mesh_ref;
00029 #endif
00030 
00031 
00032 
00033 
00035   IteratorT() 
00036     : mesh_(0), skip_bits_(0) 
00037   {}
00038 
00039 
00041   IteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false) 
00042     : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0) 
00043   {
00044     if (_skip) enable_skipping();
00045   }
00046 
00047 
00049   IteratorT(const IteratorT& _rhs) 
00050     : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_)
00051   {}
00052   
00053 
00055   IteratorT& operator=(const IteratorT<Mesh>& _rhs) 
00056   {
00057     mesh_      = _rhs.mesh_;
00058     hnd_       = _rhs.hnd_;
00059     skip_bits_ = _rhs.skip_bits_;
00060     return *this;
00061   }
00062 
00063 
00064 #if IsConst
00065 
00067   IteratorT(const NonConstIterT<Mesh>& _rhs) 
00068     : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) 
00069   {}
00070   
00071 
00073   IteratorT& operator=(const NonConstIterT<Mesh>& _rhs) 
00074   {
00075     mesh_      = _rhs.mesh_;
00076     hnd_       = _rhs.hnd_;
00077     skip_bits_ = _rhs.skip_bits_;
00078     return *this;
00079   }
00080 
00081 #else
00082   friend class ConstIterT<Mesh>;
00083 #endif
00084 
00085 
00087   reference operator*()  const { return mesh_->deref(hnd_); }
00088   
00090   pointer   operator->() const { return &(mesh_->deref(hnd_)); }
00091   
00093   value_handle handle() const { return hnd_; }
00094 
00096   operator value_handle() const { return hnd_; }
00097 
00099   bool operator==(const IteratorT& _rhs) const 
00100   { return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); }
00101 
00103   bool operator!=(const IteratorT& _rhs) const 
00104   { return !operator==(_rhs); }
00105   
00107   IteratorT& operator++() 
00108   { hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; }
00109 
00111   IteratorT& operator--() 
00112   { hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; }
00113   
00114 
00116   void enable_skipping()
00117   {
00118     if (mesh_ && mesh_->has_element_status())
00119     {
00120       Attributes::StatusInfo status;
00121       status.set_deleted(true);
00122       status.set_hidden(true);
00123       skip_bits_ = status.bits();
00124       skip_fwd();
00125     }
00126     else skip_bits_ = 0;
00127   }
00128 
00129 
00131   void disable_skipping() { skip_bits_ = 0; }
00132 
00133 
00134 
00135 private:
00136 
00137   void skip_fwd() 
00138   {
00139     assert(mesh_ && skip_bits_);
00140     while ((hnd_.idx() < (signed) mesh_->n_elements()) && 
00141            (mesh_->status(hnd_).bits() & skip_bits_))
00142       hnd_.__increment();
00143   }
00144 
00145 
00146   void skip_bwd() 
00147   {
00148     assert(mesh_ && skip_bits_);
00149     while ((hnd_.idx() >= 0) && 
00150            (mesh_->status(hnd_).bits() & skip_bits_))
00151       hnd_.__decrement();
00152   }
00153 
00154 
00155 
00156 private:
00157   mesh_ptr      mesh_;
00158   value_handle  hnd_;
00159   unsigned int  skip_bits_;
00160 };
00161 
00162 

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .