Use memcmp instead of operator==() to compare unknown types from external headers, as they might not support that operator.

This commit is contained in:
asuessenbach 2020-06-16 10:05:22 +02:00
parent 6896223a3f
commit c6a48460e8
2 changed files with 28 additions and 10 deletions

View File

@ -2748,9 +2748,9 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string
// it's optional, if it's marked as optional and there's no size specified
bool optional = param.optional && !hasSizeParam;
bool useString = ( param.type.type.find( "char" ) != std::string::npos );
bool useString = ( param.type.type.find( "char" ) != std::string::npos );
std::string optionalBegin = optional ? "Optional<" : "";
std::string optionalEnd = optional ? "> " : (useString ? " & " : "");
std::string optionalEnd = optional ? "> " : ( useString ? " & " : "" );
if ( useString )
{
@ -2774,8 +2774,8 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string
// otherwise, use our ArrayProxy
bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos );
str += optionalBegin + "ArrayProxy<" +
( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + optionalEnd +
strippedParameterName;
( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " +
optionalEnd + strippedParameterName;
}
}
@ -3490,13 +3490,30 @@ ${prefix}}
void VulkanHppGenerator::appendStructCompareOperators( std::string & str,
std::pair<std::string, StructureData> const & structData ) const
{
static const std::set<std::string> simpleTypes = { "char", "double", "DWORD", "float", "HANDLE",
"HINSTANCE", "HMONITOR", "HWND", "int", "int8_t",
"int16_t", "int32_t", "int64_t", "LPCWSTR", "size_t",
"uint8_t", "uint16_t", "uint32_t", "uint64_t" };
// two structs are compared by comparing each of the elements
std::string compareMembers;
std::string intro = "";
for ( size_t i = 0; i < structData.second.members.size(); i++ )
{
MemberData const & member = structData.second.members[i];
compareMembers += intro + "( " + member.name + " == rhs." + member.name + " )";
auto typeIt = m_types.find( member.type.type );
assert( typeIt != m_types.end() );
if ( ( typeIt->second.category == TypeCategory::Requires ) && member.type.postfix.empty() &&
( simpleTypes.find( member.type.type ) == simpleTypes.end() ) )
{
// this type might support operator==()... that is, use memcmp
compareMembers +=
intro + "( memcmp( &" + member.name + ", &rhs." + member.name + ", sizeof( " + member.type.type + " ) ) == 0 )";
}
else
{
// for all others, we use the operator== of that type
compareMembers += intro + "( " + member.name + " == rhs." + member.name + " )";
}
intro = "\n && ";
}

View File

@ -49197,7 +49197,7 @@ namespace VULKAN_HPP_NAMESPACE
bool operator==( ImagePipeSurfaceCreateInfoFUCHSIA const & rhs ) const VULKAN_HPP_NOEXCEPT
{
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) &&
( imagePipeHandle == rhs.imagePipeHandle );
( memcmp( &imagePipeHandle, &rhs.imagePipeHandle, sizeof( zx_handle_t ) ) == 0 );
}
bool operator!=( ImagePipeSurfaceCreateInfoFUCHSIA const & rhs ) const VULKAN_HPP_NOEXCEPT
@ -70507,7 +70507,8 @@ namespace VULKAN_HPP_NAMESPACE
# else
bool operator==( PresentFrameTokenGGP const & rhs ) const VULKAN_HPP_NOEXCEPT
{
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( frameToken == rhs.frameToken );
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) &&
( memcmp( &frameToken, &rhs.frameToken, sizeof( GgpFrameToken ) ) == 0 );
}
bool operator!=( PresentFrameTokenGGP const & rhs ) const VULKAN_HPP_NOEXCEPT
@ -76134,7 +76135,7 @@ namespace VULKAN_HPP_NAMESPACE
bool operator==( StreamDescriptorSurfaceCreateInfoGGP const & rhs ) const VULKAN_HPP_NOEXCEPT
{
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) &&
( streamDescriptor == rhs.streamDescriptor );
( memcmp( &streamDescriptor, &rhs.streamDescriptor, sizeof( GgpStreamDescriptor ) ) == 0 );
}
bool operator!=( StreamDescriptorSurfaceCreateInfoGGP const & rhs ) const VULKAN_HPP_NOEXCEPT
@ -79316,7 +79317,7 @@ namespace VULKAN_HPP_NAMESPACE
bool operator==( XcbSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT
{
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) &&
( connection == rhs.connection ) && ( window == rhs.window );
( connection == rhs.connection ) && ( memcmp( &window, &rhs.window, sizeof( xcb_window_t ) ) == 0 );
}
bool operator!=( XcbSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT
@ -79414,7 +79415,7 @@ namespace VULKAN_HPP_NAMESPACE
bool operator==( XlibSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT
{
return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) && ( dpy == rhs.dpy ) &&
( window == rhs.window );
( memcmp( &window, &rhs.window, sizeof( Window ) ) == 0 );
}
bool operator!=( XlibSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT