BALL
1.4.1
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
vectorIterator.h
Go to the documentation of this file.
1
#ifndef BALL_LINALG_VECTORITERATOR_H
2
#define BALL_LINALG_VECTORITERATOR_H
3
4
#ifndef BALL_LINALG_VECTOR_IH
5
# include <BALL/MATHS/LINALG/vector.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
<
typename
valuetype>
16
class
Vector;
17
18
19
template
<
typename
valuetype>
20
class
VectorIteratorTraits
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
Vector<valuetype>;
44
public
:
45
46
virtual
~VectorIteratorTraits
()
47
{
48
}
49
50
VectorIteratorTraits
()
51
:
bound_
(0),
52
position_
(0)
53
{
54
}
55
56
VectorIteratorTraits
(
const
Vector<valuetype>
& vector)
57
:
bound_
(const_cast<Vector<valuetype>*>(&vector)),
58
position_
(0)
59
{
60
}
61
62
VectorIteratorTraits
(
const
VectorIteratorTraits
& traits)
63
:
bound_
(traits.
bound_
),
64
position_
(traits.
position_
)
65
{
66
}
67
68
VectorIteratorTraits
&
operator =
(
const
VectorIteratorTraits
& traits)
69
{
70
bound_
= traits.
bound_
;
71
position_
= traits.
position_
;
72
73
return
*
this
;
74
}
75
76
Vector<valuetype>
*
getContainer
()
77
{
78
return
bound_
;
79
}
80
81
const
Vector<valuetype>
*
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
VectorIteratorTraits
& traits)
const
102
{
103
return
(
position_
== traits.
position_
);
104
}
105
106
bool
operator !=
(
const
VectorIteratorTraits
& traits)
const
107
{
108
return
(
position_
!= traits.
position_
);
109
}
110
111
bool
operator <
(
const
VectorIteratorTraits
& traits)
const
112
{
113
return
(
position_
< traits.
position_
);
114
}
115
116
Distance
getDistance
(
const
VectorIteratorTraits
& 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
position_
++;
165
}
166
167
friend
std::ostream&
operator <<
(std::ostream& s,
const
VectorIteratorTraits
& traits)
168
{
169
return
(s << traits.
position_
<<
' '
);
170
}
171
172
void
dump
(std::ostream& s)
const
173
{
174
s <<
position_
<< std::endl;
175
}
176
177
void
toRBegin
()
178
{
179
position_
=
bound_
->data_.size() - 1;
180
}
181
182
bool
isRBegin
()
const
183
{
184
return
(
position_
==
bound_
->data_.size() - 1);
185
}
186
187
void
toREnd
()
188
{
189
position_
= -1;
190
}
191
192
bool
isREnd
()
const
193
{
194
return
(
position_
<= -1);
195
}
196
197
void
backward
()
198
{
199
position_
--;
200
}
201
202
void
backward
(
Distance
distance)
203
{
204
position_
-= distance;
205
}
206
207
void
forward
(
Distance
distance)
208
{
209
position_
+= distance;
210
}
211
212
ValueType
&
getData
(
Index
index)
213
{
214
return
(*
bound_
)[index];
215
}
216
217
const
ValueType
&
getData
(
Index
index)
const
218
{
219
return
(*
bound_
)[index];
220
}
221
222
223
protected
:
224
225
Vector<valuetype>
*
bound_
;
226
IteratorPosition
position_
;
227
};
228
229
230
}
// namespace BALL
231
232
#endif
Generated by
1.8.1.2