Skip to content

[c++] Improved field generation #631

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,17 @@ private CharSequence generateArrayProperty(
token.arrayLength()));

sb.append(String.format("\n" +
indent + " const char *%1$s() const\n" +
indent + " const char *%1$s() const SBE_NOEXCEPT\n" +
indent + " {\n" +
"%2$s" +
indent + " return (m_buffer + m_offset + %3$d);\n" +
indent + " }\n",
propertyName,
generateTypeFieldNotPresentCondition(token.version(), indent),
offset));

sb.append(String.format("\n" +
indent + " char *%1$s() SBE_NOEXCEPT\n" +
indent + " {\n" +
"%2$s" +
indent + " return (m_buffer + m_offset + %3$d);\n" +
Expand All @@ -1199,7 +1209,7 @@ private CharSequence generateArrayProperty(
indent);

sb.append(String.format("\n" +
indent + " %1$s %2$s(const std::uint64_t index) const\n" +
indent + " %1$s %2$s(std::uint64_t index) const\n" +
indent + " {\n" +
indent + " if (index >= %3$d)\n" +
indent + " {\n" +
Expand All @@ -1222,7 +1232,7 @@ private CharSequence generateArrayProperty(
indent);

sb.append(String.format("\n" +
indent + " %1$s %2$s(const std::uint64_t index, const %3$s value)\n" +
indent + " %1$s %2$s(std::uint64_t index, %3$s value)\n" +
indent + " {\n" +
indent + " if (index >= %4$d)\n" +
indent + " {\n" +
Expand All @@ -1238,7 +1248,7 @@ private CharSequence generateArrayProperty(
storeValue));

sb.append(String.format("\n" +
indent + " std::uint64_t get%1$s(char *dst, const std::uint64_t length) const\n" +
indent + " std::uint64_t get%1$s(char *dst, std::uint64_t length) const\n" +
indent + " {\n" +
indent + " if (length > %2$d)\n" +
indent + " {\n" +
Expand All @@ -1255,7 +1265,7 @@ private CharSequence generateArrayProperty(
cppTypeName));

sb.append(String.format("\n" +
indent + " %1$s &put%2$s(const char *src)\n" +
indent + " %1$s &put%2$s(const char *src) SBE_NOEXCEPT\n" +
indent + " {\n" +
indent + " std::memcpy(m_buffer + m_offset + %3$d, src, sizeof(%4$s) * %5$d);\n" +
indent + " return *this;\n" +
Expand All @@ -1279,11 +1289,31 @@ private CharSequence generateArrayProperty(
token.arrayLength()));

sb.append(String.format("\n" +
indent + " %1$s &put%2$s(const std::string& str)\n" +
indent + " #if __cplusplus >= 201703L\n" +
indent + " std::string_view get%1$sAsStringView() const SBE_NOEXCEPT\n" +
indent + " {\n" +
indent + " std::string_view result(m_buffer + m_offset + %2$d, %3$d);\n" +
indent + " return result;\n" +
indent + " }\n" +
indent + " #endif\n",
toUpperFirstChar(propertyName),
offset,
token.arrayLength()));

sb.append(String.format("\n" +
indent + " #if __cplusplus >= 201703L\n" +
indent + " %1$s &put%2$s(std::string_view str) SBE_NOEXCEPT\n" +
indent + " {\n" +
indent + " std::memcpy(m_buffer + m_offset + %3$d, str.c_str(), %4$d);\n" +
indent + " return *this;\n" +
indent + " }\n",
indent + " }\n" +
indent + " #else\n" +
indent + " %1$s &put%2$s(const std::string& str) SBE_NOEXCEPT\n" +
indent + " {\n" +
indent + " std::memcpy(m_buffer + m_offset + %3$d, str.c_str(), %4$d);\n" +
indent + " return *this;\n" +
indent + " }\n" +
indent + " #endif\n",
containingClassName,
toUpperFirstChar(propertyName),
offset,
Expand Down