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
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 
23 #ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
24 #define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
25 
26 #include <boost/iterator/iterator_facade.hpp>
27 
28 namespace Gudhi {
29 
30 namespace skeleton_blocker {
31 
35 // ReturnType = const Simplex* or Simplex*
36 // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator
37 
38 template<typename MapIteratorType, typename ReturnType>
39 class Blocker_iterator_internal : public boost::iterator_facade<
40 Blocker_iterator_internal<MapIteratorType, ReturnType>,
41 ReturnType,
42 boost::forward_traversal_tag,
43 ReturnType
44 > {
45  private:
46  MapIteratorType current_position;
47  MapIteratorType end_of_map;
48 
49  public:
50  Blocker_iterator_internal() : current_position() { }
51 
52  Blocker_iterator_internal(MapIteratorType position, MapIteratorType end_of_map_) :
53  current_position(position), end_of_map(end_of_map_) { }
54 
55  bool equal(const Blocker_iterator_internal& other) const {
56  return current_position == other.current_position;
57  }
58 
59  void increment() {
60  goto_next_blocker();
61  }
62 
63  ReturnType dereference() const {
64  return (current_position->second);
65  }
66 
67  private:
73  void goto_next_blocker() {
74  do {
75  ++current_position;
76  } while (!(current_position == end_of_map) && !first_time_blocker_is_seen());
77  }
78 
79  bool first_time_blocker_is_seen() const {
80  return current_position->first == current_position->second->first_vertex();
81  }
82 };
83 
87 // ReturnType = const Simplex* or Simplex*
88 // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator
89 
90 template<typename MapIteratorType, typename ReturnType>
91 class Blocker_iterator_around_vertex_internal : public boost::iterator_facade<
92 Blocker_iterator_around_vertex_internal<MapIteratorType, ReturnType>,
93 ReturnType,
94 boost::forward_traversal_tag,
95 ReturnType
96 > {
97  private:
98  MapIteratorType current_position_;
99 
100  public:
101  Blocker_iterator_around_vertex_internal() : current_position_() { }
102 
103  Blocker_iterator_around_vertex_internal(MapIteratorType position) :
104  current_position_(position) { }
105 
107  this->current_position_ = other.current_position_;
108  return *this;
109  }
110 
111  bool equal(const Blocker_iterator_around_vertex_internal& other) const {
112  return current_position_ == other.current_position_;
113  }
114 
115  void increment() {
116  current_position_++;
117  }
118 
119  ReturnType dereference() const {
120  return (current_position_->second);
121  }
122 
123  MapIteratorType current_position() {
124  return this->current_position_;
125  }
126 };
127 
128 } // namespace skeleton_blocker
129 
130 namespace skbl = skeleton_blocker;
131 
132 } // namespace Gudhi
133 
134 #endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:91
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:39
Definition: SimplicialComplexForAlpha.h:26
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 15:00:54 for GUDHI by Doxygen 1.8.13