]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/node_iterators.hpp
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / bin_search_tree_ / node_iterators.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
aa118a03 3// Copyright (C) 2005-2014 Free Software Foundation, Inc.
4569a895
AT
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
748086b7 8// Foundation; either version 3, or (at your option) any later
4569a895
AT
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
748086b7
JJ
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.
4569a895 19
748086b7
JJ
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/>.
4569a895
AT
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
36/**
a345e45d 37 * @file bin_search_tree_/node_iterators.hpp
4569a895
AT
38 * Contains an implementation class for bin_search_tree_.
39 */
40
41#ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
42#define PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
43
44#include <ext/pb_ds/tag_and_trait.hpp>
45
5e11f978 46namespace __gnu_pbds
4569a895
AT
47{
48 namespace detail
49 {
30a96b3b
BK
50#define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC \
51 bin_search_tree_const_node_it_<Node, Const_Iterator, Iterator, _Alloc>
4569a895 52
a345e45d 53 /// Const node iterator.
4569a895
AT
54 template<typename Node,
55 class Const_Iterator,
56 class Iterator,
a345e45d 57 typename _Alloc>
4569a895
AT
58 class bin_search_tree_const_node_it_
59 {
4569a895
AT
60 private:
61 typedef
a345e45d 62 typename _Alloc::template rebind<
4569a895
AT
63 Node>::other::pointer
64 node_pointer;
65
66 public:
30a96b3b 67 /// Category.
4569a895
AT
68 typedef trivial_iterator_tag iterator_category;
69
30a96b3b 70 /// Difference type.
4569a895
AT
71 typedef trivial_iterator_difference_type difference_type;
72
30a96b3b 73 /// Iterator's value type.
4569a895
AT
74 typedef Const_Iterator value_type;
75
30a96b3b 76 /// Iterator's reference type.
4569a895
AT
77 typedef Const_Iterator reference;
78
30a96b3b 79 /// Iterator's __const reference type.
4569a895
AT
80 typedef Const_Iterator const_reference;
81
30a96b3b 82 /// Metadata type.
4569a895
AT
83 typedef typename Node::metadata_type metadata_type;
84
30a96b3b 85 /// Const metadata reference type.
4569a895 86 typedef
30a96b3b 87 typename _Alloc::template rebind<metadata_type>::other::const_reference
a345e45d 88 metadata_const_reference;
4569a895 89
4569a895 90
30a96b3b 91 bin_search_tree_const_node_it_(const node_pointer p_nd = 0)
a345e45d 92 : m_p_nd(const_cast<node_pointer>(p_nd))
4569a895
AT
93 { }
94
30a96b3b
BK
95 /// Access.
96 const_reference
4569a895 97 operator*() const
30a96b3b 98 { return Const_Iterator(m_p_nd); }
4569a895 99
30a96b3b
BK
100 /// Metadata access.
101 metadata_const_reference
4569a895 102 get_metadata() const
30a96b3b 103 { return m_p_nd->get_metadata(); }
4569a895 104
30a96b3b
BK
105 /// Returns the __const node iterator associated with the left node.
106 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 107 get_l_child() const
30a96b3b 108 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_left); }
4569a895 109
30a96b3b
BK
110 /// Returns the __const node iterator associated with the right node.
111 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 112 get_r_child() const
30a96b3b 113 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_right); }
4569a895 114
30a96b3b
BK
115 /// Compares to a different iterator object.
116 bool
4569a895 117 operator==(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
30a96b3b 118 { return m_p_nd == other.m_p_nd; }
4569a895 119
30a96b3b
BK
120 /// Compares (negatively) to a different iterator object.
121 bool
4569a895 122 operator!=(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
30a96b3b 123 { return m_p_nd != other.m_p_nd; }
4569a895 124
4569a895
AT
125 node_pointer m_p_nd;
126 };
127
30a96b3b
BK
128#define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC \
129 bin_search_tree_node_it_<Node, Const_Iterator, Iterator, _Alloc>
4569a895 130
a345e45d 131 /// Node iterator.
4569a895
AT
132 template<typename Node,
133 class Const_Iterator,
134 class Iterator,
a345e45d 135 typename _Alloc>
30a96b3b 136 class bin_search_tree_node_it_
a345e45d 137 : public PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895 138 {
4569a895
AT
139 private:
140 typedef
a345e45d 141 typename _Alloc::template rebind<
4569a895
AT
142 Node>::other::pointer
143 node_pointer;
144
145 public:
30a96b3b 146 /// Iterator's value type.
4569a895
AT
147 typedef Iterator value_type;
148
30a96b3b 149 /// Iterator's reference type.
4569a895
AT
150 typedef Iterator reference;
151
30a96b3b 152 /// Iterator's __const reference type.
4569a895
AT
153 typedef Iterator const_reference;
154
4569a895 155 inline
30a96b3b 156 bin_search_tree_node_it_(const node_pointer p_nd = 0)
a345e45d 157 : PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(const_cast<node_pointer>(p_nd))
4569a895
AT
158 { }
159
30a96b3b
BK
160 /// Access.
161 Iterator
4569a895 162 operator*() const
30a96b3b 163 { return Iterator(PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd); }
4569a895 164
30a96b3b
BK
165 /// Returns the node iterator associated with the left node.
166 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
167 get_l_child() const
168 {
30a96b3b
BK
169 return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC(
170 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_left);
4569a895
AT
171 }
172
30a96b3b
BK
173 /// Returns the node iterator associated with the right node.
174 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
175 get_r_child() const
176 {
30a96b3b
BK
177 return PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC(
178 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd->m_p_right);
4569a895
AT
179 }
180
181 };
182
183#undef PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
4569a895
AT
184#undef PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
185
186 } // namespace detail
5e11f978 187} // namespace __gnu_pbds
4569a895
AT
188
189#endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP