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