1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #ifndef CHECKERBOARDGRAPHITERATOR_H
23 #define CHECKERBOARDGRAPHITERATOR_H
29 template <typename TGraph
>
30 class CheckerBoardGraphIterator
33 typedef typename
TGraph::index_type index_t
;
36 index_t m_CurrentIndex
;
38 vector
<bool> m_Available
;
40 bool m_UpdateRequired
;
44 CheckerBoardGraphIterator() { m_Graph
= NULL
; }
45 CheckerBoardGraphIterator(TGraph
* graph
) { m_Graph
= graph
; }
46 void setGraph(TGraph
* graph
) { m_Graph
= graph
; }
47 bool updateRequired();
48 void operator=(index_t i
);
49 bool operator==(index_t i
) { return m_CurrentIndex
== i
; }
50 bool operator<(index_t i
) { return m_CurrentIndex
< i
; }
52 index_t
operator*() { return m_CurrentIndex
; }
56 template <typename TGraph
>
57 void CheckerBoardGraphIterator
<TGraph
>::operator=(index_t i
)
60 m_Available
.resize(m_Graph
->size(), true);
61 m_Done
.resize(m_Graph
->size(), false);
63 m_UpdateRequired
= false;
66 template <typename TGraph
>
67 bool CheckerBoardGraphIterator
<TGraph
>::updateRequired()
69 bool update_required
= m_UpdateRequired
;
70 m_UpdateRequired
= false;
71 return update_required
;
74 template <typename TGraph
>
75 typename CheckerBoardGraphIterator
<TGraph
>::index_t CheckerBoardGraphIterator
<TGraph
>::operator++()
77 if (m_Graph
->size() > 0) {
78 m_Done
[m_CurrentIndex
] = true;
80 for (int i
= 0; i
< m_Graph
->getNumLinks(m_CurrentIndex
); ++i
) {
81 m_Available
[m_Graph
->getLink(m_CurrentIndex
,i
)] = false;
85 if (m_CurrentIndex
>= m_Graph
->size()) {
86 if (m_DoneCount
== m_Graph
->size()) {
89 for (size_t i
= 0; i
< m_Available
.size(); ++i
) {
90 m_Available
[i
] = !m_Done
[i
];
93 m_UpdateRequired
= true;
95 } while (!m_Available
[m_CurrentIndex
]);
97 return m_CurrentIndex
;
102 #endif // CHECKERBOARDGRAPHITERATOR_H