Skip to content

Commit 0ff5e17

Browse files
authored
Merge pull request #480 from fracek/cpp-noexcept
[C++] Add noexcept specifier
2 parents 1d6bbbe + a46d103 commit 0ff5e17

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" +
@@ -1383,27 +1385,27 @@ private CharSequence generateMessageFlyweightCode(final String className, final
13831385
" }\n\n" +
13841386
"public:\n\n" +
13851387
"%11$s" +
1386-
" static SBE_CONSTEXPR %1$s sbeBlockLength()\n" +
1388+
" static SBE_CONSTEXPR %1$s sbeBlockLength() SBE_NOEXCEPT\n" +
13871389
" {\n" +
13881390
" return %2$s;\n" +
13891391
" }\n\n" +
1390-
" static SBE_CONSTEXPR %3$s sbeTemplateId()\n" +
1392+
" static SBE_CONSTEXPR %3$s sbeTemplateId() SBE_NOEXCEPT\n" +
13911393
" {\n" +
13921394
" return %4$s;\n" +
13931395
" }\n\n" +
1394-
" static SBE_CONSTEXPR %5$s sbeSchemaId()\n" +
1396+
" static SBE_CONSTEXPR %5$s sbeSchemaId() SBE_NOEXCEPT\n" +
13951397
" {\n" +
13961398
" return %6$s;\n" +
13971399
" }\n\n" +
1398-
" static SBE_CONSTEXPR %7$s sbeSchemaVersion()\n" +
1400+
" static SBE_CONSTEXPR %7$s sbeSchemaVersion() SBE_NOEXCEPT\n" +
13991401
" {\n" +
14001402
" return %8$s;\n" +
14011403
" }\n\n" +
1402-
" static SBE_CONSTEXPR const char * sbeSemanticType()\n" +
1404+
" static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT\n" +
14031405
" {\n" +
14041406
" return \"%9$s\";\n" +
14051407
" }\n\n" +
1406-
" std::uint64_t offset() const\n" +
1408+
" std::uint64_t offset() const SBE_NOEXCEPT\n" +
14071409
" {\n" +
14081410
" return m_offset;\n" +
14091411
" }\n\n" +
@@ -1419,7 +1421,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final
14191421
" reset(buffer, offset, bufferLength, actingBlockLength, actingVersion);\n" +
14201422
" return *this;\n" +
14211423
" }\n\n" +
1422-
" std::uint64_t position() const\n" +
1424+
" std::uint64_t position() const SBE_NOEXCEPT\n" +
14231425
" {\n" +
14241426
" return m_position;\n" +
14251427
" }\n\n" +
@@ -1431,15 +1433,15 @@ private CharSequence generateMessageFlyweightCode(final String className, final
14311433
" }\n" +
14321434
" m_position = position;\n" +
14331435
" }\n\n" +
1434-
" std::uint64_t encodedLength() const\n" +
1436+
" std::uint64_t encodedLength() const SBE_NOEXCEPT\n" +
14351437
" {\n" +
14361438
" return position() - m_offset;\n" +
14371439
" }\n\n" +
1438-
" char *buffer()\n" +
1440+
" char *buffer() SBE_NOEXCEPT\n" +
14391441
" {\n" +
14401442
" return m_buffer;\n" +
14411443
" }\n\n" +
1442-
" std::uint64_t actingVersion() const\n" +
1444+
" std::uint64_t actingVersion() const SBE_NOEXCEPT\n" +
14431445
" {\n" +
14441446
" return m_actingVersion;\n" +
14451447
" }\n",
@@ -1470,19 +1472,19 @@ private CharSequence generateFields(final String containingClassName, final List
14701472

14711473
sb.append(String.format(
14721474
"\n" +
1473-
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId()\n" +
1475+
indent + " static SBE_CONSTEXPR std::uint16_t %1$sId() SBE_NOEXCEPT\n" +
14741476
indent + " {\n" +
14751477
indent + " return %2$d;\n" +
14761478
indent + " }\n\n",
14771479
propertyName,
14781480
signalToken.id()));
14791481

14801482
sb.append(String.format(
1481-
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion()\n" +
1483+
indent + " static SBE_CONSTEXPR std::uint64_t %1$sSinceVersion() SBE_NOEXCEPT\n" +
14821484
indent + " {\n" +
14831485
indent + " return %2$d;\n" +
14841486
indent + " }\n\n" +
1485-
indent + " bool %1$sInActingVersion()\n" +
1487+
indent + " bool %1$sInActingVersion() SBE_NOEXCEPT\n" +
14861488
indent + " {\n" +
14871489
indent + "#if defined(__clang__)\n" +
14881490
indent + "#pragma clang diagnostic push\n" +
@@ -1497,7 +1499,7 @@ private CharSequence generateFields(final String containingClassName, final List
14971499
signalToken.version()));
14981500

14991501
sb.append(String.format(
1500-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingOffset()\n" +
1502+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingOffset() SBE_NOEXCEPT\n" +
15011503
indent + " {\n" +
15021504
indent + " return %2$d;\n" +
15031505
indent + " }\n\n",
@@ -1542,7 +1544,8 @@ private static void generateFieldMetaAttributeMethod(
15421544

15431545
sb.append(String.format(
15441546
"\n" +
1545-
indent + " static const char *%sMetaAttribute(const MetaAttribute::Attribute metaAttribute)\n" +
1547+
indent + " static const char *%sMetaAttribute(const MetaAttribute::Attribute metaAttribute)" +
1548+
" SBE_NOEXCEPT\n" +
15461549
indent + " {\n" +
15471550
indent + " switch (metaAttribute)\n" +
15481551
indent + " {\n" +
@@ -1596,7 +1599,7 @@ private CharSequence generateEnumProperty(
15961599

15971600
sb.append(String.format(
15981601
"\n" +
1599-
indent + " %1$s::Value %2$s() const\n" +
1602+
indent + " %1$s::Value %2$s() const SBE_NOEXCEPT\n" +
16001603
indent + " {\n" +
16011604
"%3$s" +
16021605
indent + " return %1$s::Value::%4$s;\n" +
@@ -1636,7 +1639,7 @@ private CharSequence generateEnumProperty(
16361639
formatByteOrderEncoding(token.encoding().byteOrder(), token.encoding().primitiveType())));
16371640

16381641
sb.append(String.format(
1639-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength()\n" +
1642+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" +
16401643
indent + " {\n" +
16411644
indent + " return %2$d;\n" +
16421645
indent + " }\n",
@@ -1675,7 +1678,7 @@ private static Object generateBitsetProperty(final String propertyName, final To
16751678

16761679
sb.append(String.format(
16771680
"\n" +
1678-
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength()\n" +
1681+
indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" +
16791682
indent + " {\n" +
16801683
indent + " return %2$d;\n" +
16811684
indent + " }\n",

0 commit comments

Comments
 (0)