Subversion Repositories gelsvn

Rev

Rev 588 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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

Generated by GNU Enscript 1.6.6.
113

Generated by GNU Enscript 1.6.6.
114
 
114
 
115
 
115
 
116
 
116