Loading...
Searching...
No Matches
iterators_template.hh
//== CLASS DEFINITION =========================================================
template <class Mesh>
class IteratorT
{
public:
//--- Typedefs ---
typedef TargetType value_type;
typedef TargetHandle value_handle;
#if IsConst
typedef const value_type& reference;
typedef const value_type* pointer;
typedef const Mesh* mesh_ptr;
typedef const Mesh& mesh_ref;
#else
typedef value_type& reference;
typedef value_type* pointer;
typedef Mesh* mesh_ptr;
typedef Mesh& mesh_ref;
#endif
IteratorT()
: mesh_(0), skip_bits_(0)
{}
IteratorT(mesh_ref _mesh, value_handle _hnd, bool _skip=false)
: mesh_(&_mesh), hnd_(_hnd), skip_bits_(0)
{
if (_skip) enable_skipping();
}
IteratorT(const IteratorT& _rhs)
: mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_)
{}
IteratorT& operator=(const IteratorT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
hnd_ = _rhs.hnd_;
skip_bits_ = _rhs.skip_bits_;
return *this;
}
#if IsConst
IteratorT(const NonConstIterT<Mesh>& _rhs)
: mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_)
{}
IteratorT& operator=(const NonConstIterT<Mesh>& _rhs)
{
mesh_ = _rhs.mesh_;
hnd_ = _rhs.hnd_;
skip_bits_ = _rhs.skip_bits_;
return *this;
}
#else
friend class ConstIterT<Mesh>;
#endif
reference operator*() const { return mesh_->deref(hnd_); }
pointer operator->() const { return &(mesh_->deref(hnd_)); }
value_handle handle() const { return hnd_; }
operator value_handle() const { return hnd_; }
bool operator==(const IteratorT& _rhs) const
{ return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); }
bool operator!=(const IteratorT& _rhs) const
{ return !operator==(_rhs); }
IteratorT& operator++()
{ hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; }
IteratorT& operator--()
{ hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; }
void enable_skipping()
{
if (mesh_ && mesh_->has_element_status())
{
Attributes::StatusInfo status;
status.set_deleted(true);
status.set_hidden(true);
skip_bits_ = status.bits();
skip_fwd();
}
else skip_bits_ = 0;
}
void disable_skipping() { skip_bits_ = 0; }
private:
void skip_fwd()
{
assert(mesh_ && skip_bits_);
while ((hnd_.idx() < (signed) mesh_->n_elements()) &&
(mesh_->status(hnd_).bits() & skip_bits_))
hnd_.__increment();
}
void skip_bwd()
{
assert(mesh_ && skip_bits_);
while ((hnd_.idx() >= 0) &&
(mesh_->status(hnd_).bits() & skip_bits_))
hnd_.__decrement();
}
private:
mesh_ptr mesh_;
value_handle hnd_;
unsigned int skip_bits_;
};
IteratorT::operator!=
bool operator!=(const IteratorT &_rhs) const
Not equal?
Definition iterators_template.hh:103
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=(const IteratorT< Mesh > &_rhs)
Assignment operator.
Definition iterators_template.hh:55
IteratorT::IteratorT
IteratorT()
Default constructor.
Definition iterators_template.hh:35
IteratorT::disable_skipping
void disable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition iterators_template.hh:131
IteratorT::operator++
IteratorT & operator++()
Standard pre-increment operator.
Definition iterators_template.hh:107
IteratorT::operator--
IteratorT & operator--()
Standard pre-decrement operator.
Definition iterators_template.hh:111
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(const IteratorT &_rhs)
Copy constructor.
Definition iterators_template.hh:49
IteratorT::operator*
reference operator*() const
Standard dereferencing operator.
Definition iterators_template.hh:87
IteratorT::handle
value_handle handle() const
Get the handle of the item the iterator refers to.
Definition iterators_template.hh:93
IteratorT::enable_skipping
void enable_skipping()
Turn on skipping: automatically skip deleted/hidden elements.
Definition iterators_template.hh:116
IteratorT::operator->
pointer operator->() const
Standard pointer operator.
Definition iterators_template.hh:90