From 0c84dbeda1cde758a86a7daa9de9132bd00fd6a0 Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 11:46:05 +0900 Subject: [PATCH 1/6] [C++] Remove m_positionPtr from message flyweight. --- .../sbe/generation/cpp/CppGenerator.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index a8eab6e559..86dc150349 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -203,6 +203,10 @@ private static void generateGroupClassHeader( indent + " std::uint64_t m_offset;\n" + indent + " std::uint64_t m_actingVersion;\n" + indent + " %2$s m_dimensions;\n\n" + + indent + " std::uint64_t *sbePositionPtr() SBE_NOEXCEPT\n" + + indent + " {\n" + + indent + " return m_positionPtr;\n" + + indent + " }\n\n" + indent + "public:\n", formatClassName(groupName), dimensionsClassName)); @@ -346,7 +350,7 @@ private static CharSequence generateGroupProperty( sb.append(String.format("\n" + indent + " inline %1$s &%2$s()\n" + indent + " {\n" + - indent + " m_%2$s.wrapForDecode(m_buffer, m_positionPtr, m_actingVersion, m_bufferLength);\n" + + indent + " m_%2$s.wrapForDecode(m_buffer, sbePositionPtr(), m_actingVersion, m_bufferLength);\n" + indent + " return m_%2$s;\n" + indent + " }\n", className, @@ -356,7 +360,7 @@ private static CharSequence generateGroupProperty( indent + " %1$s &%2$sCount(const %3$s count)\n" + indent + " {\n" + indent + " m_%2$s.wrapForEncode(" + - "m_buffer, count, m_positionPtr, m_actingVersion, m_bufferLength);\n" + + "m_buffer, count, sbePositionPtr(), m_actingVersion, m_bufferLength);\n" + indent + " return m_%2$s;\n" + indent + " }\n", className, @@ -1625,7 +1629,6 @@ private CharSequence generateMessageFlyweightCode(final String className, final "private:\n" + " char *m_buffer = nullptr;\n" + " std::uint64_t m_bufferLength = 0;\n" + - " std::uint64_t *m_positionPtr;\n" + " std::uint64_t m_offset = 0;\n" + " std::uint64_t m_position;\n" + " std::uint64_t m_actingBlockLength;\n" + @@ -1639,7 +1642,6 @@ private CharSequence generateMessageFlyweightCode(final String className, final " m_bufferLength = bufferLength;\n" + " m_actingBlockLength = actingBlockLength;\n" + " m_actingVersion = actingVersion;\n" + - " m_positionPtr = &m_position;\n" + " sbePosition(offset + m_actingBlockLength);\n" + " }\n\n" + " inline void reset(const %10$s& codec) SBE_NOEXCEPT\n" + @@ -1649,9 +1651,12 @@ private CharSequence generateMessageFlyweightCode(final String className, final " m_bufferLength = codec.m_bufferLength;\n" + " m_actingBlockLength = codec.m_actingBlockLength;\n" + " m_actingVersion = codec.m_actingVersion;\n" + - " m_positionPtr = &m_position;\n" + " m_position = codec.m_position;\n" + " }\n\n" + + " inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT\n" + + " {\n" + + " return &m_position;\n" + + " }\n\n" + "public:\n\n" + " enum MetaAttribute\n" + " {\n" + From cc72b2e3b47e5de5ccebd0aff769b2d25a2403ca Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 12:06:24 +0900 Subject: [PATCH 2/6] [C++] Remove spurious spacing. --- .../java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 86dc150349..f536b7b258 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -1702,7 +1702,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final " reset(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());\n" + " return *this;\n" + " }\n\n" + - " %10$s &wrapAndApplyHeader( " + + " %10$s &wrapAndApplyHeader(" + "char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)\n" + " {\n" + " MessageHeader hdr(buffer + offset, bufferLength, sbeSchemaVersion());\n\n" + From 52bd1260c439d7b5b70c29d5c136fb905b90d9e9 Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 12:08:58 +0900 Subject: [PATCH 3/6] [C++] Split function arguments to separate lines. --- .../uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index f536b7b258..94629c66e7 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -1711,8 +1711,12 @@ private CharSequence generateMessageFlyweightCode(final String className, final " .templateId(sbeTemplateId())\n" + " .schemaId(sbeSchemaId())\n" + " .version(sbeSchemaVersion());\n\n" + - " reset(buffer + offset + MessageHeader::encodedLength(), 0, bufferLength, sbeBlockLength(), " + - "sbeSchemaVersion());\n" + + " reset(\n" + + " buffer + offset + MessageHeader::encodedLength(),\n" + + " 0,\n" + + " bufferLength,\n" + + " sbeBlockLength()\n," + + " sbeSchemaVersion());\n" + " return *this;\n" + " }\n\n" + " %10$s &wrapForDecode(\n" + From 7bf9edcd546f25ecb3f0b582848714d56233d5e1 Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 12:10:17 +0900 Subject: [PATCH 4/6] [C++] Fix call to reset in wrapAndApplyHeader(). The message flyweight should only see buffer length minus the encoded length of the message header. --- .../java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 94629c66e7..a74e19ff81 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -1714,7 +1714,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final " reset(\n" + " buffer + offset + MessageHeader::encodedLength(),\n" + " 0,\n" + - " bufferLength,\n" + + " bufferLength - MessageHeader::encodedLength(),\n" + " sbeBlockLength()\n," + " sbeSchemaVersion());\n" + " return *this;\n" + From 7097b58994bb5167579fb2f872f3baf893f70491 Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 15:42:30 +0900 Subject: [PATCH 5/6] [C++] Use initializer lists and remove reset methods. --- .../sbe/generation/cpp/CppGenerator.java | 113 ++++++++---------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index a74e19ff81..517de62bb6 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -273,13 +273,17 @@ private static void generateGroupClassHeader( indent + " {\n" + indent + " return *m_positionPtr;\n" + indent + " }\n\n" + - indent + " void sbePosition(const std::uint64_t position)\n" + + indent + " std::uint64_t sbeCheckPosition(const std::uint64_t position)\n" + indent + " {\n" + indent + " if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))\n" + indent + " {\n" + - indent + " throw std::runtime_error(\"buffer too short [E100]\");\n" + + indent + " throw std::runtime_error(\"buffer too short [E100]\");\n" + indent + " }\n" + - indent + " *m_positionPtr = position;\n" + + indent + " return position;\n" + + indent + " }\n\n" + + indent + " void sbePosition(const std::uint64_t position)\n" + + indent + " {\n" + + indent + " *m_positionPtr = sbeCheckPosition(position);\n" + indent + " }\n\n" + indent + " inline std::uint64_t count() const SBE_NOEXCEPT\n" + indent + " {\n" + @@ -1518,18 +1522,6 @@ private CharSequence generateFixedFlyweightCode(final String className, final in " std::uint64_t m_bufferLength;\n" + " std::uint64_t m_offset = 0;\n" + " std::uint64_t m_actingVersion;\n\n" + - " inline void reset(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength," + - " const std::uint64_t actingVersion)\n" + - " {\n" + - " if (SBE_BOUNDS_CHECK_EXPECT(((offset + %2$s) > bufferLength), false))\n" + - " {\n" + - " throw std::runtime_error(\"buffer too short for flyweight [E107]\");\n" + - " }\n\n" + - " m_buffer = buffer;\n" + - " m_bufferLength = bufferLength;\n" + - " m_offset = offset;\n" + - " m_actingVersion = actingVersion;\n" + - " }\n\n" + "public:\n" + " enum MetaAttribute\n" + " {\n" + @@ -1546,15 +1538,32 @@ private CharSequence generateFixedFlyweightCode(final String className, final in " std::uint64_t uint_value;\n" + " };\n\n" + " %1$s() = default;\n\n" + - " %1$s(char *buffer, const std::uint64_t bufferLength, const std::uint64_t actingVersion)\n" + + " %1$s(\n" + + " char *buffer,\n" + + " const std::uint64_t offset,\n" + + " const std::uint64_t bufferLength,\n" + + " const std::uint64_t actingVersion) :\n" + + " m_buffer(buffer),\n" + + " m_bufferLength(bufferLength),\n" + + " m_offset(offset),\n" + + " m_actingVersion(actingVersion)\n" + + " {\n" + + " if (SBE_BOUNDS_CHECK_EXPECT(((m_offset + %2$s) > m_bufferLength), false))\n" + + " {\n" + + " throw std::runtime_error(\"buffer too short for flyweight [E107]\");\n" + + " }\n" + + " }\n\n" + + " %1$s(\n" + + " char *buffer,\n" + + " const std::uint64_t bufferLength,\n" + + " const std::uint64_t actingVersion) :\n" + + " %1$s(buffer, 0, bufferLength, actingVersion)\n" + " {\n" + - " reset(buffer, 0, bufferLength, actingVersion);\n" + " }\n\n" + " %1$s &wrap(char *buffer, const std::uint64_t offset, const std::uint64_t actingVersion," + " const std::uint64_t bufferLength)\n" + " {\n" + - " reset(buffer, offset, bufferLength, actingVersion);\n" + - " return *this;\n" + + " return *this = %1$s(buffer, offset, bufferLength, actingVersion);\n" + " }\n\n" + " static SBE_CONSTEXPR std::uint64_t encodedLength() SBE_NOEXCEPT\n" + " {\n" + @@ -1596,23 +1605,27 @@ private static CharSequence generateConstructorsAndOperators(final String classN { return String.format( " %1$s() = default;\n\n" + - " %1$s(char *buffer, const std::uint64_t bufferLength)\n" + - " {\n" + - " reset(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion());\n" + - " }\n\n" + - " %1$s(char *buffer, const std::uint64_t bufferLength, const std::uint64_t actingBlockLength," + - " const std::uint64_t actingVersion)\n" + + " %1$s(\n" + + " char *buffer,\n" + + " const std::uint64_t offset,\n" + + " const std::uint64_t bufferLength,\n" + + " const std::uint64_t actingBlockLength,\n" + + " const std::uint64_t actingVersion) :\n" + + " m_buffer(buffer),\n" + + " m_bufferLength(bufferLength),\n" + + " m_offset(offset),\n" + + " m_position(sbeCheckPosition(offset + actingBlockLength)),\n" + + " m_actingVersion(actingVersion)\n" + " {\n" + - " reset(buffer, 0, bufferLength, actingBlockLength, actingVersion);\n" + " }\n\n" + - " %1$s(const %1$s& codec) SBE_NOEXCEPT\n" + + " %1$s(char *buffer, const std::uint64_t bufferLength) :\n" + + " %1$s(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion())\n" + " {\n" + - " reset(codec);\n" + " }\n\n" + - " %1$s& operator=(const %1$s& codec) SBE_NOEXCEPT\n" + + " %1$s(char *buffer, const std::uint64_t bufferLength, const std::uint64_t actingBlockLength," + + " const std::uint64_t actingVersion) :\n" + + " %1$s(buffer, 0, bufferLength, actingBlockLength, actingVersion)\n" + " {\n" + - " reset(codec);\n" + - " return *this;\n" + " }\n\n", className); } @@ -1631,28 +1644,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final " std::uint64_t m_bufferLength = 0;\n" + " std::uint64_t m_offset = 0;\n" + " std::uint64_t m_position;\n" + - " std::uint64_t m_actingBlockLength;\n" + " std::uint64_t m_actingVersion;\n\n" + - " inline void reset(\n" + - " char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength,\n" + - " const std::uint64_t actingBlockLength, const std::uint64_t actingVersion)\n" + - " {\n" + - " m_buffer = buffer;\n" + - " m_offset = offset;\n" + - " m_bufferLength = bufferLength;\n" + - " m_actingBlockLength = actingBlockLength;\n" + - " m_actingVersion = actingVersion;\n" + - " sbePosition(offset + m_actingBlockLength);\n" + - " }\n\n" + - " inline void reset(const %10$s& codec) SBE_NOEXCEPT\n" + - " {\n" + - " m_buffer = codec.m_buffer;\n" + - " m_offset = codec.m_offset;\n" + - " m_bufferLength = codec.m_bufferLength;\n" + - " m_actingBlockLength = codec.m_actingBlockLength;\n" + - " m_actingVersion = codec.m_actingVersion;\n" + - " m_position = codec.m_position;\n" + - " }\n\n" + " inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT\n" + " {\n" + " return &m_position;\n" + @@ -1699,8 +1691,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final " }\n\n" + " %10$s &wrapForEncode(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)\n" + " {\n" + - " reset(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());\n" + - " return *this;\n" + + " return *this = %10$s(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());\n" + " }\n\n" + " %10$s &wrapAndApplyHeader(" + "char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)\n" + @@ -1711,32 +1702,34 @@ private CharSequence generateMessageFlyweightCode(final String className, final " .templateId(sbeTemplateId())\n" + " .schemaId(sbeSchemaId())\n" + " .version(sbeSchemaVersion());\n\n" + - " reset(\n" + + " return *this = %10$s(\n" + " buffer + offset + MessageHeader::encodedLength(),\n" + " 0,\n" + " bufferLength - MessageHeader::encodedLength(),\n" + " sbeBlockLength()\n," + " sbeSchemaVersion());\n" + - " return *this;\n" + " }\n\n" + " %10$s &wrapForDecode(\n" + " char *buffer, const std::uint64_t offset, const std::uint64_t actingBlockLength,\n" + " const std::uint64_t actingVersion, const std::uint64_t bufferLength)\n" + " {\n" + - " reset(buffer, offset, bufferLength, actingBlockLength, actingVersion);\n" + - " return *this;\n" + + " return *this = %10$s(buffer, offset, bufferLength, actingBlockLength, actingVersion);\n" + " }\n\n" + " std::uint64_t sbePosition() const SBE_NOEXCEPT\n" + " {\n" + " return m_position;\n" + " }\n\n" + - " void sbePosition(const std::uint64_t position)\n" + + " std::uint64_t sbeCheckPosition(const std::uint64_t position)\n" + " {\n" + " if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))\n" + " {\n" + " throw std::runtime_error(\"buffer too short [E100]\");\n" + " }\n" + - " m_position = position;\n" + + " return position;\n" + + " }\n\n" + + " void sbePosition(const std::uint64_t position)\n" + + " {\n" + + " m_position = sbeCheckPosition(position);\n" + " }\n\n" + " std::uint64_t encodedLength() const SBE_NOEXCEPT\n" + " {\n" + From 12cdd1395df02c975be1b19e4160c3e6f9062954 Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Wed, 13 Mar 2019 17:40:46 +0900 Subject: [PATCH 6/6] [C++] Add a constructor overload to composites that uses default schema version. --- .../uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 517de62bb6..922cfb604f 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -1560,6 +1560,12 @@ private CharSequence generateFixedFlyweightCode(final String className, final in " %1$s(buffer, 0, bufferLength, actingVersion)\n" + " {\n" + " }\n\n" + + " %1$s(\n" + + " char *buffer,\n" + + " const std::uint64_t bufferLength) :\n" + + " %1$s(buffer, 0, bufferLength, sbeSchemaVersion())\n" + + " {\n" + + " }\n\n" + " %1$s &wrap(char *buffer, const std::uint64_t offset, const std::uint64_t actingVersion," + " const std::uint64_t bufferLength)\n" + " {\n" +