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"
36 namespace mdds {
namespace mtv {
namespace soa {
namespace detail {
54 template<
typename _Trait>
58 using parent_type =
typename _Trait::parent;
59 using positions_type =
typename _Trait::positions_type;
60 using sizes_type =
typename _Trait::sizes_type;
61 using element_blocks_type =
typename _Trait::element_blocks_type;
62 using size_type =
typename _Trait::parent::size_type;
66 using positions_iterator_type =
typename _Trait::positions_iterator_type;
67 using sizes_iterator_type =
typename _Trait::sizes_iterator_type;
68 using element_blocks_iterator_type =
typename _Trait::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 &&
97 size_iterator == other.size_iterator &&
98 element_block_iterator == other.element_block_iterator;
103 return !operator==(other);
109 const positions_iterator_type& itr_pos,
110 const sizes_iterator_type& itr_size,
111 const element_blocks_iterator_type& itr_elem_blocks) :
112 position_iterator(itr_pos),
113 size_iterator(itr_size),
114 element_block_iterator(itr_elem_blocks)
126 const grouped_iterator_type& pos,
const grouped_iterator_type& end, size_type block_index) :
127 m_cur_node(block_index),
136 const positions_iterator_type& positions_pos,
137 const sizes_iterator_type& sizes_pos,
138 const element_blocks_iterator_type& eb_pos,
139 const positions_iterator_type& positions_end,
140 const sizes_iterator_type& sizes_end,
141 const element_blocks_iterator_type& eb_end,
142 size_type block_index) :
144 { positions_pos, sizes_pos, eb_pos },
145 { positions_end, sizes_end, eb_end },
151 iterator_updater(
const iterator_updater& other) :
152 m_cur_node(other.m_cur_node),
160 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
162 throw general_error(
"Current node position should never equal the end position during node update.");
165 m_cur_node.position = *m_pos.position_iterator;
166 m_cur_node.size = *m_pos.size_iterator;
167 m_cur_node.data = *m_pos.element_block_iterator;
170 m_cur_node.type = mdds::mtv::get_block_type(*m_cur_node.data);
172 m_cur_node.type = mdds::mtv::element_type_empty;
192 void _print_state(std::ostream& os)
const
194 os <<
"block-index=" << m_cur_node.__private_data.block_index
195 <<
"; position=" << m_cur_node.position
196 <<
"; size=" << m_cur_node.size
197 <<
"; type=" << m_cur_node.type
198 <<
"; data=0x" << std::hex << m_cur_node.data;
202 bool operator== (
const iterator_updater& other)
const
204 if (m_pos != m_end && other.m_pos != other.m_end)
208 if (m_cur_node != other.m_cur_node)
211 return m_pos == other.m_pos && m_end == other.m_end;
214 bool operator!= (
const iterator_updater& other)
const
216 return !operator==(other);
219 iterator_updater& operator= (
const iterator_updater& other)
221 m_cur_node = other.m_cur_node;
227 void swap(iterator_updater& other)
229 m_cur_node.swap(other.m_cur_node);
230 std::swap(m_pos, other.m_pos);
231 std::swap(m_end, other.m_end);
234 const node& get_node()
const {
return m_cur_node; }
235 const grouped_iterator_type& get_pos()
const {
return m_pos; }
236 const grouped_iterator_type& get_end()
const {
return m_end; }
239 template<
typename _Trait>
242 using node_update_func =
typename _Trait::private_data_update;
246 using size_type =
typename updater::size_type;
250 using updater::m_cur_node;
254 using updater::get_pos;
255 using updater::get_end;
259 using pointer = value_type*;
260 using reference = value_type&;
261 using difference_type = ptrdiff_t;
262 using iterator_category = std::bidirectional_iterator_tag;
267 const grouped_iterator_type& pos,
const grouped_iterator_type& end, size_type block_index) :
268 updater(pos, end, block_index) {}
270 value_type& operator*()
275 const value_type& operator*()
const
280 value_type* operator->()
285 const value_type* operator->()
const
292 node_update_func::inc(m_cur_node);
300 node_update_func::dec(m_cur_node);
304 void _print_state(std::ostream& os)
const
307 updater::_print_state(os);
312 template<
typename _Trait,
typename _NonConstItrBase>
315 using node_update_func =
typename _Trait::private_data_update;
319 using size_type =
typename updater::size_type;
323 using updater::m_cur_node;
327 using updater::get_pos;
328 using updater::get_end;
330 using iterator_base = _NonConstItrBase;
334 using pointer = value_type*;
335 using reference = value_type&;
336 using difference_type = ptrdiff_t;
337 using iterator_category = std::bidirectional_iterator_tag;
342 const grouped_iterator_type& pos,
const grouped_iterator_type& end, size_type block_index) :
343 updater(pos, end, block_index) {}
350 other.get_pos().position_iterator,
351 other.get_pos().size_iterator,
352 other.get_pos().element_block_iterator,
353 other.get_end().position_iterator,
354 other.get_end().size_iterator,
355 other.get_end().element_block_iterator,
356 other.get_node().__private_data.block_index) {}
358 const value_type& operator*()
const
363 const value_type* operator->()
const
368 const_iterator_base& operator++()
370 node_update_func::inc(m_cur_node);
375 const_iterator_base& operator--()
378 node_update_func::dec(m_cur_node);
382 bool operator== (
const const_iterator_base& other)
const
384 return updater::operator==(other);
387 bool operator!= (
const const_iterator_base& other)
const
389 return updater::operator!=(other);
392 void _print_state(std::ostream& os)
const
394 os <<
"(const-iterator: ";
395 updater::_print_state(os);
400 template<
typename _Trait>
401 std::ostream& operator<< (std::ostream& os,
const iterator_base<_Trait>& it)
407 template<
typename _Trait,
typename _NonConstItrBase>
408 std::ostream& operator<< (std::ostream& os,
const const_iterator_base<_Trait, _NonConstItrBase>& it)
Definition: soa/iterator.hpp:314
const_iterator_base(const iterator_base &other)
Definition: soa/iterator.hpp:348
Definition: soa/iterator.hpp:241
Definition: soa/iterator.hpp:56
Definition: soa/iterator.hpp:75