@@ -128,42 +128,52 @@ 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
- mqbs::MappedFileDescriptor* mfd,
135
- ITER* iter,
136
- const char * filename)
134
+ mqbs::MappedFileDescriptor * mfd,
135
+ ITER * iter,
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
- case CHOICE::SELECTION_ID_N: {
143
+ case CHOICE::SELECTION_ID_N: {
144
144
reverse = false ;
145
145
skip = choice.n ();
146
- } break ;
147
- case CHOICE::SELECTION_ID_NEXT: {
146
+ } break ;
147
+ case CHOICE::SELECTION_ID_NEXT: {
148
148
reverse = false ;
149
149
skip = choice.next ();
150
- } break ;
151
- case CHOICE::SELECTION_ID_P: {
150
+ } break ;
151
+ case CHOICE::SELECTION_ID_P: {
152
152
reverse = true ;
153
153
skip = choice.p ();
154
- } break ;
155
- case CHOICE::SELECTION_ID_PREV: {
154
+ } break ;
155
+ case CHOICE::SELECTION_ID_PREV: {
156
156
reverse = true ;
157
157
skip = choice.prev ();
158
- } break ;
159
- case CHOICE::SELECTION_ID_RECORD: {
158
+ } break ;
159
+ case CHOICE::SELECTION_ID_RECORD: {
160
160
skip = choice.record ();
161
- } break ;
162
- case CHOICE::SELECTION_ID_R: {
163
- if (skip == -1 ) {
164
- skip = choice.r ();
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 ;
165
167
}
166
- if (skip >= static_cast <int >(iter->recordIndex ())) {
168
+ else {
169
+ skip = iter->recordIndex () - skip;
170
+ reverse = true ;
171
+ }
172
+ } break ;
173
+ case CHOICE::SELECTION_ID_R: {
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 ();
@@ -173,30 +183,32 @@ void iterateNextPosition(CHOICE& choice,
173
183
skip = iter->recordIndex () - skip;
174
184
reverse = true ;
175
185
}
176
- } break ;
177
- case CHOICE::SELECTION_ID_LIST: {
178
- skip = choice.list ();
179
- verbose = true ;
180
- if (skip >= 0 ) {
186
+ } break ;
187
+ case CHOICE::SELECTION_ID_LIST: {
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
}
187
- } break ;
188
- case CHOICE::SELECTION_ID_L: {
189
- skip = choice.l ();
190
- verbose = true ;
191
- if (skip >= 0 ) {
197
+ skip = list;
198
+ } break ;
199
+ case CHOICE::SELECTION_ID_L: {
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
}
198
- } break ;
199
- default :
209
+ skip = list;
210
+ } break ;
211
+ default :
200
212
BALL_LOG_ERROR << " Unsupported choice: " << choice.selectionId ();
201
213
return ; // RETURN
202
214
}
0 commit comments