Skip to content

Commit a46d103

Browse files
committed
[C++] Add noexcept specifier
See #368
1 parent d311b1f commit a46d103

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ private static void generateGroupClassHeader(
251251
numInGroupToken.encoding().applicableMaxValue().longValue()));
252252

253253
sb.append(String.format(
254-
indent + " static SBE_CONSTEXPR std::uint64_t sbeHeaderSize()\n" +
254+
indent + " static SBE_CONSTEXPR std::uint64_t sbeHeaderSize() SBE_NOEXCEPT\n" +
255255
indent + " {\n" +
256256
indent + " return %1$d;\n" +
257257
indent + " }\n\n" +
258-
indent + " static SBE_CONSTEXPR std::uint64_t sbeBlockLength()\n" +
258+
indent + " static SBE_CONSTEXPR std::uint64_t sbeBlockLength() SBE_NOEXCEPT\n" +
259259
indent + " {\n" +
260260
indent + " return %2$d;\n" +
261261
indent + " }\n\n" +
@@ -271,11 +271,11 @@ private static void generateGroupClassHeader(
271271
indent + " }\n" +
272272
indent + " *m_positionPtr = position;\n" +
273273
indent + " }\n\n" +
274-
indent + " inline std::uint64_t count() const\n" +
274+
indent + " inline std::uint64_t count() const SBE_NOEXCEPT\n" +
275275
indent + " {\n" +
276276
indent + " return m_count;\n" +
277277
indent + " }\n\n" +
278-
indent + " inline bool hasNext() const\n" +
278+
indent + " inline bool hasNext() const SBE_NOEXCEPT\n" +
279279
indent + " {\n" +
280280
indent + " return m_index + 1 < m_count;\n" +
281281
indent + " }\n\n" +
@@ -331,7 +331,7 @@ private static CharSequence generateGroupProperty(
331331

332332
sb.append(String.format(
333333
"\n" +
334-
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId()\n" +
334+
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId() SBE_NOEXCEPT\n" +
335335
indent + " {\n" +
336336
indent + " return %2$d;\n" +
337337
indent + " }\n\n",
@@ -361,11 +361,11 @@ private static CharSequence generateGroupProperty(
361361
cppTypeForNumInGroup));
362362

363363
sb.append(String.format(
364-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion()\n" +
364+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion() SBE_NOEXCEPT\n" +
365365
indent + " {\n" +
366366
indent + " return %2$d;\n" +
367367
indent + " }\n\n" +
368-
indent + " bool %1$sInActingVersion()\n" +
368+
indent + " bool %1$sInActingVersion() SBE_NOEXCEPT\n" +
369369
indent + " {\n" +
370370
indent + "#if defined(__clang__)\n" +
371371
indent + "#pragma clang diagnostic push\n" +
@@ -516,19 +516,19 @@ private void generateVarDataDescriptors(
516516
{
517517
sb.append(String.format(
518518
"\n" +
519-
indent + " static const char *%1$sCharacterEncoding()\n" +
519+
indent + " static const char *%1$sCharacterEncoding() SBE_NOEXCEPT\n" +
520520
indent + " {\n" +
521521
indent + " return \"%2$s\";\n" +
522522
indent + " }\n\n",
523523
toLowerFirstChar(propertyName),
524524
characterEncoding));
525525

526526
sb.append(String.format(
527-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion()\n" +
527+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion() SBE_NOEXCEPT\n" +
528528
indent + " {\n" +
529529
indent + " return %2$d;\n" +
530530
indent + " }\n\n" +
531-
indent + " bool %1$sInActingVersion()\n" +
531+
indent + " bool %1$sInActingVersion() SBE_NOEXCEPT\n" +
532532
indent + " {\n" +
533533
indent + "#if defined(__clang__)\n" +
534534
indent + "#pragma clang diagnostic push\n" +
@@ -539,7 +539,7 @@ private void generateVarDataDescriptors(
539539
indent + "#pragma clang diagnostic pop\n" +
540540
indent + "#endif\n" +
541541
indent + " }\n\n" +
542-
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId()\n" +
542+
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId() SBE_NOEXCEPT\n" +
543543
indent + " {\n" +
544544
indent + " return %3$d;\n" +
545545
indent + " }\n\n",
@@ -549,7 +549,7 @@ private void generateVarDataDescriptors(
549549

550550
sb.append(String.format(
551551
"\n" +
552-
indent + " static SBE_CONSTEXPR std::uint64_t %sHeaderLength()\n" +
552+
indent + " static SBE_CONSTEXPR std::uint64_t %sHeaderLength() SBE_NOEXCEPT\n" +
553553
indent + " {\n" +
554554
indent + " return %d;\n" +
555555
indent + " }\n",
@@ -844,8 +844,10 @@ private static CharSequence generateFileHeader(
844844
"#endif\n\n" +
845845
"#if __cplusplus >= 201103L\n" +
846846
"# define SBE_CONSTEXPR constexpr\n" +
847+
"# define SBE_NOEXCEPT noexcept\n" +
847848
"#else\n" +
848849
"# define SBE_CONSTEXPR\n" +
850+
"# define SBE_NOEXCEPT\n" +
849851
"#endif\n\n" +
850852
"#include <sbe/sbe.h>\n\n",
851853
String.join("_", namespaces).toUpperCase(),
@@ -964,7 +966,7 @@ private CharSequence generatePrimitiveFieldMetaData(
964966

965967
sb.append(String.format(
966968
"\n" +
967-
indent + " static SBE_CONSTEXPR %1$s %2$sNullValue()\n" +
969+
indent + " static SBE_CONSTEXPR %1$s %2$sNullValue() SBE_NOEXCEPT\n" +
968970
indent + " {\n" +
969971
indent + " return %3$s;\n" +
970972
indent + " }\n",
@@ -974,7 +976,7 @@ private CharSequence generatePrimitiveFieldMetaData(
974976

975977
sb.append(String.format(
976978
"\n" +
977-
indent + " static SBE_CONSTEXPR %1$s %2$sMinValue()\n" +
979+
indent + " static SBE_CONSTEXPR %1$s %2$sMinValue() SBE_NOEXCEPT\n" +
978980
indent + " {\n" +
979981
indent + " return %3$s;\n" +
980982
indent + " }\n",
@@ -984,7 +986,7 @@ private CharSequence generatePrimitiveFieldMetaData(
984986

985987
sb.append(String.format(
986988
"\n" +
987-
indent + " static SBE_CONSTEXPR %1$s %2$sMaxValue()\n" +
989+
indent + " static SBE_CONSTEXPR %1$s %2$sMaxValue() SBE_NOEXCEPT\n" +
988990
indent + " {\n" +
989991
indent + " return %3$s;\n" +
990992
indent + " }\n",
@@ -994,7 +996,7 @@ private CharSequence generatePrimitiveFieldMetaData(
994996

995997
sb.append(String.format(
996998
"\n" +
997-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength()\n" +
999+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" +
9981000
indent + " {\n" +
9991001
indent + " return %2$d;\n" +
10001002
indent + " }\n",
@@ -1049,7 +1051,7 @@ private CharSequence generateArrayProperty(
10491051

10501052
sb.append(String.format(
10511053
"\n" +
1052-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sLength()\n" +
1054+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sLength() SBE_NOEXCEPT\n" +
10531055
indent + " {\n" +
10541056
indent + " return %2$d;\n" +
10551057
indent + " }\n\n",
@@ -1165,7 +1167,7 @@ private CharSequence generateConstPropertyMethods(
11651167
{
11661168
return String.format(
11671169
"\n" +
1168-
indent + " static SBE_CONSTEXPR %1$s %2$s()\n" +
1170+
indent + " static SBE_CONSTEXPR %1$s %2$s() SBE_NOEXCEPT\n" +
11691171
indent + " {\n" +
11701172
indent + " return %3$s;\n" +
11711173
indent + " }\n",
@@ -1190,7 +1192,7 @@ private CharSequence generateConstPropertyMethods(
11901192

11911193
sb.append(String.format(
11921194
"\n" +
1193-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sLength()\n" +
1195+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sLength() SBE_NOEXCEPT\n" +
11941196
indent + " {\n" +
11951197
indent + " return %2$d;\n" +
11961198
indent + " }\n\n",
@@ -1263,7 +1265,7 @@ private static CharSequence generateFixedFlyweightCode(final String className, f
12631265
"#if __cplusplus >= 201103L\n" +
12641266
" %1$s(%1$s&& codec) :\n" +
12651267
" m_buffer(codec.m_buffer), m_offset(codec.m_offset), m_actingVersion(codec.m_actingVersion){}\n\n" +
1266-
" %1$s& operator=(%1$s&& codec)\n" +
1268+
" %1$s& operator=(%1$s&& codec) SBE_NOEXCEPT\n" +
12671269
" {\n" +
12681270
" m_buffer = codec.m_buffer;\n" +
12691271
" m_bufferLength = codec.m_bufferLength;\n" +
@@ -1272,7 +1274,7 @@ private static CharSequence generateFixedFlyweightCode(final String className, f
12721274
" return *this;\n" +
12731275
" }\n\n" +
12741276
"#endif\n\n" +
1275-
" %1$s& operator=(const %1$s& codec)\n" +
1277+
" %1$s& operator=(const %1$s& codec) SBE_NOEXCEPT\n" +
12761278
" {\n" +
12771279
" m_buffer = codec.m_buffer;\n" +
12781280
" m_bufferLength = codec.m_bufferLength;\n" +
@@ -1286,15 +1288,15 @@ private static CharSequence generateFixedFlyweightCode(final String className, f
12861288
" reset(buffer, offset, bufferLength, actingVersion);\n" +
12871289
" return *this;\n" +
12881290
" }\n\n" +
1289-
" static SBE_CONSTEXPR std::uint64_t encodedLength()\n" +
1291+
" static SBE_CONSTEXPR std::uint64_t encodedLength() SBE_NOEXCEPT\n" +
12901292
" {\n" +
12911293
" return %2$s;\n" +
12921294
" }\n\n" +
1293-
" std::uint64_t offset() const\n" +
1295+
" std::uint64_t offset() const SBE_NOEXCEPT\n" +
12941296
" {\n" +
12951297
" return m_offset;\n" +
12961298
" }\n\n" +
1297-
" char *buffer()\n" +
1299+
" char *buffer() SBE_NOEXCEPT\n" +
12981300
" {\n" +
12991301
" return m_buffer;\n" +
13001302
" }\n\n",
@@ -1379,27 +1381,27 @@ private CharSequence generateMessageFlyweightCode(final String className, final
13791381
" }\n\n" +
13801382
"public:\n\n" +
13811383
"%11$s" +
1382-
" static SBE_CONSTEXPR %1$s sbeBlockLength()\n" +
1384+
" static SBE_CONSTEXPR %1$s sbeBlockLength() SBE_NOEXCEPT\n" +
13831385
" {\n" +
13841386
" return %2$s;\n" +
13851387
" }\n\n" +
1386-
" static SBE_CONSTEXPR %3$s sbeTemplateId()\n" +
1388+
" static SBE_CONSTEXPR %3$s sbeTemplateId() SBE_NOEXCEPT\n" +
13871389
" {\n" +
13881390
" return %4$s;\n" +
13891391
" }\n\n" +
1390-
" static SBE_CONSTEXPR %5$s sbeSchemaId()\n" +
1392+
" static SBE_CONSTEXPR %5$s sbeSchemaId() SBE_NOEXCEPT\n" +
13911393
" {\n" +
13921394
" return %6$s;\n" +
13931395
" }\n\n" +
1394-
" static SBE_CONSTEXPR %7$s sbeSchemaVersion()\n" +
1396+
" static SBE_CONSTEXPR %7$s sbeSchemaVersion() SBE_NOEXCEPT\n" +
13951397
" {\n" +
13961398
" return %8$s;\n" +
13971399
" }\n\n" +
1398-
" static SBE_CONSTEXPR const char * sbeSemanticType()\n" +
1400+
" static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT\n" +
13991401
" {\n" +
14001402
" return \"%9$s\";\n" +
14011403
" }\n\n" +
1402-
" std::uint64_t offset() const\n" +
1404+
" std::uint64_t offset() const SBE_NOEXCEPT\n" +
14031405
" {\n" +
14041406
" return m_offset;\n" +
14051407
" }\n\n" +
@@ -1415,7 +1417,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final
14151417
" reset(buffer, offset, bufferLength, actingBlockLength, actingVersion);\n" +
14161418
" return *this;\n" +
14171419
" }\n\n" +
1418-
" std::uint64_t position() const\n" +
1420+
" std::uint64_t position() const SBE_NOEXCEPT\n" +
14191421
" {\n" +
14201422
" return m_position;\n" +
14211423
" }\n\n" +
@@ -1427,15 +1429,15 @@ private CharSequence generateMessageFlyweightCode(final String className, final
14271429
" }\n" +
14281430
" m_position = position;\n" +
14291431
" }\n\n" +
1430-
" std::uint64_t encodedLength() const\n" +
1432+
" std::uint64_t encodedLength() const SBE_NOEXCEPT\n" +
14311433
" {\n" +
14321434
" return position() - m_offset;\n" +
14331435
" }\n\n" +
1434-
" char *buffer()\n" +
1436+
" char *buffer() SBE_NOEXCEPT\n" +
14351437
" {\n" +
14361438
" return m_buffer;\n" +
14371439
" }\n\n" +
1438-
" std::uint64_t actingVersion() const\n" +
1440+
" std::uint64_t actingVersion() const SBE_NOEXCEPT\n" +
14391441
" {\n" +
14401442
" return m_actingVersion;\n" +
14411443
" }\n",
@@ -1466,19 +1468,19 @@ private CharSequence generateFields(final String containingClassName, final List
14661468

14671469
sb.append(String.format(
14681470
"\n" +
1469-
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId()\n" +
1471+
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId() SBE_NOEXCEPT\n" +
14701472
indent + " {\n" +
14711473
indent + " return %2$d;\n" +
14721474
indent + " }\n\n",
14731475
propertyName,
14741476
signalToken.id()));
14751477

14761478
sb.append(String.format(
1477-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion()\n" +
1479+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion() SBE_NOEXCEPT\n" +
14781480
indent + " {\n" +
14791481
indent + " return %2$d;\n" +
14801482
indent + " }\n\n" +
1481-
indent + " bool %1$sInActingVersion()\n" +
1483+
indent + " bool %1$sInActingVersion() SBE_NOEXCEPT\n" +
14821484
indent + " {\n" +
14831485
indent + "#if defined(__clang__)\n" +
14841486
indent + "#pragma clang diagnostic push\n" +
@@ -1493,7 +1495,7 @@ private CharSequence generateFields(final String containingClassName, final List
14931495
signalToken.version()));
14941496

14951497
sb.append(String.format(
1496-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingOffset()\n" +
1498+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingOffset() SBE_NOEXCEPT\n" +
14971499
indent + " {\n" +
14981500
indent + " return %2$d;\n" +
14991501
indent + " }\n\n",
@@ -1538,7 +1540,8 @@ private static void generateFieldMetaAttributeMethod(
15381540

15391541
sb.append(String.format(
15401542
"\n" +
1541-
indent + " static const char *%sMetaAttribute(const MetaAttribute::Attribute metaAttribute)\n" +
1543+
indent + " static const char *%sMetaAttribute(const MetaAttribute::Attribute metaAttribute)" +
1544+
" SBE_NOEXCEPT\n" +
15421545
indent + " {\n" +
15431546
indent + " switch (metaAttribute)\n" +
15441547
indent + " {\n" +
@@ -1592,7 +1595,7 @@ private CharSequence generateEnumProperty(
15921595

15931596
sb.append(String.format(
15941597
"\n" +
1595-
indent + " %1$s::Value %2$s() const\n" +
1598+
indent + " %1$s::Value %2$s() const SBE_NOEXCEPT\n" +
15961599
indent + " {\n" +
15971600
"%3$s" +
15981601
indent + " return %1$s::Value::%4$s;\n" +
@@ -1632,7 +1635,7 @@ private CharSequence generateEnumProperty(
16321635
formatByteOrderEncoding(token.encoding().byteOrder(), token.encoding().primitiveType())));
16331636

16341637
sb.append(String.format(
1635-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength()\n" +
1638+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" +
16361639
indent + " {\n" +
16371640
indent + " return %2$d;\n" +
16381641
indent + " }\n",
@@ -1671,7 +1674,7 @@ private static Object generateBitsetProperty(final String propertyName, final To
16711674

16721675
sb.append(String.format(
16731676
"\n" +
1674-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength()\n" +
1677+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" +
16751678
indent + " {\n" +
16761679
indent + " return %2$d;\n" +
16771680
indent + " }\n",

0 commit comments

Comments
 (0)