Aleph-w  1.9
General library for algorithms and data structures
tpl_stl_itor.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 # ifndef TPL_STD_ITRO_H
28 # define TPL_STD_ITRO_H
29 
30 namespace Aleph {
31 
32 
38  template <class Tree_Type>
40 {
41 private:
42 
43  friend class Set_Type;
44 
45  typedef typename Tree_Type::Iterator Iterator;
46 
47  Iterator itor;
48  bool underflow;
49  bool overflow;
50 
51  void init_flags ()
52  {
53  if (itor.has_current () )
54  underflow = overflow = false;
55  else
56  underflow = overflow = true;
57  }
58 
59  void goto_begin ()
60  {
61  itor.reset_first ();
62  init_flags ();
63  }
64 
65  void goto_last ()
66  {
67  itor.reset_last ();
68  init_flags ();
69  }
70 
71  void goto_end ()
72  {
73  itor.reset_last ();
74  init_flags ();
75  overflow = true;
76  if (not size() != 0)
77  itor.next ();
78  }
79 
80  void forward ()
81  {
82  if (underflow)
83  {
84  goto_begin ();
85  return;
86  }
87 
88  itor.next ();
89 
90  if (not itor.has_current () )
91  overflow = true;
92  }
93 
94  void backward ()
95  {
96  if (overflow)
97  {
98  goto_last ();
99  return;
100  }
101 
102  itor.prev ();
103 
104  if (not itor.has_current () )
105  underflow = true;
106  }
107 
108  iterator (Tree_Type & _tree, Node * node)
109  : itor (_tree, node), underflow (false), overflow (false)
110  {
111  /* empty */
112  }
113 
114 public:
115 
116  typedef typename map::value_type value_type;
117  typedef typename map::size_type difference_type;
118  typedef typename map::value_type * pointer;
119  typedef typename map::reference reference;
120 
122  iterator () { /* empty */ }
123 
124  iterator (Tree_Type & tree) : itor (tree)
125  {
126  init_flags ();
127  }
128 
130  Pair & operator * ()
131  {
132  return KEY (itor.get_current () );
133  }
134 
136  Pair * operator -> ()
137  {
138  return &KEY (itor.get_current () );
139  }
140 
143  Pair & operator ++ ()
144  {
145  forward ();
146 
147  return KEY (itor.get_current () );
148  }
149 
150  Pair & operator ++ (int)
151  {
152  Pair & retPair = KEY (itor.get_current () );
153  forward ();
154 
155  return retPair;
156  }
157 
158  Pair & operator -- ()
159  {
160  backward ();
161 
162  return KEY (itor.get_current () );
163  }
164 
165  Pair & operator -- (int)
166  {
167  Pair & retPair = KEY (itor.get_current () );
168  backward ();
169 
170  return retPair;
171  }
172 
173  Pair & operator += (const size_type & n)
174  {
175  itor.reset_to_pos (itor.get_current_position () + n);
176 
177  return KEY (itor.get_current () );
178  }
179 
180  Pair & operator -= (const size_type & n)
181  {
182  itor.reset_to_pos (itor.get_current_position () - n);
183 
184  return KEY (itor.get_current () );
185  }
186 
187  bool operator == (const iterator & _itor) const
188  {
189  return itor == _itor.itor;
190  }
191 
192  bool operator != (const iterator & _itor) const
193  {
194  return not (itor == _itor.itor);
195  }
196 
197  bool verify (const map & _map) const
198  {
199  return itor.verify ( (Tree_Type*) &_map.tree);
200  }
201 
202  bool verify (const iterator & it) const
203  {
204  return itor.verify (it.itor);
205  }
206 };
207 
208 
209 
210 } // end namespace Aleph
211 
212 # endif // TPL_STD_ITRO_H
Pair * operator->()
"Dereferencia" un puntero al elemento actual.
Definition: tpl_stl_itor.H:136
Definition: tpl_stl_itor.H:39
Node::Key_Type & KEY(Node *p) noexcept
Definition: tpl_binNode.H:318
Pair & operator++()
Definition: tpl_stl_itor.H:143
Pair & operator*()
Proporciona una referencia al elemento actual.
Definition: tpl_stl_itor.H:130
Definition: ah-comb.H:35
map::value_type & reference
Definition: Map.H:104
Pair value_type
Tipo a exportar como tipo del contenedor.
Definition: Map.H:100
iterator()
Constructor vacío; no tiene validez si no se asocia un conjunto.
Definition: tpl_stl_itor.H:122
Definition: Map.H:82

Leandro Rabindranath León