3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
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
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.
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.
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/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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
37 * @file bin_search_tree_/node_iterators.hpp
38 * Contains an implementation class for bin_search_tree_.
41 #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
42 #define PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP
44 #include <ext/pb_ds/tag_and_trait.hpp>
50 #define PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC \
51 bin_search_tree_const_node_it_<Node, Const_Iterator, Iterator, _Alloc>
53 /// Const node iterator.
54 template<typename Node,
58 class bin_search_tree_const_node_it_
62 typename _Alloc::template rebind<
68 typedef trivial_iterator_tag iterator_category;
71 typedef trivial_iterator_difference_type difference_type;
73 /// Iterator's value type.
74 typedef Const_Iterator value_type;
76 /// Iterator's reference type.
77 typedef Const_Iterator reference;
79 /// Iterator's __const reference type.
80 typedef Const_Iterator const_reference;
83 typedef typename Node::metadata_type metadata_type;
85 /// Const metadata reference type.
87 typename _Alloc::template rebind<metadata_type>::other::const_reference
88 metadata_const_reference;
91 bin_search_tree_const_node_it_(const node_pointer p_nd = 0)
92 : m_p_nd(const_cast<node_pointer>(p_nd))
98 { return Const_Iterator(m_p_nd); }
101 metadata_const_reference
103 { return m_p_nd->get_metadata(); }
105 /// Returns the __const node iterator associated with the left node.
106 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
108 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_left); }
110 /// Returns the __const node iterator associated with the right node.
111 PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
113 { return PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(m_p_nd->m_p_right); }
115 /// Compares to a different iterator object.
117 operator==(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
118 { return m_p_nd == other.m_p_nd; }
120 /// Compares (negatively) to a different iterator object.
122 operator!=(const PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC& other) const
123 { return m_p_nd != other.m_p_nd; }
128 #define PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC \
129 bin_search_tree_node_it_<Node, Const_Iterator, Iterator, _Alloc>
132 template<typename Node,
133 class Const_Iterator,
136 class bin_search_tree_node_it_
137 : public PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
141 typename _Alloc::template rebind<
142 Node>::other::pointer
146 /// Iterator's value type.
147 typedef Iterator value_type;
149 /// Iterator's reference type.
150 typedef Iterator reference;
152 /// Iterator's __const reference type.
153 typedef Iterator const_reference;
156 bin_search_tree_node_it_(const node_pointer p_nd = 0)
157 : PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC(const_cast<node_pointer>(p_nd))
163 { return Iterator(PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC::m_p_nd); }
165 /// Returns the node iterator associated with the left node.
166 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
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);
173 /// Returns the node iterator associated with the right node.
174 PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
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);
183 #undef PB_DS_TREE_CONST_NODE_ITERATOR_CLASS_C_DEC
184 #undef PB_DS_TREE_NODE_ITERATOR_CLASS_C_DEC
186 } // namespace detail
187 } // namespace __gnu_pbds
189 #endif // #ifndef PB_DS_BIN_SEARCH_TREE_NODE_ITERATORS_HPP