|
15 | 15 | */ |
16 | 16 | package uk.co.real_logic.sbe.generation.cpp; |
17 | 17 |
|
| 18 | +import org.agrona.Strings; |
18 | 19 | import org.agrona.Verify; |
19 | 20 | import org.agrona.generation.OutputManager; |
20 | 21 | import uk.co.real_logic.sbe.PrimitiveType; |
@@ -2113,25 +2114,38 @@ private static void generateFieldMetaAttributeMethod( |
2113 | 2114 | final String timeUnit = encoding.timeUnit() == null ? "" : encoding.timeUnit(); |
2114 | 2115 | final String semanticType = encoding.semanticType() == null ? "" : encoding.semanticType(); |
2115 | 2116 |
|
2116 | | - new Formatter(sb).format("\n" + |
2117 | | - indent + " SBE_NODISCARD static const char * %sMetaAttribute(const MetaAttribute metaAttribute)" + |
2118 | | - " SBE_NOEXCEPT\n" + |
2119 | | - indent + " {\n" + |
2120 | | - indent + " switch (metaAttribute)\n" + |
2121 | | - indent + " {\n" + |
2122 | | - indent + " case MetaAttribute::EPOCH: return \"%s\";\n" + |
2123 | | - indent + " case MetaAttribute::TIME_UNIT: return \"%s\";\n" + |
2124 | | - indent + " case MetaAttribute::SEMANTIC_TYPE: return \"%s\";\n" + |
2125 | | - indent + " case MetaAttribute::PRESENCE: return \"%s\";\n" + |
2126 | | - indent + " }\n\n" + |
| 2117 | + sb.append("\n") |
| 2118 | + .append(indent).append(" SBE_NODISCARD static const char * ") |
| 2119 | + .append(token.name()).append("MetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT\n") |
| 2120 | + .append(indent).append(" {\n") |
| 2121 | + .append(indent).append(" switch (metaAttribute)\n") |
| 2122 | + .append(indent).append(" {\n"); |
2127 | 2123 |
|
2128 | | - indent + " return \"\";\n" + |
2129 | | - indent + " }\n", |
2130 | | - token.name(), |
2131 | | - epoch, |
2132 | | - timeUnit, |
2133 | | - semanticType, |
2134 | | - encoding.presence().toString().toLowerCase()); |
| 2124 | + if (!Strings.isEmpty(epoch)) |
| 2125 | + { |
| 2126 | + sb.append(indent) |
| 2127 | + .append(" case MetaAttribute::EPOCH: return \"").append(epoch).append("\";\n"); |
| 2128 | + } |
| 2129 | + |
| 2130 | + if (!Strings.isEmpty(timeUnit)) |
| 2131 | + { |
| 2132 | + sb.append(indent) |
| 2133 | + .append(" case MetaAttribute::TIME_UNIT: return \"").append(timeUnit).append("\";\n"); |
| 2134 | + } |
| 2135 | + |
| 2136 | + if (!Strings.isEmpty(semanticType)) |
| 2137 | + { |
| 2138 | + sb.append(indent) |
| 2139 | + .append(" case MetaAttribute::SEMANTIC_TYPE: return \"").append(semanticType) |
| 2140 | + .append("\";\n"); |
| 2141 | + } |
| 2142 | + |
| 2143 | + sb |
| 2144 | + .append(indent).append(" case MetaAttribute::PRESENCE: return \"") |
| 2145 | + .append(encoding.presence().toString().toLowerCase()).append("\";\n") |
| 2146 | + .append(indent).append(" default: return \"\";\n") |
| 2147 | + .append(indent).append(" }\n") |
| 2148 | + .append(indent).append(" }\n"); |
2135 | 2149 | } |
2136 | 2150 |
|
2137 | 2151 | private static CharSequence generateEnumFieldNotPresentCondition( |
|
0 commit comments