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