@@ -128,16 +128,16 @@ bool resetIterator(mqbs::MappedFileDescriptor* mfd,
128
128
// / opened by the iterator. Verify that the file and iterator are in a
129
129
// / valid state; reset them if this is not the case. Pass parameters to
130
130
// / indicate how many records to skip and whether that is forward
131
- // / or backwards. Return true on success and false on error.
131
+ // / or backwards.
132
132
template <typename CHOICE, typename ITER>
133
133
void iterateNextPosition (CHOICE& choice,
134
134
mqbs::MappedFileDescriptor* mfd,
135
135
ITER* iter,
136
136
const char * filename)
137
137
{
138
- int skip = - 1 ;
139
- bool reverse = false ;
140
- bool verbose = false ;
138
+ bsls::Types::Uint64 skip = 0 ;
139
+ bool reverse = false ;
140
+ bool verbose = false ;
141
141
142
142
switch (choice.selectionId ()) {
143
143
case CHOICE::SELECTION_ID_N: {
@@ -158,12 +158,22 @@ void iterateNextPosition(CHOICE& choice,
158
158
} break ;
159
159
case CHOICE::SELECTION_ID_RECORD: {
160
160
skip = choice.record ();
161
+
162
+ if (skip >= iter->recordIndex ()) {
163
+ // If the skip is greater than our current index, than we are
164
+ // iterating forward to reach the specified index.
165
+ skip -= iter->recordIndex ();
166
+ reverse = false ;
167
+ }
168
+ else {
169
+ skip = iter->recordIndex () - skip;
170
+ reverse = true ;
171
+ }
161
172
} break ;
162
173
case CHOICE::SELECTION_ID_R: {
163
- if (skip == -1 ) {
164
- skip = choice.r ();
165
- }
166
- if (skip >= static_cast <int >(iter->recordIndex ())) {
174
+ skip = choice.r ();
175
+
176
+ if (skip >= iter->recordIndex ()) {
167
177
// If the skip is greater than our current index, than we are
168
178
// iterating forward to reach the specified index.
169
179
skip -= iter->recordIndex ();
@@ -175,26 +185,28 @@ void iterateNextPosition(CHOICE& choice,
175
185
}
176
186
} break ;
177
187
case CHOICE::SELECTION_ID_LIST: {
178
- skip = choice.list ();
179
- verbose = true ;
180
- if (skip >= 0 ) {
188
+ int list = choice.list ();
189
+ verbose = true ;
190
+ if (list >= 0 ) {
181
191
reverse = false ;
182
192
}
183
193
else {
184
194
reverse = true ;
185
- skip *= -1 ;
195
+ list *= -1 ;
186
196
}
197
+ skip = list;
187
198
} break ;
188
199
case CHOICE::SELECTION_ID_L: {
189
- skip = choice.l ();
190
- verbose = true ;
191
- if (skip >= 0 ) {
200
+ int list = choice.l ();
201
+ verbose = true ;
202
+ if (list >= 0 ) {
192
203
reverse = false ;
193
204
}
194
205
else {
195
206
reverse = true ;
196
- skip *= -1 ;
207
+ list *= -1 ;
197
208
}
209
+ skip = list;
198
210
} break ;
199
211
default :
200
212
BALL_LOG_ERROR << " Unsupported choice: " << choice.selectionId ();
0 commit comments