private static CharSequence generateOnWrappedListener(final FieldPrecedenceModel fieldPrecedenceModel)
    {
        if (null == fieldPrecedenceModel)
        {
            return "";
        }

        if (fieldPrecedenceModel.versionCount() == 1)
        {
            return "";
        }

        final StringBuilder sb = new StringBuilder();
        sb.append(INDENT).append("void onWrapped(std::uint64_t actingVersion)\n")
            .append(INDENT).append("{\n");

        final MutableBoolean actingVersionCanBeTooLowToBeValid = new MutableBoolean(true);

        fieldPrecedenceModel.forEachWrappedStateByVersionDesc((version, state) ->
        {
            if (version == 0)
            {
                actingVersionCanBeTooLowToBeValid.set(false);

                sb.append(INDENT).append("    codecState(")
                    .append(qualifiedStateCase(state)).append(");\n");
            }
            else
            {
                sb.append(INDENT).append("    if (actingVersion >= ").append(version).append(")\n")
                    .append(INDENT).append("    {\n")
                    .append(INDENT).append("        codecState(")
                    .append(qualifiedStateCase(state)).append(");\n")
                    .append(INDENT).append("        return;\n")
                    .append(INDENT).append("    }\n\n");
            }
        });

        if (actingVersionCanBeTooLowToBeValid.get())
        {
            sb.append(INDENT)
                .append("    throw std::runtime_error(\"Unsupported acting version: \" + actingVersion);\n");
        }

        sb.append(INDENT).append("}\n\n");

        return sb;
    }
\n");
        sb.append("     * The states in which a encoder/decoder/codec can live.\n");
        sb.append("     *\n");
        sb.append("     * <p>The state machine diagram below, encoded in the dot language, describes\n");
        sb.append("     * the valid state transitions according to the order in which fields may be\n");
        sb.append("     * accessed safely. Tools such as PlantUML and Graphviz can render it.\n");
        sb.append("     *\n");
        sb.append("     * <pre>{@code\n");
        fieldPrecedenceModel.generateGraph(sb, "     *   ");
        sb.append("     * }</pre>\n");
        sb.append("
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java