41#ifndef PB_DS_OV_TREE_NODE_ITERATORS_HPP
42#define PB_DS_OV_TREE_NODE_ITERATORS_HPP
52#define PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC \
53 ov_tree_node_const_it_<Value_Type, Metadata_Type, _Alloc>
56 template<
typename Value_Type,
typename Metadata_Type,
typename _Alloc>
68 const_metadata_pointer;
70 typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
this_type;
74 template<
typename Ptr>
76 mid_pointer(Ptr p_begin, Ptr p_end)
78 _GLIBCXX_DEBUG_ASSERT(p_end >= p_begin);
79 return (p_begin + (p_end - p_begin) / 2);
92 typename remove_const<Value_Type>::type>::const_pointer
96 typename remove_const<Value_Type>::type>::const_pointer
99 typedef Metadata_Type metadata_type;
101 typedef typename rebind_traits<_Alloc, metadata_type>::const_reference
102 metadata_const_reference;
107 const_pointer p_begin_nd = 0,
108 const_pointer p_end_nd = 0,
109 const_metadata_pointer p_metadata = 0)
110 : m_p_value(
const_cast<pointer
>(p_nd)),
111 m_p_begin_value(
const_cast<pointer
>(p_begin_nd)),
112 m_p_end_value(
const_cast<pointer
>(p_end_nd)),
113 m_p_metadata(p_metadata)
116 inline const_reference
118 {
return m_p_value; }
120 inline metadata_const_reference
125 has_metadata = !is_same<Metadata_Type, null_type>::value
128 PB_DS_STATIC_ASSERT(should_have_metadata, has_metadata);
129 _GLIBCXX_DEBUG_ASSERT(m_p_metadata != 0);
130 return *m_p_metadata;
137 if (m_p_begin_value == m_p_value)
138 return (
this_type(m_p_begin_value, m_p_begin_value, m_p_begin_value));
140 const_metadata_pointer p_begin_metadata =
141 m_p_metadata - (m_p_value - m_p_begin_value);
143 return (
this_type(mid_pointer(m_p_begin_value, m_p_value),
146 mid_pointer(p_begin_metadata, m_p_metadata)));
153 if (m_p_value == m_p_end_value)
154 return (
this_type(m_p_end_value, m_p_end_value, m_p_end_value));
156 const_metadata_pointer p_end_metadata =
157 m_p_metadata + (m_p_end_value - m_p_value);
159 return (
this_type(mid_pointer(m_p_value + 1, m_p_end_value),
161 m_p_end_value,(m_p_metadata == 0) ?
162 0 : mid_pointer(m_p_metadata + 1, p_end_metadata)));
166 operator==(
const this_type& other)
const
168 const bool is_end = m_p_begin_value == m_p_end_value;
169 const bool is_other_end = other.m_p_begin_value == other.m_p_end_value;
172 return (is_other_end);
177 return m_p_value == other.m_p_value;
181 operator!=(
const this_type& other)
const
182 {
return !operator==(other); }
186 pointer m_p_begin_value;
187 pointer m_p_end_value;
189 const_metadata_pointer m_p_metadata;
192#define PB_DS_OV_TREE_NODE_ITERATOR_C_DEC \
193 ov_tree_node_it_<Value_Type, Metadata_Type, _Alloc>
196 template<
typename Value_Type,
typename Metadata_Type,
typename _Alloc>
200 typedef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC
this_type;
202 typedef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
base_type;
204 typedef typename base_type::pointer pointer;
206 typedef typename base_type::const_pointer const_pointer;
209 typename base_type::const_metadata_pointer
210 const_metadata_pointer;
221 typename remove_const<Value_Type>::type>::pointer
225 typename remove_const<Value_Type>::type>::pointer
229 ov_tree_node_it_(const_pointer p_nd = 0, const_pointer p_begin_nd = 0, const_pointer p_end_nd = 0, const_metadata_pointer p_metadata = 0) :
base_type(p_nd, p_begin_nd, p_end_nd, p_metadata)
235 {
return reference(base_type::m_p_value); }
241 if (base_type::m_p_begin_value == base_type::m_p_value)
242 return (
this_type(base_type::m_p_begin_value, base_type::m_p_begin_value, base_type::m_p_begin_value));
244 const_metadata_pointer p_begin_metadata =
245 base_type::m_p_metadata - (base_type::m_p_value - base_type::m_p_begin_value);
247 return (
this_type(base_type::mid_pointer(base_type::m_p_begin_value, base_type::m_p_value),
248 base_type::m_p_begin_value,
249 base_type::m_p_value,
250 base_type::mid_pointer(p_begin_metadata, base_type::m_p_metadata)));
257 if (base_type::m_p_value == base_type::m_p_end_value)
258 return this_type(base_type::m_p_end_value, base_type::m_p_end_value,
259 base_type::m_p_end_value);
261 const_metadata_pointer p_end_metadata =
262 base_type::m_p_metadata + (base_type::m_p_end_value - base_type::m_p_value);
264 return (
this_type(base_type::mid_pointer(base_type::m_p_value + 1, base_type::m_p_end_value),
265 base_type::m_p_value + 1,
266 base_type::m_p_end_value,(base_type::m_p_metadata == 0)?
267 0 : base_type::mid_pointer(base_type::m_p_metadata + 1, p_end_metadata)));
272#undef PB_DS_OV_TREE_NODE_ITERATOR_C_DEC
273#undef PB_DS_OV_TREE_CONST_NODE_ITERATOR_C_DEC
void trivial_iterator_difference_type
Prohibit moving trivial iterators.
GNU extensions for policy-based data structures for public use.
A trivial iterator tag. Signifies that the iterators has none of std::iterators's movement abilities.
Consistent API for accessing allocator-related types.
this_type get_l_child() const
Returns the node iterator associated with the left node.
this_type get_r_child() const
Returns the node iterator associated with the right node.
ov_tree_node_it_ get_r_child() const
Returns the node reference associated with the right node.
reference operator*() const
Access.
ov_tree_node_it_ get_l_child() const
Returns the node reference associated with the left node.