OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
iterators_template.hh
1 //== CLASS DEFINITION =========================================================
2
3
8 template <class Mesh>
9 class IteratorT
10 {
11 public:
12
13
14 //--- Typedefs ---
15
16 typedef TargetType value_type;
17 typedef TargetHandle value_handle;
18
19 #if IsConst
20 typedef const value_type& reference;
21 typedef const value_type* pointer;
22 typedef const Mesh* mesh_ptr;
23 typedef const Mesh& mesh_ref;
24 #else
25 typedef value_type& reference;
26 typedef value_type* pointer;
27 typedef Mesh* mesh_ptr;
28 typedef Mesh& mesh_ref;
29 #endif
30
31
32
33
35 IteratorT()
36 : mesh_(0), skip_bits_(0)
37 {}
38
39
41 IteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
42 : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
43 {
44 if (_skip) enable_skipping();
45 }
46
47
49 IteratorT(const IteratorT& _rhs)
50 : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_)
51 {}
52
53
55 IteratorT& operator=(const IteratorT<Mesh>& _rhs)
56 {
57 mesh_ = _rhs.mesh_;
58 hnd_ = _rhs.hnd_;
59 skip_bits_ = _rhs.skip_bits_;
60 return *this;
61 }
62
63
64 #if IsConst
65
67 IteratorT(const NonConstIterT<Mesh>& _rhs)
68 : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_)
69 {}
70
71
73 IteratorT& operator=(const NonConstIterT<Mesh>& _rhs)
74 {
75 mesh_ = _rhs.mesh_;
76 hnd_ = _rhs.hnd_;
77 skip_bits_ = _rhs.skip_bits_;
78 return *this;
79 }
80
81 #else
82 friend class ConstIterT<Mesh>;
83 #endif
84
85
87 reference operator*() const { return mesh_->deref(hnd_); }
88
90 pointer operator->() const { return &(mesh_->deref(hnd_)); }
91
93 value_handle handle() const { return hnd_; }
94
96 operator value_handle() const { return hnd_; }
97
99 bool operator==(const IteratorT& _rhs) const
100 { return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); }
101
103 bool operator!=(const IteratorT& _rhs) const
104 { return !operator==(_rhs); }
105
107 IteratorT& operator++()
108 { hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; }
109
111 IteratorT& operator--()
112 { hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; }
113
114
116 void enable_skipping()
117 {
118 if (mesh_ && mesh_->has_element_status())
119 {
120 Attributes::StatusInfo status;
121 status.set_deleted(true);
122 status.set_hidden(true);
123 skip_bits_ = status.bits();
124 skip_fwd();
125 }
126 else skip_bits_ = 0;
127 }
128
129
131 void disable_skipping() { skip_bits_ = 0; }
132
133
134
135 private:
136
137 void skip_fwd()
138 {
139 assert(mesh_ && skip_bits_);
140 while ((hnd_.idx() < (signed) mesh_->n_elements()) &&
141 (mesh_->status(hnd_).bits() & skip_bits_))
142 hnd_.__increment();
143 }
144
145
146 void skip_bwd()
147 {
148 assert(mesh_ && skip_bits_);
149 while ((hnd_.idx() >= 0) &&
150 (mesh_->status(hnd_).bits() & skip_bits_))
151 hnd_.__decrement();
152 }
153
154
155
156 private:
157 mesh_ptr mesh_;
158 value_handle hnd_;
159 unsigned int skip_bits_;
160 };
161
162
IteratorT::enable_skipping
void enable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: iterators_template.hh:116
IteratorT
Linear iterator.
Definition: iterators_template.hh:9
IteratorT::IteratorT
IteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
Construct with mesh and a target handle.
Definition: iterators_template.hh:41
IteratorT::operator++
IteratorT & operator++()
Standard pre-increment operator.
Definition: iterators_template.hh:107
IteratorT::disable_skipping
void disable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition: iterators_template.hh:131
IteratorT::handle
value_handle handle() const
Get the handle of the item the iterator refers to.
Definition: iterators_template.hh:93
IteratorT::operator=
IteratorT & operator=(const IteratorT< Mesh > &_rhs)
Assignment operator.
Definition: iterators_template.hh:55
IteratorT::operator*
reference operator*() const
Standard dereferencing operator.
Definition: iterators_template.hh:87
IteratorT::operator!=
bool operator!=(const IteratorT &_rhs) const
Not equal?
Definition: iterators_template.hh:103
OpenMesh::PolyMesh_ArrayKernelT
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:91
IteratorT::operator==
bool operator==(const IteratorT &_rhs) const
Are two iterators equal? Only valid if they refer to the same mesh!
Definition: iterators_template.hh:99
IteratorT::IteratorT
IteratorT()
Default constructor.
Definition: iterators_template.hh:35
IteratorT::operator->
pointer operator->() const
Standard pointer operator.
Definition: iterators_template.hh:90
IteratorT::IteratorT
IteratorT(const IteratorT &_rhs)
Copy constructor.
Definition: iterators_template.hh:49
IteratorT::operator--
IteratorT & operator--()
Standard pre-decrement operator.
Definition: iterators_template.hh:111