Rev 520 | Rev 578 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/* ----------------------------------------------------------------------- *
* This file is part of GEL, http://www.imm.dtu.dk/GEL
* Copyright (C) the authors and DTU Informatics
*
* For license and list of authors, see ../doc/intro.pdf
* ----------------------------------------------------------------------- */
#ifndef __HMESH_ITERATORS_H__
#define __HMESH_ITERATORS_H__
#include "ConnectivityKernel.h"
namespace HMesh
{
template<typename ID>
class IDIterator
{
public:
// typedefs to accommodiate stl compliance
typedef std::bidirectional_iterator_tag iterator_category;
typedef ptrdiff_t difference_type;
typedef ID value_type;
typedef value_type reference;
typedef value_type* pointer;
/// constructor (default: skipping enabled)
IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip = true);
/// prefix increment
IDIterator& operator ++();
/// postfix increment
IDIterator& operator ++(int);
/// prefix decrement
IDIterator& operator --();
/// postfix decrement
IDIterator& operator --(int);
/// equal to
bool operator ==(const IDIterator& other) const;
/// not equal to
bool operator !=(const IDIterator& other) const;
/// indirection
reference operator *();
/// member by pointer
pointer operator ->();
/// cast
//operator VertexID() const;
private:
const ConnectivityKernel* ck;
ID id;
bool skip;
};
/*---------
* Typedefs
*----------*/
typedef IDIterator<VertexID> VertexIDIterator;
typedef IDIterator<FaceID> FaceIDIterator;
typedef IDIterator<HalfEdgeID> HalfEdgeIDIterator;
/*-----------------------------------------
* IDIterator template implementation
*-----------------------------------------*/
template<typename ID>
inline IDIterator<ID>::IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip)
: ck(&_ck), id(_id), skip(_skip){}
template<typename ID>
inline IDIterator<ID>& IDIterator<ID>::operator ++(int)
{ return ++(*this); }
template<typename ID>
inline IDIterator<ID>& IDIterator<ID>::operator --(int)
{ return --(*this); }
template<typename ID>
inline bool IDIterator<ID>::operator ==(const IDIterator<ID>& other) const
{ return ck == other.ck && id == other.id; }
template<typename ID>
inline bool IDIterator<ID>::operator !=(const IDIterator<ID>& other) const
{ return ck != other.ck || id != other.id; }
template<typename ID>
inline ID IDIterator<ID>::operator *()
{ return id; }
template<typename ID>
inline ID* IDIterator<ID>::operator ->()
{ return &id; }
/*-----------------------------
* Specializations for vertices
*------------------------------*/
template<>
inline IDIterator<VertexID>& IDIterator<VertexID>::operator ++()
{
id = ck->vertices_next(id, skip);
return *this;
}
template<>
inline IDIterator<VertexID>& IDIterator<VertexID>::operator --()
{
id = ck->vertices_prev(id, skip);
return *this;
}
/*-----------------------------
* Specializations for faces
*------------------------------*/
template<>
inline IDIterator<FaceID>& IDIterator<FaceID>::operator ++()
{
id = ck->faces_next(id, skip);
return *this;
}
template<>
inline IDIterator<FaceID>& IDIterator<FaceID>::operator --()
{
id = ck->faces_prev(id, skip);
return *this;
}
/*-----------------------------
* Specializations for halfedges
*------------------------------*/
template<>
inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator ++()
{
id = ck->halfedges_next(id, skip);
return *this;
}
template<>
inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator --()
{
id = ck->halfedges_prev(id, skip);
return *this;
}
}
#endif
Generated by GNU Enscript 1.6.6.