Subversion Repositories gelsvn

Rev

Rev 595 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
512 s042372 1
/* ----------------------------------------------------------------------- *
572 jab 2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
578 jab 4
 * For license and list of authors, see ../../doc/intro.pdf
512 s042372 5
 * ----------------------------------------------------------------------- */
511 s042372 6
 
578 jab 7
/**
8
 * @file Iterators.h
9
 * @brief Contains class for iterating over mesh entities in a HMesh.
10
 */
511 s042372 11
#ifndef __HMESH_ITERATORS_H__
12
#define __HMESH_ITERATORS_H__
13
 
588 jab 14
#include "ItemVector.h"
511 s042372 15
 
16
namespace HMesh
17
{
578 jab 18
    /** Traverse the entities of an HMesh in the order they are stored in the
19
      data structure. */
588 jab 20
    template<typename ITEM>
518 s042372 21
    class IDIterator
512 s042372 22
    {
23
    public:
588 jab 24
        typedef ItemID<ITEM> ID;
25
 
520 s042372 26
        // typedefs to accommodiate stl compliance
515 s042372 27
        typedef std::bidirectional_iterator_tag iterator_category;
28
        typedef ptrdiff_t difference_type;
520 s042372 29
        typedef ID value_type;
518 s042372 30
        typedef value_type reference;
515 s042372 31
        typedef value_type* pointer;
520 s042372 32
 
512 s042372 33
        /// constructor (default: skipping enabled)
588 jab 34
        IDIterator(const ItemVector<ITEM>& _item_vector, ID _id, bool _skip = true);
511 s042372 35
 
512 s042372 36
        /// prefix increment 
518 s042372 37
        IDIterator& operator ++();		
512 s042372 38
        /// postfix increment
518 s042372 39
        IDIterator& operator ++(int);
512 s042372 40
        /// prefix decrement
518 s042372 41
        IDIterator& operator --();
512 s042372 42
        /// postfix decrement
518 s042372 43
        IDIterator& operator --(int);
511 s042372 44
 
512 s042372 45
        /// equal to
518 s042372 46
        bool operator ==(const IDIterator& other) const;
512 s042372 47
        /// not equal to
518 s042372 48
        bool operator !=(const IDIterator& other) const;
511 s042372 49
 
512 s042372 50
        /// indirection
518 s042372 51
        reference operator *();
512 s042372 52
        /// member by pointer
518 s042372 53
        pointer operator ->();
512 s042372 54
        /// cast
55
        //operator VertexID() const;
511 s042372 56
 
512 s042372 57
    private:
588 jab 58
        const ItemVector<ITEM>* item_vector;
518 s042372 59
        ID id;
512 s042372 60
        bool skip;
61
    };
511 s042372 62
 
515 s042372 63
 
518 s042372 64
    /*-----------------------------------------
65
     * IDIterator template implementation
66
     *-----------------------------------------*/
511 s042372 67
 
588 jab 68
    template<typename ITEM>
69
    inline IDIterator<ITEM>::IDIterator(const ItemVector<ITEM>& _item_vector, ID _id, bool _skip) 
70
        : item_vector(&_item_vector), id(_id), skip(_skip){}
511 s042372 71
 
588 jab 72
    template<typename ITEM>
73
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator ++(int)
518 s042372 74
    { return ++(*this); }
511 s042372 75
 
588 jab 76
    template<typename ITEM>
77
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator --(int)
518 s042372 78
    { return --(*this); }
511 s042372 79
 
588 jab 80
    template<typename ITEM>
81
    inline bool IDIterator<ITEM>::operator ==(const IDIterator<ITEM>& other) const
82
    { return item_vector == other.item_vector && id == other.id; }
511 s042372 83
 
588 jab 84
    template<typename ITEM>
85
    inline bool IDIterator<ITEM>::operator !=(const IDIterator<ITEM>& other) const
86
    { return item_vector != other.item_vector || id != other.id; }
511 s042372 87
 
588 jab 88
    template<typename ITEM>
89
    inline ItemID<ITEM> IDIterator<ITEM>::operator *()
518 s042372 90
    { return id; }
511 s042372 91
 
588 jab 92
    template<typename ITEM>
93
    inline ItemID<ITEM>* IDIterator<ITEM>::operator ->()
518 s042372 94
    { return &id; }
515 s042372 95
 
588 jab 96
    template<typename ITEM>
97
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator ++()
512 s042372 98
    {
588 jab 99
        id = item_vector->index_next(id, skip);
512 s042372 100
        return *this;
101
    }
511 s042372 102
 
588 jab 103
    template<typename ITEM>
104
    inline IDIterator<ITEM>& IDIterator<ITEM>::operator --()
512 s042372 105
    {
588 jab 106
        id = item_vector->index_prev(id, skip);
512 s042372 107
        return *this;
108
    }
511 s042372 109
}
110
 
111
#endif