29#ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_DIR_SOA_ITERATOR_HPP
30#define INCLUDED_MDDS_MULTI_TYPE_VECTOR_DIR_SOA_ITERATOR_HPP
32#include "../iterator_node.hpp"
36namespace mdds {
namespace mtv {
namespace soa {
namespace detail {
54template<
typename Traits>
58 using parent_type =
typename Traits::parent;
59 using positions_type =
typename Traits::positions_type;
60 using sizes_type =
typename Traits::sizes_type;
61 using element_blocks_type =
typename Traits::element_blocks_type;
62 using size_type =
typename Traits::parent::size_type;
66 using positions_iterator_type =
typename Traits::positions_iterator_type;
67 using sizes_iterator_type =
typename Traits::sizes_iterator_type;
68 using element_blocks_iterator_type =
typename Traits::element_blocks_iterator_type;
76 positions_iterator_type position_iterator;
77 sizes_iterator_type size_iterator;
78 element_blocks_iterator_type element_block_iterator;
84 ++element_block_iterator;
91 --element_block_iterator;
96 return position_iterator == other.position_iterator && size_iterator == other.size_iterator &&
97 element_block_iterator == other.element_block_iterator;
102 return !operator==(other);
108 const positions_iterator_type& itr_pos,
const sizes_iterator_type& itr_size,
109 const element_blocks_iterator_type& itr_elem_blocks)
110 : position_iterator(itr_pos), size_iterator(itr_size), element_block_iterator(itr_elem_blocks)
122 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
123 size_type block_index)
124 : m_cur_node(parent, block_index), m_pos(pos), m_end(end)
131 const positions_iterator_type& positions_pos,
const sizes_iterator_type& sizes_pos,
132 const element_blocks_iterator_type& eb_pos,
const positions_iterator_type& positions_end,
133 const sizes_iterator_type& sizes_end,
const element_blocks_iterator_type& eb_end,
const parent_type* parent,
134 size_type block_index)
135 : iterator_updater({positions_pos, sizes_pos, eb_pos}, {positions_end, sizes_end, eb_end}, parent, block_index)
138 iterator_updater(
const iterator_updater& other)
139 : m_cur_node(other.m_cur_node), m_pos(other.m_pos), m_end(other.m_end)
144#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
146 throw general_error(
"Current node position should never equal the end position during node update.");
149 m_cur_node.position = *m_pos.position_iterator;
150 m_cur_node.size = *m_pos.size_iterator;
151 m_cur_node.data = *m_pos.element_block_iterator;
154 m_cur_node.type = mdds::mtv::get_block_type(*m_cur_node.data);
156 m_cur_node.type = mdds::mtv::element_type_empty;
176 void _print_state(std::ostream& os)
const
178 auto prev_flags = os.flags();
179 os <<
"parent=" << std::hex << m_cur_node.__private_data.parent
180 <<
"; block-index=" << m_cur_node.__private_data.block_index <<
"; position=" << m_cur_node.position
181 <<
"; size=" << m_cur_node.size <<
"; type=" << m_cur_node.type <<
"; data=" << m_cur_node.data;
182 os.flags(prev_flags);
186 bool operator==(
const iterator_updater& other)
const
188 if (m_pos != m_end && other.m_pos != other.m_end)
192 if (m_cur_node != other.m_cur_node)
195 return m_pos == other.m_pos && m_end == other.m_end;
198 bool operator!=(
const iterator_updater& other)
const
200 return !operator==(other);
203 iterator_updater& operator=(
const iterator_updater& other)
205 m_cur_node = other.m_cur_node;
211 void swap(iterator_updater& other)
213 m_cur_node.swap(other.m_cur_node);
214 std::swap(m_pos, other.m_pos);
215 std::swap(m_end, other.m_end);
218 const node& get_node()
const
222 const grouped_iterator_type& get_pos()
const
226 const grouped_iterator_type& get_end()
const
232template<
typename Traits>
235 using parent_type =
typename Traits::parent;
236 using node_update_func =
typename Traits::private_data_update;
240 using size_type =
typename updater::size_type;
244 using updater::m_cur_node;
247 using updater::get_end;
248 using updater::get_pos;
252 using pointer = value_type*;
253 using reference = value_type&;
254 using difference_type = ptrdiff_t;
255 using iterator_category = std::bidirectional_iterator_tag;
261 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
262 size_type block_index)
263 :
updater(pos, end, parent, block_index)
266 value_type& operator*()
271 const value_type& operator*()
const
276 value_type* operator->()
281 const value_type* operator->()
const
288 node_update_func::inc(m_cur_node);
296 node_update_func::dec(m_cur_node);
300 void _print_state(std::ostream& os)
const
303 updater::_print_state(os);
308template<
typename Traits,
typename NonConstItrBase>
311 using parent_type =
typename Traits::parent;
312 using node_update_func =
typename Traits::private_data_update;
316 using size_type =
typename updater::size_type;
320 using updater::m_cur_node;
323 using updater::get_end;
324 using updater::get_pos;
326 using iterator_base = NonConstItrBase;
330 using pointer = value_type*;
331 using reference = value_type&;
332 using difference_type = ptrdiff_t;
333 using iterator_category = std::bidirectional_iterator_tag;
339 const grouped_iterator_type& pos,
const grouped_iterator_type& end,
const parent_type* parent,
340 size_type block_index)
341 :
updater(pos, end, parent, block_index)
349 other.get_pos().position_iterator, other.get_pos().size_iterator, other.get_pos().element_block_iterator,
350 other.get_end().position_iterator, other.get_end().size_iterator, other.get_end().element_block_iterator,
351 other.get_node().__private_data.parent, other.get_node().__private_data.block_index)
354 const value_type& operator*()
const
359 const value_type* operator->()
const
364 const_iterator_base& operator++()
366 node_update_func::inc(m_cur_node);
371 const_iterator_base& operator--()
374 node_update_func::dec(m_cur_node);
378 bool operator==(
const const_iterator_base& other)
const
380 return updater::operator==(other);
383 bool operator!=(
const const_iterator_base& other)
const
385 return updater::operator!=(other);
388 void _print_state(std::ostream& os)
const
390 os <<
"(const-iterator: ";
391 updater::_print_state(os);
396template<
typename Traits>
397std::ostream& operator<<(std::ostream& os,
const iterator_base<Traits>& it)
403template<
typename Traits,
typename NonConstItrBase>
404std::ostream& operator<<(std::ostream& os,
const const_iterator_base<Traits, NonConstItrBase>& it)
Definition: soa/iterator.hpp:310
const_iterator_base(const iterator_base &other)
Definition: soa/iterator.hpp:347
Definition: soa/iterator.hpp:234
Definition: soa/iterator.hpp:56
Definition: soa/iterator.hpp:75