@@ -183,7 +183,8 @@ private void generateGroupClassHeader(
183183 ));
184184
185185 sb .append (String .format (
186-  indent  + " void wrapForDecode(char *buffer, int *pos, const int actingVersion, const int bufferLength)\n "  +
186+  indent  + " inline void wrapForDecode(char *buffer, int *pos, const int actingVersion,"  +
187+  indent  + " const int bufferLength)\n "  +
187188 indent  + " {\n "  +
188189 indent  + " buffer_ = buffer;\n "  +
189190 indent  + " bufferLength_ = bufferLength;\n "  +
@@ -203,8 +204,8 @@ private void generateGroupClassHeader(
203204 final  String  cpp98TypeForNumInGroup  = cpp98TypeName (tokens .get (index  + 3 ).encoding ().primitiveType ());
204205
205206 sb .append (String .format (
206-  indent  + " void wrapForEncode(char *buffer, const int count,\n "  +
207-  indent  + "   int *pos, const int actingVersion, const int bufferLength)\n "  +
207+  indent  + " inline  void wrapForEncode(char *buffer, const int count,"  +
208+  indent  + " int *pos, const int actingVersion, const int bufferLength)\n "  +
208209 indent  + " {\n "  +
209210 indent  + " buffer_ = buffer;\n "  +
210211 indent  + " bufferLength_ = bufferLength;\n "  +
@@ -224,42 +225,53 @@ private void generateGroupClassHeader(
224225 sb .append (String .format (
225226 indent  + " static const int sbeHeaderSize()\n "  +
226227 indent  + " {\n "  +
227-  indent  + " return %d;\n "  +
228-  indent  + " }\n \n " ,
229-  dimensionHeaderLength 
230-  ));
231- 
232-  sb .append (String .format (
228+  indent  + " return %1$d;\n "  +
229+  indent  + " }\n \n "  +
233230 indent  + " static const int sbeBlockLength()\n "  +
234231 indent  + " {\n "  +
235-  indent  + " return %d;\n "  +
236-  indent  + " }\n \n " ,
237-  blockLength 
238-  ));
239- 
240-  sb .append (String .format (
241-  indent  + " int count(void) const\n "  +
232+  indent  + " return %2$d;\n "  +
233+  indent  + " }\n \n "  +
234+  indent  + " inline int count(void) const\n "  +
242235 indent  + " {\n "  +
243236 indent  + " return count_;\n "  +
244237 indent  + " }\n \n "  +
245-  indent  + " bool hasNext(void) const\n "  +
238+  indent  + " inline  bool hasNext(void) const\n "  +
246239 indent  + " {\n "  +
247240 indent  + " return index_ + 1 < count_;\n "  +
248-  indent  + " }\n \n " 
249-  ));
250- 
251-  sb .append (String .format (
252-  indent  + " %1$s &next(void)\n "  +
241+  indent  + " }\n \n "  +
242+  indent  + " inline %3$s &next(void)\n "  +
253243 indent  + " {\n "  +
254244 indent  + " offset_ = *positionPtr_;\n "  +
255-  indent  + " if (SBE_BOUNDS_CHECK_EXPECT(( (offset_ + blockLength_) > bufferLength_ ),0 ))\n "  +
245+  indent  + " if (SBE_BOUNDS_CHECK_EXPECT(( (offset_ + blockLength_) > bufferLength_ ), false ))\n "  +
256246 indent  + " {\n "  +
257247 indent  + " throw std::runtime_error(\" buffer too short to support next group index [E108]\" );\n "  +
258248 indent  + " }\n "  +
259249 indent  + " *positionPtr_ = offset_ + blockLength_;\n "  +
260250 indent  + " ++index_;\n \n "  +
261251 indent  + " return *this;\n "  +
262252 indent  + " }\n \n " ,
253+  dimensionHeaderLength , blockLength , formatClassName (groupName )
254+  ));
255+ 
256+  sb .append (String .format (
257+  indent  + "#if __cplusplus < 201103L\n "  +
258+  indent  + " template<class Func>\n "  +
259+  indent  + " inline void forEach(Func& func)\n "  +
260+  indent  + " {\n "  +
261+  indent  + " while(hasNext())\n "  +
262+  indent  + " {\n "  +
263+  indent  + " next(); func(*this);\n "  +
264+  indent  + " }\n "  +
265+  indent  + " }\n \n "  +
266+  indent  + "#else\n "  +
267+  indent  + " inline void forEach(std::function<void(%1$s&)> func)\n "  +
268+  indent  + " {\n "  +
269+  indent  + " while(hasNext())\n "  +
270+  indent  + " {\n "  +
271+  indent  + " next(); func(*this);\n "  +
272+  indent  + " }\n "  +
273+  indent  + " }\n \n "  +
274+  indent  + "#endif\n \n " ,
263275 formatClassName (groupName )
264276 ));
265277 }
@@ -292,7 +304,7 @@ private CharSequence generateGroupProperty(final String groupName, final Token t
292304
293305 sb .append (String .format (
294306 "\n "  +
295-  indent  + " %1$s &%2$s(void)\n "  +
307+  indent  + " inline  %1$s &%2$s(void)\n "  +
296308 indent  + " {\n "  +
297309 indent  + " %2$s_.wrapForDecode(buffer_, positionPtr_, actingVersion_, bufferLength_);\n "  +
298310 indent  + " return %2$s_;\n "  +
@@ -1067,16 +1079,38 @@ private CharSequence generateFixedFlyweightCode(final String className, final in
10671079 " char *buffer_;\n "  +
10681080 " int offset_;\n "  +
10691081 " int actingVersion_;\n \n "  +
1070-  "public:\n "  +
1071-  " %1$s &wrap(char *buffer, const int offset, const int actingVersion, const int bufferLength)\n "  +
1082+  " inline void reset(char *buffer, const int offset, const int bufferLength, const int actingVersion)\n "  +
10721083 " {\n "  +
1073-  " if (SBE_BOUNDS_CHECK_EXPECT((offset > (bufferLength - %2$s)), 0 ))\n "  +
1084+  " if (SBE_BOUNDS_CHECK_EXPECT((offset > (bufferLength - %2$s)), false ))\n "  +
10741085 " {\n "  +
10751086 " throw std::runtime_error(\" buffer too short for flyweight [E107]\" );\n "  +
10761087 " }\n "  +
10771088 " buffer_ = buffer;\n "  +
10781089 " offset_ = offset;\n "  +
10791090 " actingVersion_ = actingVersion;\n "  +
1091+  " }\n \n "  +
1092+  "public:\n "  +
1093+  " %1$s(void) : buffer_(NULL), offset_(0) {}\n \n "  +
1094+  " %1$s(char *buffer, const int bufferLength, const int actingVersion)\n "  +
1095+  " {\n "  +
1096+  " reset(buffer, 0, bufferLength, actingVersion);\n "  +
1097+  " }\n \n "  +
1098+  " %1$s(const %1$s& codec) :\n "  +
1099+  " buffer_(codec.buffer_), offset_(codec.offset_), actingVersion_(codec.actingVersion_) {}\n \n "  +
1100+  "#if __cplusplus >= 201103L\n "  +
1101+  " %1$s(%1$s&& codec) = default;\n "  +
1102+  " %1$s& operator=(const %1$s&& codec) = default;\n "  +
1103+  "#endif\n \n "  +
1104+  " %1$s& operator=(const %1$s& codec)\n "  +
1105+  " {\n "  +
1106+  " buffer_ = codec.buffer_;\n "  +
1107+  " offset_ = codec.offset_;\n "  +
1108+  " actingVersion_ = codec.actingVersion_;\n "  +
1109+  " return *this;\n "  +
1110+  " }\n \n "  +
1111+  " %1$s &wrap(char *buffer, const int offset, const int actingVersion, const int bufferLength)\n "  +
1112+  " {\n "  +
1113+  " reset(buffer, offset, bufferLength, actingVersion);\n "  +
10801114 " return *this;\n "  +
10811115 " }\n \n "  +
10821116 " static const int size(void)\n "  +
@@ -1088,6 +1122,43 @@ private CharSequence generateFixedFlyweightCode(final String className, final in
10881122 );
10891123 }
10901124
1125+  private  CharSequence  generateConstructorsAndOperators (final  String  className )
1126+  {
1127+  return  String .format (
1128+  " %1$s(void) : buffer_(NULL), bufferLength_(0), offset_(0) {}\n \n "  +
1129+  " %1$s(char *buffer, const int bufferLength, const int actingBlockLength, const int actingVersion)\n "  +
1130+  " {\n "  +
1131+  " reset(buffer, 0, bufferLength, actingBlockLength, actingVersion);\n "  +
1132+  " }\n \n "  +
1133+  " %1$s(const %1$s& codec)\n "  +
1134+  " {\n "  +
1135+  " reset(codec.buffer_, codec.offset_, codec.bufferLength_, codec.actingBlockLength_,"  +
1136+  " codec.actingVersion_);\n "  +
1137+  " }\n \n "  +
1138+  "#if __cplusplus >= 201103L\n "  +
1139+  " %1$s(%1$s&& codec)\n "  +
1140+  " {\n "  +
1141+  " reset(codec.buffer_, codec.offset_, codec.bufferLength_, codec.actingBlockLength_,"  +
1142+  " codec.actingVersion_);\n "  +
1143+  " }\n \n "  +
1144+  " %1$s& operator=(const %1$s&& codec)\n "  +
1145+  " {\n "  +
1146+  " reset(codec.buffer_, codec.offset_, codec.bufferLength_, codec.actingBlockLength_,"  +
1147+  " codec.actingVersion_);\n "  +
1148+  " return *this;\n "  +
1149+  " }\n \n "  +
1150+  "#endif\n \n "  +
1151+  " %1$s& operator=(const %1$s& codec)\n "  +
1152+  " {\n "  +
1153+  " reset(codec.buffer_, codec.offset_, codec.bufferLength_, codec.actingBlockLength_,"  +
1154+  " codec.actingVersion_);\n "  +
1155+  " return *this;\n "  +
1156+  " }\n \n "  +
1157+  "" ,
1158+  className 
1159+  );
1160+  }
1161+ 
10911162 private  CharSequence  generateMessageFlyweightCode (final  String  className , final  Token  token )
10921163 {
10931164 final  String  blockLengthType  = cpp98TypeName (ir .headerStructure ().blockLengthType ());
@@ -1105,9 +1176,19 @@ private CharSequence generateMessageFlyweightCode(final String className, final
11051176 " int position_;\n "  +
11061177 " int actingBlockLength_;\n "  +
11071178 " int actingVersion_;\n \n "  +
1108-  " %10$s(const %10$s&) {}\n \n "  +
1179+  " inline void reset(char *buffer, const int offset, const int bufferLength, const int actingBlockLength,"  +
1180+  " const int actingVersion)\n "  +
1181+  " {\n "  +
1182+  " buffer_ = buffer;\n "  +
1183+  " offset_ = offset;\n "  +
1184+  " bufferLength_ = bufferLength;\n "  +
1185+  " actingBlockLength_ = actingBlockLength;\n "  +
1186+  " actingVersion_ = actingVersion;\n "  +
1187+  " positionPtr_ = &position_;\n "  +
1188+  " position(offset + actingBlockLength_);\n "  +
1189+  " }\n \n "  +
11091190 "public:\n \n "  +
1110-  " %10$s(void) : buffer_(NULL), bufferLength_(0), offset_(0) {} \n \n "  +
1191+  "%11$s "  +
11111192 " static const %1$s sbeBlockLength(void)\n "  +
11121193 " {\n "  +
11131194 " return %2$s;\n "  +
@@ -1134,25 +1215,13 @@ private CharSequence generateMessageFlyweightCode(final String className, final
11341215 " }\n \n "  +
11351216 " %10$s &wrapForEncode(char *buffer, const int offset, const int bufferLength)\n "  +
11361217 " {\n "  +
1137-  " buffer_ = buffer;\n "  +
1138-  " offset_ = offset;\n "  +
1139-  " bufferLength_ = bufferLength;\n "  +
1140-  " actingBlockLength_ = sbeBlockLength();\n "  +
1141-  " actingVersion_ = sbeSchemaVersion();\n "  +
1142-  " position(offset + actingBlockLength_);\n "  +
1143-  " positionPtr_ = &position_;\n "  +
1218+  " reset(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());\n "  +
11441219 " return *this;\n "  +
11451220 " }\n \n "  +
1146-  " %10$s &wrapForDecode(char *buffer, const int offset, const int actingBlockLength, const int actingVersion,\n "  +
1147-  "   const int bufferLength)\n "  +
1221+  " %10$s &wrapForDecode(char *buffer, const int offset, const int actingBlockLength, const int actingVersion,"  +
1222+  " const int bufferLength)\n "  +
11481223 " {\n "  +
1149-  " buffer_ = buffer;\n "  +
1150-  " offset_ = offset;\n "  +
1151-  " bufferLength_ = bufferLength;\n "  +
1152-  " actingBlockLength_ = actingBlockLength;\n "  +
1153-  " actingVersion_ = actingVersion;\n "  +
1154-  " positionPtr_ = &position_;\n "  +
1155-  " position(offset + actingBlockLength_);\n "  +
1224+  " reset(buffer, offset, bufferLength, actingBlockLength, actingVersion);\n "  +
11561225 " return *this;\n "  +
11571226 " }\n \n "  +
11581227 " sbe_uint64_t position(void) const\n "  +
@@ -1161,7 +1230,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final
11611230 " }\n \n "  +
11621231 " void position(const int position)\n "  +
11631232 " {\n "  +
1164-  " if (SBE_BOUNDS_CHECK_EXPECT((position > bufferLength_), 0 ))\n "  +
1233+  " if (SBE_BOUNDS_CHECK_EXPECT((position > bufferLength_), false ))\n "  +
11651234 " {\n "  +
11661235 " throw std::runtime_error(\" buffer too short [E100]\" );\n "  +
11671236 " }\n "  +
@@ -1188,7 +1257,8 @@ private CharSequence generateMessageFlyweightCode(final String className, final
11881257 schemaVersionType ,
11891258 generateLiteral (ir .headerStructure ().schemaVersionType (), Integer .toString (token .version ())),
11901259 semanticType ,
1191-  className 
1260+  className ,
1261+  generateConstructorsAndOperators (className )
11921262 );
11931263 }
11941264
0 commit comments