Fix construction of multiple flags in to_string() functions. (#293)

Fix construction of multiple flags in to_string() functions based on Wunkolos proposal.
This commit is contained in:
Andreas Süßenbach
2019-02-25 10:46:51 +01:00
committed by Markus Tavenrath
parent efe676ab66
commit 018ebdd87f
2 changed files with 132 additions and 137 deletions

View File

@@ -660,24 +660,19 @@ void writeBitmaskToStringFunction(std::ostream & os, std::string const& bitmaskN
{
// 'or' together all the bits in the value
static const std::string caseTemplate = R"(
if ( value & ${typeName}::${value} ) result += "${valueString})";
if ( value & ${typeName}::${value} ) result += "${valueString} | ";)";
std::string casesString;
for (auto const& value : enumValues)
{
if (!casesString.empty())
{
casesString += " | \";";
}
casesString += replaceWithMap(caseTemplate, { { "typeName", enumName },{ "value", value.second },{ "valueString", value.second.substr(1) } });
}
casesString += "\";";
static const std::string bodyTemplate = R"(
if ( !value ) return "{}";
std::string result;
${cases}
return result;)";
return "{ " + result.substr(0, result.size() - 3) + " }";)";
functionBody = replaceWithMap(bodyTemplate, { { "cases", casesString } });
}