Gudhi  1.2.0
 All Classes Functions Variables Typedefs Friends Groups Pages
Skeleton_blockers_blockers_iterators.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): David Salinas
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
23 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
24 
25 #include <boost/iterator/iterator_facade.hpp>
26 
27 namespace Gudhi {
28 
29 namespace skbl {
30 
34 // ReturnType = const Simplex_handle* or Simplex_handle*
35 // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator
36 
37 template<typename MapIteratorType, typename ReturnType>
38 class Blocker_iterator_internal : public boost::iterator_facade<
39 Blocker_iterator_internal<MapIteratorType, ReturnType>,
40 ReturnType,
41 boost::forward_traversal_tag,
42 ReturnType
43 > {
44  private:
45  MapIteratorType current_position;
46  MapIteratorType end_of_map;
47 
48  public:
49  Blocker_iterator_internal() : current_position() { }
50 
51  Blocker_iterator_internal(MapIteratorType position, MapIteratorType end_of_map_) :
52  current_position(position), end_of_map(end_of_map_) { }
53 
54  bool equal(const Blocker_iterator_internal& other) const {
55  return current_position == other.current_position;
56  }
57 
58  void increment() {
59  goto_next_blocker();
60  }
61 
62  ReturnType dereference() const {
63  return (current_position->second);
64  }
65 
66  private:
72  void goto_next_blocker() {
73  do {
74  ++current_position;
75  } while (!(current_position == end_of_map) && !first_time_blocker_is_seen());
76  }
77 
78  bool first_time_blocker_is_seen() const {
79  return current_position->first == current_position->second->first_vertex();
80  }
81 };
82 
86 // ReturnType = const Simplex_handle* or Simplex_handle*
87 // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator
88 
89 template<typename MapIteratorType, typename ReturnType>
90 class Blocker_iterator_around_vertex_internal : public boost::iterator_facade<
91 Blocker_iterator_around_vertex_internal<MapIteratorType, ReturnType>,
92 ReturnType,
93 boost::forward_traversal_tag,
94 ReturnType
95 > {
96  private:
97  MapIteratorType current_position_;
98 
99  public:
100  Blocker_iterator_around_vertex_internal() : current_position_() { }
101 
102  Blocker_iterator_around_vertex_internal(MapIteratorType position) :
103  current_position_(position) { }
104 
106  this->current_position_ = other.current_position_;
107  return *this;
108  }
109 
110  bool equal(const Blocker_iterator_around_vertex_internal& other) const {
111  return current_position_ == other.current_position_;
112  }
113 
114  void increment() {
115  current_position_++;
116  }
117 
118  ReturnType dereference() const {
119  return (current_position_->second);
120  }
121 
122  MapIteratorType current_position() {
123  return this->current_position_;
124  }
125 };
126 
127 } // namespace skbl
128 
129 } // namespace Gudhi
130 
131 #endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:38
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:90