mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2025-09-12 05:16:21 -04:00
Optimize to_string
functions for enums (#2096)
* Optimize `to_string` functions for enums * Fix `-Wunused-parameter` warning
This commit is contained in:
parent
da9db0c8a0
commit
fe203f86d0
@ -2558,31 +2558,6 @@ std::string VulkanHppGenerator::generateBitmaskToString( std::map<std::string, B
|
|||||||
std::string enumName = stripPrefix( bitmaskBitsIt->first, "Vk" );
|
std::string enumName = stripPrefix( bitmaskBitsIt->first, "Vk" );
|
||||||
|
|
||||||
std::string str;
|
std::string str;
|
||||||
if ( bitmaskBitsIt->second.values.empty() ||
|
|
||||||
std::none_of( bitmaskBitsIt->second.values.begin(), bitmaskBitsIt->second.values.end(), []( auto const & evd ) { return evd.supported; } ) )
|
|
||||||
{
|
|
||||||
static std::string bitmaskToStringTemplate = R"(
|
|
||||||
VULKAN_HPP_INLINE std::string to_string( ${bitmaskName} )
|
|
||||||
{
|
|
||||||
return "{}";
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName } } );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
static const std::string bitmaskToStringTemplate = R"(
|
|
||||||
VULKAN_HPP_INLINE std::string to_string( ${bitmaskName} value )
|
|
||||||
{
|
|
||||||
if ( !value )
|
|
||||||
return "${emptyValue}";
|
|
||||||
|
|
||||||
std::string result;
|
|
||||||
${toStringChecks}
|
|
||||||
return "{ " + result.substr( 0, result.size() - 3 ) + " }";
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
std::string emptyValue = "{}";
|
std::string emptyValue = "{}";
|
||||||
std::string toStringChecks;
|
std::string toStringChecks;
|
||||||
std::string previousEnter, previousLeave;
|
std::string previousEnter, previousLeave;
|
||||||
@ -2613,6 +2588,30 @@ ${toStringChecks}
|
|||||||
previousLeave.resize( previousLeave.size() - strlen( "\n" ) );
|
previousLeave.resize( previousLeave.size() - strlen( "\n" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( toStringChecks.empty() )
|
||||||
|
{
|
||||||
|
static const std::string bitmaskToStringTemplate = R"(
|
||||||
|
VULKAN_HPP_INLINE std::string to_string( ${bitmaskName} )
|
||||||
|
{
|
||||||
|
return "${emptyValue}";
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName }, { "emptyValue", emptyValue } } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static const std::string bitmaskToStringTemplate = R"(
|
||||||
|
VULKAN_HPP_INLINE std::string to_string( ${bitmaskName} value )
|
||||||
|
{
|
||||||
|
std::string result = "{";
|
||||||
|
${toStringChecks}
|
||||||
|
if ( result.size() > 1 )
|
||||||
|
result.back() = '}';
|
||||||
|
else
|
||||||
|
result = "${emptyValue}";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
)";
|
||||||
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName }, { "emptyValue", emptyValue }, { "toStringChecks", toStringChecks } } );
|
str += replaceWithMap( bitmaskToStringTemplate, { { "bitmaskName", bitmaskName }, { "emptyValue", emptyValue }, { "toStringChecks", toStringChecks } } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user