remove \r
[extl.git] / extl / container / detail / matrix_cole_iterator.h
blobb85f286b26bc5dec795f5bbfbe2c4d5d9ef71443
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: matrix_cole_iterator.h
4 * Created: 08.12.05
5 * Updated: 08.12.05
7 * Brief: The Matrix Column Entry Iterator
9 * [<Home>]
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 /* ///////////////////////////////////////////////////////////////////////
17 * Includes
19 #include "../prefix.h"
21 /* ///////////////////////////////////////////////////////////////////////
22 * ::extl::detail namespace
24 EXTL_BEGIN_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>
32 , Val
33 , e_ptrdiff_t
36 private:
37 typedef const_bidirectional_iterator_base < const_matrix_cole_iterator<Val, Mtx>
38 , Val
39 , e_ptrdiff_t
40 > base_type;
41 typedef base_type iterator_base_type;
43 public:
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;
57 private:
58 index_type m_col;
59 index_type m_current;
60 matrix_type const* m_pmatrix;
62 public:
63 const_matrix_cole_iterator()
64 : m_col(0)
65 , m_current(0)
66 , m_pmatrix(NULL)
68 const_matrix_cole_iterator(index_type col, index_type cur, matrix_type const& mx)
69 : m_col(col)
70 , m_current(cur)
71 , m_pmatrix(&mx)
72 {}
73 const_matrix_cole_iterator(class_type const& it)
74 : m_col(it.m_col)
75 , m_current(it.m_current)
76 , m_pmatrix(it.m_pmatrix)
79 public:
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; }
84 public:
85 void do_increase()
87 m_current = (m_current + 1) % (matrix().dim0() + 1);
89 void do_decrease()
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>
109 , Val
110 , e_ptrdiff_t
113 private:
114 typedef bidirectional_iterator_base < matrix_cole_iterator<Val, Mtx>
115 , const_matrix_cole_iterator<Val, Mtx>
116 , Val
117 , e_ptrdiff_t
118 > base_type;
119 typedef const_matrix_cole_iterator<Val, Mtx> const_iterator_type;
120 typedef base_type iterator_base_type;
122 public:
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;
136 public:
137 matrix_cole_iterator()
138 : base_type()
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)
144 : base_type(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)
149 : base_type(it)
154 /* ///////////////////////////////////////////////////////////////////////
155 * ::extl::detail namespace
157 EXTL_DETAIL_END_NAMESPACE
158 EXTL_END_NAMESPACE
159 /* //////////////////////////////////////////////////////////////////// */
160 #endif /* EXTL_CONTAINER_DETAIL_MATRIX_COLE_ITERATOR_H */
161 /* //////////////////////////////////////////////////////////////////// */