@@ -192,15 +192,16 @@ private static void generateGroupClassHeader(
192
192
final int blockLength = tokens .get (index ).encodedLength ();
193
193
final Token blockLengthToken = Generators .findFirst ("blockLength" , tokens , index );
194
194
final Token numInGroupToken = Generators .findFirst ("numInGroup" , tokens , index );
195
- final String cppTypeForBlockLength = cppTypeName (blockLengthToken .encoding ().primitiveType ());
196
- final String cppTypeForNumInGroup = cppTypeName (numInGroupToken .encoding ().primitiveType ());
195
+ final String cppTypeBlockLength = cppTypeName (blockLengthToken .encoding ().primitiveType ());
196
+ final String cppTypeNumInGroup = cppTypeName (numInGroupToken .encoding ().primitiveType ());
197
197
198
198
new Formatter (sb ).format ("\n " +
199
199
indent + "class %1$s\n " +
200
200
indent + "{\n " +
201
201
indent + "private:\n " +
202
202
indent + " char *m_buffer = nullptr;\n " +
203
203
indent + " std::uint64_t m_bufferLength = 0;\n " +
204
+ indent + " std::uint64_t m_initialPosition = 0;\n " +
204
205
indent + " std::uint64_t *m_positionPtr = nullptr;\n " +
205
206
indent + " std::uint64_t m_blockLength = 0;\n " +
206
207
indent + " std::uint64_t m_count = 0;\n " +
@@ -228,8 +229,9 @@ private static void generateGroupClassHeader(
228
229
indent + " m_bufferLength = bufferLength;\n " +
229
230
indent + " m_blockLength = dimensions.blockLength();\n " +
230
231
indent + " m_count = dimensions.numInGroup();\n " +
231
- indent + " m_index = std::numeric_limits<std::uint64_t>::max() ;\n " +
232
+ indent + " m_index = 0 ;\n " +
232
233
indent + " m_actingVersion = actingVersion;\n " +
234
+ indent + " m_initialPosition = *pos;\n " +
233
235
indent + " m_positionPtr = pos;\n " +
234
236
indent + " *m_positionPtr = *m_positionPtr + %1$d;\n " +
235
237
indent + " }\n " ,
@@ -262,14 +264,18 @@ private static void generateGroupClassHeader(
262
264
indent + " %7$s dimensions(buffer, *pos, bufferLength, actingVersion);\n " +
263
265
indent + " dimensions.blockLength((%1$s)%2$d);\n " +
264
266
indent + " dimensions.numInGroup((%3$s)count);\n " +
265
- indent + " m_index = std::numeric_limits<std::uint64_t>::max() ;\n " +
267
+ indent + " m_index = 0 ;\n " +
266
268
indent + " m_count = count;\n " +
267
269
indent + " m_blockLength = %2$d;\n " +
268
270
indent + " m_actingVersion = actingVersion;\n " +
271
+ indent + " m_initialPosition = *pos;\n " +
269
272
indent + " m_positionPtr = pos;\n " +
270
273
indent + " *m_positionPtr = *m_positionPtr + %4$d;\n " +
271
274
indent + " }\n " ,
272
- cppTypeForBlockLength , blockLength , cppTypeForNumInGroup , dimensionHeaderLength ,
275
+ cppTypeBlockLength ,
276
+ blockLength ,
277
+ cppTypeNumInGroup ,
278
+ dimensionHeaderLength ,
273
279
minCheck ,
274
280
numInGroupToken .encoding ().applicableMaxValue ().longValue (),
275
281
dimensionsClassName );
@@ -311,25 +317,41 @@ private static void generateGroupClassHeader(
311
317
312
318
indent + " SBE_NODISCARD inline bool hasNext() const SBE_NOEXCEPT\n " +
313
319
indent + " {\n " +
314
- indent + " return m_index + 1 < m_count;\n " +
320
+ indent + " return m_index < m_count;\n " +
315
321
indent + " }\n \n " +
316
322
317
323
indent + " inline %3$s &next()\n " +
318
324
indent + " {\n " +
325
+ indent + " if (m_index >= m_count)\n " +
326
+ indent + " {\n " +
327
+ indent + " throw std::runtime_error(\" index >= count [E108]\" );\n " +
328
+ indent + " }\n " +
319
329
indent + " m_offset = *m_positionPtr;\n " +
320
330
indent + " if (SBE_BOUNDS_CHECK_EXPECT(((m_offset + m_blockLength) > m_bufferLength), false))\n " +
321
331
indent + " {\n " +
322
- indent + " throw std::runtime_error(\" " +
323
- "buffer too short to support next group index [E108]\" );\n " +
332
+ indent + " throw std::runtime_error(\" buffer too short for next group index [E108]\" );\n " +
324
333
indent + " }\n " +
325
334
indent + " *m_positionPtr = m_offset + m_blockLength;\n " +
326
335
indent + " ++m_index;\n \n " +
327
336
328
337
indent + " return *this;\n " +
329
338
indent + " }\n " ,
330
- dimensionHeaderLength , blockLength , formatClassName (groupName ));
339
+ dimensionHeaderLength ,
340
+ blockLength ,
341
+ formatClassName (groupName ));
342
+
343
+ sb .append ("\n " )
344
+ .append (indent ).append (" inline std::uint64_t resetCountToIndex() SBE_NOEXCEPT\n " )
345
+ .append (indent ).append (" {\n " )
346
+ .append (indent ).append (" m_count = m_index;\n " )
347
+ .append (indent ).append (" " ).append (dimensionsClassName )
348
+ .append (" dimensions(m_buffer, m_initialPosition, m_bufferLength, m_actingVersion);\n " )
349
+ .append (indent ).append (" dimensions.numInGroup((" ).append (cppTypeNumInGroup ).append (")m_count);\n " )
350
+ .append (indent ).append (" return m_count;\n " )
351
+ .append (indent ).append (" }\n " );
331
352
332
- sb .append (indent ).append ("#if __cplusplus < 201103L\n " )
353
+ sb .append ("\n " )
354
+ .append (indent ).append ("#if __cplusplus < 201103L\n " )
333
355
.append (indent ).append (" template<class Func> inline void forEach(Func& func)\n " )
334
356
.append (indent ).append (" {\n " )
335
357
.append (indent ).append (" while (hasNext())\n " )
0 commit comments