BALL
1.4.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
BALL
MATHS
LINALG
elementColumnIterator.h
Go to the documentation of this file.
1
#ifndef BALL_LINALG_ELEMENTCOLUMNITERATOR_H
2
#define BALL_LINALG_ELEMENTCOLUMNITERATOR_H
3
4
#ifndef BALL_LINALG_MATRIX_IH
5
# include <BALL/MATHS/LINALG/matrix.ih>
6
#endif
7
8
#ifndef BALL_CONCEPT_RANDOMACCESSITERATOR_H
9
#include <
BALL/CONCEPT/randomAccessIterator.h
>
10
#endif
11
12
namespace
BALL {
13
14
// forward declaration
15
template
<
class
valuetype,
class
mtraits>
16
class
Matrix;
17
18
19
template
<
class
valuetype,
class
mtraits=StandardTraits>
20
class
ElementColumnIteratorTraits
21
{
22
25
typedef
valuetype
ValueType
;
26
29
typedef
valuetype*
PointerType
;
30
33
typedef
int
IteratorPosition
;
34
37
typedef
int
Distance
;
38
41
typedef
int
Index
;
42
43
friend
class
Matrix
<valuetype, mtraits>;
44
public
:
45
46
virtual
~ElementColumnIteratorTraits
()
47
{
48
}
49
50
ElementColumnIteratorTraits
()
51
:
bound_
(0),
52
position_
(0)
53
{
54
}
55
56
ElementColumnIteratorTraits
(
const
Matrix<valuetype, mtraits>
& matrix)
57
:
bound_
(const_cast<
Matrix
<valuetype, mtraits>*>(&matrix)),
58
position_
(0)
59
{
60
}
61
62
ElementColumnIteratorTraits
(
const
ElementColumnIteratorTraits
& traits)
63
:
bound_
(traits.
bound_
),
64
position_
(traits.
position_
)
65
{
66
}
67
68
ElementColumnIteratorTraits
&
operator =
(
const
ElementColumnIteratorTraits
& traits)
69
{
70
bound_
= traits.
bound_
;
71
position_
= traits.
position_
;
72
73
return
*
this
;
74
}
75
76
Matrix<valuetype, mtraits>
*
getContainer
()
77
{
78
return
bound_
;
79
}
80
81
const
Matrix<valuetype, mtraits>
*
getContainer
()
const
82
{
83
return
bound_
;
84
}
85
86
bool
isSingular
()
const
87
{
88
return
(
bound_
== 0);
89
}
90
91
IteratorPosition
&
getPosition
()
92
{
93
return
position_
;
94
}
95
96
const
IteratorPosition
&
getPosition
()
const
97
{
98
return
position_
;
99
}
100
101
bool
operator ==
(
const
ElementColumnIteratorTraits
& traits)
const
102
{
103
return
(
position_
== traits.
position_
);
104
}
105
106
bool
operator !=
(
const
ElementColumnIteratorTraits
& traits)
const
107
{
108
return
(
position_
!= traits.
position_
);
109
}
110
111
bool
operator <
(
const
ElementColumnIteratorTraits
& traits)
const
112
{
113
return
(
position_
< traits.
position_
);
114
}
115
116
Distance
getDistance
(
const
ElementColumnIteratorTraits
& traits)
const
117
{
118
return
(
Distance
)(
position_
- traits.
position_
);
119
}
120
121
bool
isValid
()
const
122
{
123
return
((
bound_
!= 0) && (
position_
>= 0) && (
position_
< (
int
)
bound_
->data_.size()));
124
}
125
126
void
invalidate
()
127
{
128
bound_
= 0;
129
position_
= -1;
130
}
131
132
void
toBegin
()
133
{
134
position_
= 0;
135
}
136
137
bool
isBegin
()
const
138
{
139
return
(
position_
== 0 );
140
}
141
142
void
toEnd
()
143
{
144
position_
=
bound_
->data_.size();
145
}
146
147
bool
isEnd
()
const
148
{
149
return
(
position_
== (
int
)
bound_
->data_.size());
150
}
151
152
ValueType
&
getData
()
153
{
154
return
(*
bound_
)[
position_
];
155
}
156
157
const
ValueType
&
getData
()
const
158
{
159
return
(*
bound_
)[
position_
];
160
}
161
162
void
forward
()
163
{
164
if
(
bound_
->row_major_)
165
{
166
if
((
uint
)(
position_
+1) ==
bound_
->data_.size())
167
{
168
position_
++;
169
return
;
170
}
171
position_
+=
bound_
->m_;
172
if
((
uint
)
position_
>=
bound_
->data_.size())
173
position_
= (
position_
%
bound_
->n_) + 1;
174
}
175
else
176
{
177
position_
++;
178
}
179
}
180
181
friend
std::ostream&
operator <<
(std::ostream& s,
const
ElementColumnIteratorTraits
& traits)
182
{
183
return
(s << traits.
position_
<<
' '
);
184
}
185
186
void
dump
(std::ostream& s)
const
187
{
188
s <<
position_
<< std::endl;
189
}
190
191
void
toRBegin
()
192
{
193
position_
=
bound_
->data_.size() - 1;
194
}
195
196
bool
isRBegin
()
const
197
{
198
return
(
position_
==
bound_
->data_.size() - 1);
199
}
200
201
void
toREnd
()
202
{
203
position_
= -1;
204
}
205
206
bool
isREnd
()
const
207
{
208
return
(
position_
<= -1);
209
}
210
211
void
backward
()
212
{
213
if
(
bound_
->row_major_)
214
{
215
if
(
position_
== 0)
216
{
217
position_
--;
218
return
;
219
}
220
position_
-=
bound_
->m_;
221
if
(
position_
< 0)
222
position_
= (int)(
bound_
->data_.size()) - 1 +
position_
;
223
}
224
else
225
{
226
position_
--;
227
}
228
}
229
230
void
backward
(
Distance
distance)
231
{
232
if
(
bound_
->row_major_)
233
{
234
for
(
int
i=0; i<distance; i++)
235
{
236
if
(
position_
== 0)
237
{
238
position_
--;
239
return
;
240
}
241
position_
-=
bound_
->m_;
242
if
(
position_
< 0)
243
position_
= (int)(
bound_
->data_.size()) - 1 +
position_
;
244
}
245
}
246
else
247
{
248
position_
-= distance;
249
}
250
}
251
252
void
forward
(
Distance
distance)
253
{
254
if
(
bound_
->row_major_)
255
{
256
for
(
int
i=0; i<distance; i++)
257
{
258
if
((
uint
)(
position_
+1) ==
bound_
->data_.size())
259
{
260
position_
++;
261
return
;
262
}
263
position_
+=
bound_
->m_;
264
if
((
uint
)
position_
>=
bound_
->data_.size())
265
position_
= (
position_
%
bound_
->n_) + 1;
266
}
267
}
268
else
269
{
270
position_
+= distance;
271
}
272
}
273
274
ValueType
&
getData
(
Index
index)
275
{
276
return
(*
bound_
)[index];
277
}
278
279
const
ValueType
&
getData
(
Index
index)
const
280
{
281
return
(*
bound_
)[index];
282
}
283
284
285
protected
:
286
287
Matrix<valuetype, mtraits>
*
bound_
;
288
IteratorPosition
position_
;
289
};
290
291
292
}
// namespace BALL
293
294
#endif
Generated by
1.8.3.1