Gudhi  1.1.0
 All Classes Functions 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 GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_
23 #define GUDHI_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 template<typename MapIteratorType, typename ReturnType>
37 class Blocker_iterator_internal : public boost::iterator_facade<
38  Blocker_iterator_internal<MapIteratorType,ReturnType>,
39  ReturnType,
40  boost::forward_traversal_tag,
41  ReturnType
42  >{
43 private:
44  MapIteratorType current_position;
45  MapIteratorType end_of_map;
46 public:
47 
48  Blocker_iterator_internal():current_position(){}
49 
50  Blocker_iterator_internal(MapIteratorType position,MapIteratorType end_of_map_ ):
51  current_position(position), end_of_map(end_of_map_)
52  { }
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 
83 
84 
88 // ReturnType = const Simplex_handle* or Simplex_handle*
89 // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator
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 public:
100 
101  Blocker_iterator_around_vertex_internal():current_position_(){}
102 
103  Blocker_iterator_around_vertex_internal(MapIteratorType position):
104  current_position_(position)
105  {}
106 
108  this->current_position_ = other.current_position_;
109  return *this;
110  }
111 
112  bool equal(const Blocker_iterator_around_vertex_internal& other) const{
113  return current_position_ == other.current_position_;
114  }
115 
116  void increment(){
117  current_position_++;
118  }
119 
120  ReturnType dereference() const{
121  return(current_position_->second);
122  }
123 
124 
125  MapIteratorType current_position(){
126  return this->current_position_;
127  }
128 };
129 
130 }
131 
132 } // namespace GUDHI
133 
134 #endif /* GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ */
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:37
Iterator through the blockers of a vertex.
Definition: Skeleton_blockers_blockers_iterators.h:91