Merge pull request #668 from asuessenbach/values

Add support of struct member attribute <values> to specify a default.
This commit is contained in:
Andreas Süßenbach 2020-07-10 11:48:34 +02:00 committed by GitHub
commit c2a9319aeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3688,7 +3688,7 @@ void VulkanHppGenerator::appendStructConstructorsEnhanced( std::string &
assert( ( litit->second.size() == 1 ) || !litit->second.front()->optional ); assert( ( litit->second.size() == 1 ) || !litit->second.front()->optional );
initializers += initializers +=
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit ) + " )"; ( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit ) + " )";
sizeChecks += generateSizeCheck( litit->second, stripPrefix(structData.first, "Vk"), prefix ); sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), prefix );
} }
else if ( std::find( memberIts.begin(), memberIts.end(), mit ) != memberIts.end() ) else if ( std::find( memberIts.begin(), memberIts.end(), mit ) != memberIts.end() )
{ {
@ -3770,6 +3770,10 @@ bool VulkanHppGenerator::appendStructConstructorArgument( std::string & str
{ {
appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values ); appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values );
} }
else if ( !memberData.values.empty() )
{
str += memberData.values;
}
else else
{ {
// all the rest can be initialized with just {} // all the rest can be initialized with just {}
@ -3850,6 +3854,10 @@ std::string VulkanHppGenerator::appendStructMembers( std::string &
{ {
appendEnumInitializer( str, member.type, member.arraySizes, enumIt->second.values ); appendEnumInitializer( str, member.type, member.arraySizes, enumIt->second.values );
} }
else if ( !member.values.empty() )
{
str += member.values;
}
else else
{ {
str += "{}"; str += "{}";
@ -4508,9 +4516,8 @@ void VulkanHppGenerator::checkCorrectness()
member.xmlLine, member.xmlLine,
"struct member array size uses unknown constant <" + member.usedConstant + ">" ); "struct member array size uses unknown constant <" + member.usedConstant + ">" );
} }
if ( !member.values.empty() ) if ( !member.values.empty() && ( member.name == "sType" ) )
{ {
assert( member.name == "sType" );
check( std::find_if( structureTypeIt->second.values.begin(), check( std::find_if( structureTypeIt->second.values.begin(),
structureTypeIt->second.values.end(), structureTypeIt->second.values.end(),
[&member]( auto const & evd ) { return member.values == evd.vulkanValue; } ) != [&member]( auto const & evd ) { return member.values == evd.vulkanValue; } ) !=
@ -6780,12 +6787,15 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
} }
else if ( attribute.first == "values" ) else if ( attribute.first == "values" )
{ {
check( memberData.name == "sType", check( tokenize( attribute.second, "," ).size() == 1,
line, line,
"Structure member named differently than <sType> with attribute <values> encountered: " ); "struct member <" + memberData.name + "> holds mulitple values <" + attribute.second + ">" );
if ( memberData.name == "sType" )
{
check( m_sTypeValues.insert( attribute.second ).second, check( m_sTypeValues.insert( attribute.second ).second,
line, line,
"<" + attribute.second + "> already encountered as values for the sType member of a struct" ); "<" + attribute.second + "> already encountered as values for the sType member of a struct" );
}
memberData.values = attribute.second; memberData.values = attribute.second;
} }
} }