1 /* ///////////////////////////////////////////////////////////////////////
2 * File: matrix_cole_iterator.h
7 * Brief: The Matrix Column Entry Iterator
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_CONTAINER_DETAIL_MATRIX_COLE_ITERATOR_H
14 #define EXTL_CONTAINER_DETAIL_MATRIX_COLE_ITERATOR_H
16 /* ///////////////////////////////////////////////////////////////////////
19 #include "../prefix.h"
21 /* ///////////////////////////////////////////////////////////////////////
22 * ::extl::detail namespace
25 EXTL_DETAIL_BEGIN_NAMESPACE
27 template< typename_param_k Val
28 , typename_param_k Mtx
30 class const_matrix_cole_iterator
31 : public const_bidirectional_iterator_base
< const_matrix_cole_iterator
<Val
, Mtx
>
37 typedef const_bidirectional_iterator_base
< const_matrix_cole_iterator
<Val
, Mtx
>
41 typedef base_type iterator_base_type
;
44 typedef const_matrix_cole_iterator class_type
;
45 typedef typename_type_k
iterator_base_type::iterator_category iterator_category
;
46 typedef typename_type_k
iterator_base_type::value_type value_type
;
47 typedef typename_type_k
iterator_base_type::reference reference
;
48 typedef typename_type_k
iterator_base_type::const_reference const_reference
;
49 typedef typename_type_k
iterator_base_type::pointer pointer
;
50 typedef typename_type_k
iterator_base_type::const_pointer const_pointer
;
51 typedef typename_type_k
iterator_base_type::difference_type difference_type
;
52 typedef typename_type_k
base_type::bool_type bool_type
;
53 typedef e_size_t size_type
;
54 typedef size_type index_type
;
55 typedef Mtx matrix_type
;
60 matrix_type
const* m_pmatrix
;
63 const_matrix_cole_iterator()
68 const_matrix_cole_iterator(index_type col
, index_type cur
, matrix_type
const& mx
)
73 const_matrix_cole_iterator(class_type
const& it
)
75 , m_current(it
.m_current
)
76 , m_pmatrix(it
.m_pmatrix
)
80 index_type
current() const { return m_current
; }
81 index_type
current() { return m_current
; }
82 matrix_type
const& matrix() const { EXTL_ASSERT(NULL
!= m_pmatrix
); return *m_pmatrix
; }
87 m_current
= (m_current
+ 1) % (matrix().dim0() + 1);
91 m_current
= (m_current
+ matrix().dim0() + 1 - 1) % (matrix().dim0() + 1);
93 const_reference
do_dereference() const
95 return matrix().at(m_current
, m_col
);
97 bool_type
do_equal(class_type
const& rhs
) const
99 return (m_pmatrix
== rhs
.m_pmatrix
) && current() == rhs
.current();
102 // matrix_cole_iterator can be converted to const_matrix_cole_iterator implicitly
103 template< typename_param_k Val
104 , typename_param_k Mtx
106 class matrix_cole_iterator
107 : public bidirectional_iterator_base
< matrix_cole_iterator
<Val
, Mtx
>
108 , const_matrix_cole_iterator
<Val
, Mtx
>
114 typedef bidirectional_iterator_base
< matrix_cole_iterator
<Val
, Mtx
>
115 , const_matrix_cole_iterator
<Val
, Mtx
>
119 typedef const_matrix_cole_iterator
<Val
, Mtx
> const_iterator_type
;
120 typedef base_type iterator_base_type
;
123 typedef matrix_cole_iterator class_type
;
124 typedef typename_type_k
iterator_base_type::iterator_category iterator_category
;
125 typedef typename_type_k
iterator_base_type::value_type value_type
;
126 typedef typename_type_k
iterator_base_type::reference reference
;
127 typedef typename_type_k
iterator_base_type::const_reference const_reference
;
128 typedef typename_type_k
iterator_base_type::pointer pointer
;
129 typedef typename_type_k
iterator_base_type::const_pointer const_pointer
;
130 typedef typename_type_k
iterator_base_type::difference_type difference_type
;
131 typedef typename_type_k
base_type::bool_type bool_type
;
132 typedef typename_type_k
base_type::index_type index_type
;
133 typedef typename_type_k
base_type::size_type size_type
;
134 typedef typename_type_k
base_type::matrix_type matrix_type
;
137 matrix_cole_iterator()
140 explicit_k
matrix_cole_iterator(index_type col
, index_type cur
, matrix_type
const& mx
)
141 : base_type(const_iterator_type(col
, cur
, mx
))
143 matrix_cole_iterator(class_type
const& it
)
146 // const_matrix_cole_iterator can be explicitly converted to matrix_cole_iterator
147 // because this is an empty member class
148 explicit_k
matrix_cole_iterator(const_iterator_type
const& it
)
154 /* ///////////////////////////////////////////////////////////////////////
155 * ::extl::detail namespace
157 EXTL_DETAIL_END_NAMESPACE
159 /* //////////////////////////////////////////////////////////////////// */
160 #endif /* EXTL_CONTAINER_DETAIL_MATRIX_COLE_ITERATOR_H */
161 /* //////////////////////////////////////////////////////////////////// */