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
rowIterator.h
Go to the documentation of this file.
1
#ifndef BALL_LINALG_ROWITERATOR_H
2
#define BALL_LINALG_ROWITERATOR_H
3
4
#ifndef BALL_LINALG_MATRIX_IH
5
# include <BALL/MATHS/LINALG/matrix.ih>
6
#endif
7
8
#ifndef BALL_LINALG_VECTOR_IH
9
# include <BALL/MATHS/LINALG/vector.ih>
10
#endif
11
12
#ifndef BALL_CONCEPT_RANDOMACCESSITERATOR_H
13
#include <
BALL/CONCEPT/randomAccessIterator.h
>
14
#endif
15
16
17
typedef
unsigned
int
uint
;
18
19
namespace
BALL {
20
21
// forward declaration
22
template
<
class
valuetype,
class
mtraits>
23
class
Matrix;
24
25
template
<
class
valuetype,
class
mtraits=StandardTraits>
26
class
RowIteratorTraits
27
{
28
31
typedef
valuetype
ValueType
;
32
35
typedef
valuetype*
PointerType
;
36
39
typedef
int
IteratorPosition
;
40
43
typedef
int
Distance
;
44
47
typedef
int
Index
;
48
49
friend
class
Matrix
<valuetype, mtraits>;
50
public
:
51
52
virtual
~RowIteratorTraits
()
53
{
54
}
55
56
RowIteratorTraits
()
57
:
bound_
(0),
58
position_
(0),
59
vector_
(0)
60
{
61
}
62
63
RowIteratorTraits
(
const
Matrix<valuetype, mtraits>
& matrix)
64
:
bound_
(const_cast<
Matrix
<valuetype, mtraits>*>(&matrix)),
65
position_
(0),
66
vector_
(
bound_
->m_)
67
{
68
}
69
70
RowIteratorTraits
(
const
RowIteratorTraits
& traits)
71
:
bound_
(traits.
bound_
),
72
position_
(traits.
position_
),
73
vector_
(
bound_
->m_)
74
{
75
}
76
77
RowIteratorTraits
&
operator =
(
const
RowIteratorTraits
& traits)
78
{
79
bound_
= traits.
bound_
;
80
position_
= traits.
position_
;
81
vector_
= traits.
vector_
;
82
83
return
*
this
;
84
}
85
86
Matrix<valuetype, mtraits>
*
getContainer
()
87
{
88
return
bound_
;
89
}
90
91
const
Matrix<valuetype, mtraits>
*
getContainer
()
const
92
{
93
return
bound_
;
94
}
95
96
bool
isSingular
()
const
97
{
98
return
(
bound_
== 0);
99
}
100
101
IteratorPosition
&
getPosition
()
102
{
103
return
position_
;
104
}
105
106
const
IteratorPosition
&
getPosition
()
const
107
{
108
return
position_
;
109
}
110
111
bool
operator ==
(
const
RowIteratorTraits
& traits)
const
112
{
113
return
(
position_
== traits.
position_
);
114
}
115
116
bool
operator !=
(
const
RowIteratorTraits
& traits)
const
117
{
118
return
(
position_
!= traits.
position_
);
119
}
120
121
bool
operator <
(
const
RowIteratorTraits
& traits)
const
122
{
123
return
(
position_
< traits.
position_
);
124
}
125
126
Distance
getDistance
(
const
RowIteratorTraits
& traits)
const
127
{
128
return
(
Distance
)(
position_
- traits.
position_
);
129
}
130
131
bool
isValid
()
const
132
{
133
return
((
bound_
!= 0) && (
position_
>= 0) && (
position_
< (
int
)
bound_
->data_.size()));
134
}
135
136
void
invalidate
()
137
{
138
bound_
= 0;
139
position_
= -1;
140
}
141
142
void
toBegin
()
143
{
144
position_
= 0;
145
}
146
147
bool
isBegin
()
const
148
{
149
return
(
position_
== 0 );
150
}
151
152
void
toEnd
()
153
{
154
position_
=
bound_
->data_.size();
155
}
156
157
bool
isEnd
()
const
158
{
159
return
(
position_
== (
int
)
bound_
->data_.size());
160
}
161
162
Vector<valuetype>
&
getData
()
163
{
164
165
if
(
bound_
->row_major_)
166
{
167
for
(
uint
i = 0; i <
bound_
->m_; i++)
168
{
169
vector_
[i]=&(*bound_)[
position_
+i];
170
}
171
}
172
else
173
{
174
uint
j = 0;
175
for
(
uint
i = 0; i <
bound_
->data_.size(); i+=
bound_
->n_)
176
{
177
vector_
[j++]=&(*bound_)[
position_
+i];
178
}
179
}
180
181
return
vector_
;
182
}
183
184
const
Vector<valuetype>
&
getData
()
const
185
{
186
187
if
(
bound_
->row_major_)
188
{
189
for
(
uint
i = 0; i <
bound_
->m_; i++)
190
{
191
vector_
[i]=(*bound_)[
position_
+i];
192
}
193
}
194
else
195
{
196
uint
j = 0;
197
for
(
uint
i = 0; i <
bound_
->data_.size(); i+=
bound_
->n_)
198
{
199
vector_
[j++]=(*bound_)[
position_
+i];
200
}
201
}
202
return
vector_
;
203
204
}
205
206
void
forward
()
207
{
208
if
(
bound_
->row_major_)
209
{
210
position_
+=
bound_
->m_;
211
}
212
else
213
{
214
position_
++;
215
if
(
position_
== (
int
)
bound_
->n_)
216
position_
=
bound_
->data_.size();
217
}
218
}
219
220
friend
std::ostream&
operator <<
(std::ostream& s,
const
RowIteratorTraits
& traits)
221
{
222
return
(s << traits.
position_
<<
' '
);
223
}
224
225
void
dump
(std::ostream& s)
const
226
{
227
s <<
position_
<< std::endl;
228
}
229
230
void
toRBegin
()
231
{
232
position_
=
bound_
->data_.size() - 1;
233
}
234
235
bool
isRBegin
()
const
236
{
237
return
(
position_
==
bound_
->data_.size() - 1);
238
}
239
240
void
toREnd
()
241
{
242
position_
= -1;
243
}
244
245
bool
isREnd
()
const
246
{
247
return
(
position_
<= -1);
248
}
249
250
void
backward
()
251
{
252
if
(
bound_
->row_major_)
253
{
254
if
(
position_
== 0)
255
position_
--;
256
else
257
position_
-=
bound_
->m_;
258
}
259
else
260
{
261
if
(
position_
== (
int
)
bound_
->data_.size())
262
position_
=
bound_
->n_;
263
position_
--;
264
}
265
}
266
267
void
backward
(
Distance
distance)
268
{
269
if
(
bound_
->row_major_)
270
{
271
if
(
position_
-(distance * (
int
)
bound_
->m_) < 0)
272
{
273
position_
= -1;
274
return
;
275
}
276
position_
-= (distance * (int)
bound_
->m_);
277
278
}
279
else
280
{
281
if
(
position_
== (
int
)
bound_
->data_.size())
282
position_
=
bound_
->n_;
283
if (
position_
-distance < 0)
284
{
285
position_
= -1;
286
return
;
287
}
288
position_
-= distance;
289
}
290
}
291
292
void
forward
(
Distance
distance)
293
{
294
295
if
(
bound_
->row_major_)
296
{
297
if
(
position_
+(distance *
bound_
->m_) >
bound_
->data_.size())
298
{
299
position_
=
bound_
->data_.size();
300
return
;
301
}
302
position_
+= (distance *
bound_
->m_);
303
}
304
else
305
{
306
position_
+= distance;
307
if
(
position_
>= (
int
)
bound_
->n_)
308
position_
=
bound_
->data_.size();
309
}
310
}
311
312
Vector<valuetype>
&
getData
(
Index
index)
313
{
314
315
if
(
bound_
->row_major_)
316
{
317
for
(
uint
i = 0; i <
bound_
->m_; i++)
318
vector_
[i]=(*
bound_
)[index+i];
319
}
320
else
321
{
322
for
(
uint
i = 0; i <
bound_
->m_; i+=
bound_
->n_)
323
vector_
[i]=(*
bound_
)[index+i];
324
}
325
326
return
vector_
;
327
}
328
329
const
Vector<valuetype>
&
getData
(
Index
index)
const
330
{
331
332
if
(
bound_
->row_major_)
333
{
334
for
(
uint
i = 0; i <
bound_
->m_; i++)
335
vector_
[i]=(*
bound_
)[index+i];
336
}
337
else
338
{
339
for
(
uint
i = 0; i <
bound_
->m_; i+=
bound_
->n_)
340
vector_
[i]=(*
bound_
)[index+i];
341
}
342
343
return
vector_
;
344
}
345
346
347
protected
:
348
349
Matrix<valuetype, mtraits>
*
bound_
;
350
IteratorPosition
position_
;
351
mutable
Vector<valuetype>
vector_
;
352
};
353
354
355
}
// namespace BALL
356
357
#endif
Generated by
1.8.3.1