35 using parent_type =
typename Traits::parent;
36 using positions_type =
typename Traits::positions_type;
37 using sizes_type =
typename Traits::sizes_type;
38 using element_blocks_type =
typename Traits::element_blocks_type;
39 using size_type =
typename Traits::parent::size_type;
43 using positions_iterator_type =
typename Traits::positions_iterator_type;
44 using sizes_iterator_type =
typename Traits::sizes_iterator_type;
45 using element_blocks_iterator_type =
typename Traits::element_blocks_iterator_type;
51 struct grouped_iterator_type
53 positions_iterator_type position_iterator;
54 sizes_iterator_type size_iterator;
55 element_blocks_iterator_type element_block_iterator;
61 ++element_block_iterator;
68 --element_block_iterator;
71 bool operator==(
const grouped_iterator_type& other)
const
73 return position_iterator == other.position_iterator && size_iterator == other.size_iterator &&
74 element_block_iterator == other.element_block_iterator;
77 grouped_iterator_type() =
default;
79 grouped_iterator_type(
80 const positions_iterator_type& itr_pos,
const sizes_iterator_type& itr_size,
81 const element_blocks_iterator_type& itr_elem_blocks)
82 : position_iterator(itr_pos), size_iterator(itr_size), element_block_iterator(itr_elem_blocks)
90 iterator_updater() : m_cur_node(nullptr, 0, 0)
94 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
95 size_type block_index, container_id_t container_id)
96 : m_cur_node(parent, block_index, container_id), m_pos(pos), m_end(end)
103 const positions_iterator_type& positions_pos,
const sizes_iterator_type& sizes_pos,
104 const element_blocks_iterator_type& eb_pos,
const positions_iterator_type& positions_end,
105 const sizes_iterator_type& sizes_end,
const element_blocks_iterator_type& eb_end,
const parent_type* parent,
106 size_type block_index, container_id_t container_id)
108 {positions_pos, sizes_pos, eb_pos}, {positions_end, sizes_end, eb_end}, parent, block_index, container_id)
111 iterator_updater(
const iterator_updater& other)
112 : m_cur_node(other.m_cur_node), m_pos(other.m_pos), m_end(other.m_end)
117#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
119 throw general_error(
"Current node position should never equal the end position during node update.");
122 m_cur_node.position = *m_pos.position_iterator;
123 m_cur_node.size = *m_pos.size_iterator;
124 m_cur_node.data = *m_pos.element_block_iterator;
127 m_cur_node.type = mdds::mtv::get_block_type(*m_cur_node.data);
129 m_cur_node.type = mdds::mtv::element_type_empty;
149 void _print_state(std::ostream& os)
const
151 auto prev_flags = os.flags();
152 os <<
"parent=" << std::hex << m_cur_node.__private_data.parent
153 <<
"; block-index=" << m_cur_node.__private_data.block_index <<
"; position=" << m_cur_node.position
154 <<
"; size=" << m_cur_node.size <<
"; type=" << m_cur_node.type <<
"; data=" << m_cur_node.data;
155 os.flags(prev_flags);
159 bool operator==(
const iterator_updater& other)
const
161 if (m_pos != m_end && other.m_pos != other.m_end)
165 if (m_cur_node != other.m_cur_node)
168 return m_pos == other.m_pos && m_end == other.m_end;
171 iterator_updater& operator=(
const iterator_updater& other)
173 m_cur_node = other.m_cur_node;
179 void swap(iterator_updater& other)
181 m_cur_node.swap(other.m_cur_node);
182 std::swap(m_pos, other.m_pos);
183 std::swap(m_end, other.m_end);
186 const node& get_node()
const
201class iterator_base :
public iterator_updater<Traits>
203 using parent_type =
typename Traits::parent;
204 using node_update_func =
typename Traits::private_data_update;
205 using updater = iterator_updater<Traits>;
208 using size_type =
typename updater::size_type;
212 using updater::m_cur_node;
215 using updater::get_end;
216 using updater::get_pos;
219 using value_type =
typename updater::node;
220 using pointer = value_type*;
221 using reference = value_type&;
222 using difference_type = ptrdiff_t;
223 using iterator_category = std::bidirectional_iterator_tag;
229 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
230 size_type block_index, container_id_t container_id)
231 : updater(pos, end, parent, block_index, container_id)
234 value_type& operator*()
239 const value_type& operator*()
const
244 value_type* operator->()
249 const value_type* operator->()
const
254 iterator_base& operator++()
256 node_update_func::inc(m_cur_node);
261 iterator_base& operator--()
264 node_update_func::dec(m_cur_node);
268 void _print_state(std::ostream& os)
const
271 updater::_print_state(os);
277class const_iterator_base :
public iterator_updater<Traits>
279 using parent_type =
typename Traits::parent;
280 using node_update_func =
typename Traits::private_data_update;
281 using updater = iterator_updater<Traits>;
284 using size_type =
typename updater::size_type;
288 using updater::m_cur_node;
291 using updater::get_end;
292 using updater::get_pos;
294 using iterator_base = NonConstItrBase;
297 using value_type =
typename updater::node;
298 using pointer = value_type*;
299 using reference = value_type&;
300 using difference_type = ptrdiff_t;
301 using iterator_category = std::bidirectional_iterator_tag;
304 const_iterator_base() : updater()
307 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
308 size_type block_index, container_id_t container_id)
309 : updater(pos, end, parent, block_index, container_id)
317 other.get_pos().position_iterator, other.get_pos().size_iterator, other.get_pos().element_block_iterator,
318 other.get_end().position_iterator, other.get_end().size_iterator, other.get_end().element_block_iterator,
319 other.get_node().__private_data.parent, other.get_node().__private_data.block_index,
320 other.get_node().__private_data.container_id)
333 const_iterator_base& operator++()
335 node_update_func::inc(m_cur_node);
340 const_iterator_base& operator--()
343 node_update_func::dec(m_cur_node);
347 bool operator==(
const const_iterator_base& other)
const
349 return updater::operator==(other);
352 void _print_state(std::ostream& os)
const
354 os <<
"(const-iterator: ";
355 updater::_print_state(os);