STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
node_iterators.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
10 
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26 
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
35 
41 #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
42 #define PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
43 
45 
46 namespace __gnu_pbds
47 {
48  namespace detail
49  {
50 #define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC \
51  bin_search_tree_const_node_it_<Node, Const_Iterator, Iterator, _Alloc>
52 
54  template<typename Node,
55  class Const_Iterator,
56  class Iterator,
57  typename _Alloc>
59  {
60  private:
61  typedef
62  typename _Alloc::template rebind<
63  Node>::other::pointer
65 
66  public:
69 
72 
74  typedef Const_Iterator value_type;
75 
77  typedef Const_Iterator reference;
78 
80  typedef Const_Iterator const_reference;
81 
83  typedef typename Node::metadata_type metadata_type;
84 
86  typedef
87  typename _Alloc::template rebind<metadata_type>::other::const_reference
89 
90 
92  : m_p_nd(const_cast<node_pointer>(p_nd))
93  { }
94 
97  operator*() const
98  { return Const_Iterator(m_p_nd); }
99 
102  get_metadata() const
103  { return m_p_nd->get_metadata(); }
104 
107  get_l_child() const
109 
112  get_r_child() const
113  { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_right); }
114 
116  bool
118  { return m_p_nd == other.m_p_nd; }
119 
121  bool
123  { return m_p_nd != other.m_p_nd; }
124 
126  };
127 
128 #define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC \
129  bin_search_tree_node_it_<Node, Const_Iterator, Iterator, _Alloc>
130 
132  template<typename Node,
133  class Const_Iterator,
134  class Iterator,
135  typename _Alloc>
138  {
139  private:
140  typedef
141  typename _Alloc::template rebind<
142  Node>::other::pointer
144 
145  public:
147  typedef Iterator value_type;
148 
150  typedef Iterator reference;
151 
153  typedef Iterator const_reference;
154 
155  inline
158  { }
159 
161  Iterator
162  operator*() const
163  { return Iterator(PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd); }
164 
167  get_l_child() const
168  {
170  PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_left);
171  }
172 
175  get_r_child() const
176  {
178  PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_right);
179  }
180 
181  };
182 
183 #undef PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
184 #undef PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
185 
186  } // namespace detail
187 } // namespace __gnu_pbds
188 
189 #endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
Iterator operator*() const
Access.
Definition: node_iterators.hpp:162
PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC get_l_child() const
Returns the node iterator associated with the left node.
Definition: node_iterators.hpp:167
metadata_const_reference get_metadata() const
Metadata access.
Definition: node_iterators.hpp:102
PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC get_r_child() const
Returns the __const node iterator associated with the right node.
Definition: node_iterators.hpp:112
#define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
Definition: node_iterators.hpp:128
const_reference operator*() const
Access.
Definition: node_iterators.hpp:97
void trivial_iterator_difference_type
Prohibit moving trivial iterators.
Definition: tag_and_trait.hpp:79
Const_Iterator value_type
Iterator's value type.
Definition: node_iterators.hpp:74
bin_search_tree_node_it_(const node_pointer p_nd=0)
Definition: node_iterators.hpp:156
trivial_iterator_difference_type difference_type
Difference type.
Definition: node_iterators.hpp:71
Const_Iterator const_reference
Iterator's __const reference type.
Definition: node_iterators.hpp:80
Iterator const_reference
Iterator's __const reference type.
Definition: node_iterators.hpp:153
#define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
Definition: node_iterators.hpp:50
Const_Iterator reference
Iterator's reference type.
Definition: node_iterators.hpp:77
Iterator value_type
Iterator's value type.
Definition: node_iterators.hpp:147
bool operator!=(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC &other) const
Compares (negatively) to a different iterator object.
Definition: node_iterators.hpp:122
PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC get_r_child() const
Returns the node iterator associated with the right node.
Definition: node_iterators.hpp:175
_Alloc::template rebind< Node >::other::pointer node_pointer
Definition: node_iterators.hpp:64
node_pointer m_p_nd
Definition: node_iterators.hpp:125
trivial_iterator_tag iterator_category
Category.
Definition: node_iterators.hpp:68
bool operator==(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC &other) const
Compares to a different iterator object.
Definition: node_iterators.hpp:117
bin_search_tree_const_node_it_(const node_pointer p_nd=0)
Definition: node_iterators.hpp:91
_Alloc::template rebind< metadata_type >::other::const_reference metadata_const_reference
Const metadata reference type.
Definition: node_iterators.hpp:88
Iterator reference
Iterator's reference type.
Definition: node_iterators.hpp:150
PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC get_l_child() const
Returns the __const node iterator associated with the left node.
Definition: node_iterators.hpp:107
Definition: tag_and_trait.hpp:75
Node iterator.
Definition: node_iterators.hpp:136
Const node iterator.
Definition: node_iterators.hpp:58
_Alloc::template rebind< Node >::other::pointer node_pointer
Definition: node_iterators.hpp:143
Node::metadata_type metadata_type
Metadata type.
Definition: node_iterators.hpp:83