mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Improve operator==() of structs (#472)
When a struct holds a fixed size array of stuff, and the member variable right before that array is the count (determined by its specific name) for that array, we now only compare that number of stuff. Resolves #456
This commit is contained in:
parent
0b3af1ee76
commit
4ee2d61ef6
@ -2531,8 +2531,9 @@ void VulkanHppGenerator::appendStructCompareOperators(std::string & str, std::pa
|
||||
// two structs are compared by comparing each of the elements
|
||||
std::string compareMembers;
|
||||
std::string intro = "";
|
||||
for (auto const& member : structData.second.members)
|
||||
for (size_t i = 0; i < structData.second.members.size(); i++)
|
||||
{
|
||||
MemberData const& member = structData.second.members[i];
|
||||
compareMembers += intro;
|
||||
if (member.arraySize.empty())
|
||||
{
|
||||
@ -2540,7 +2541,13 @@ void VulkanHppGenerator::appendStructCompareOperators(std::string & str, std::pa
|
||||
}
|
||||
else
|
||||
{
|
||||
compareMembers += "( memcmp( " + member.name + ", rhs." + member.name + ", " + member.arraySize + " * sizeof( " + member.type.compose() + " ) ) == 0 )";
|
||||
std::string arraySize = member.arraySize;
|
||||
if ((0 < i) && ((stripPostfix(member.name, "s") + "Count") == structData.second.members[i - 1].name))
|
||||
{
|
||||
assert(structData.second.members[i - 1].type.type == "uint32_t"); // make sure, it's an unsigned type, so we don't need to clamp here
|
||||
arraySize = "std::min<" + structData.second.members[i-1].type.type + ">( " + arraySize + ", " + structData.second.members[i - 1].name + " )";
|
||||
}
|
||||
compareMembers += "( memcmp( " + member.name + ", rhs." + member.name + ", " + arraySize + " * sizeof( " + member.type.compose() + " ) ) == 0 )";
|
||||
}
|
||||
intro = "\n && ";
|
||||
}
|
||||
|
@ -44202,7 +44202,7 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
return ( sType == rhs.sType )
|
||||
&& ( pNext == rhs.pNext )
|
||||
&& ( physicalDeviceCount == rhs.physicalDeviceCount )
|
||||
&& ( memcmp( physicalDevices, rhs.physicalDevices, VK_MAX_DEVICE_GROUP_SIZE * sizeof( VULKAN_HPP_NAMESPACE::PhysicalDevice ) ) == 0 )
|
||||
&& ( memcmp( physicalDevices, rhs.physicalDevices, std::min<uint32_t>( VK_MAX_DEVICE_GROUP_SIZE, physicalDeviceCount ) * sizeof( VULKAN_HPP_NAMESPACE::PhysicalDevice ) ) == 0 )
|
||||
&& ( subsetAllocation == rhs.subsetAllocation );
|
||||
}
|
||||
|
||||
@ -45757,9 +45757,9 @@ namespace VULKAN_HPP_NAMESPACE
|
||||
bool operator==( PhysicalDeviceMemoryProperties const& rhs ) const VULKAN_HPP_NOEXCEPT
|
||||
{
|
||||
return ( memoryTypeCount == rhs.memoryTypeCount )
|
||||
&& ( memcmp( memoryTypes, rhs.memoryTypes, VK_MAX_MEMORY_TYPES * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) ) == 0 )
|
||||
&& ( memcmp( memoryTypes, rhs.memoryTypes, std::min<uint32_t>( VK_MAX_MEMORY_TYPES, memoryTypeCount ) * sizeof( VULKAN_HPP_NAMESPACE::MemoryType ) ) == 0 )
|
||||
&& ( memoryHeapCount == rhs.memoryHeapCount )
|
||||
&& ( memcmp( memoryHeaps, rhs.memoryHeaps, VK_MAX_MEMORY_HEAPS * sizeof( VULKAN_HPP_NAMESPACE::MemoryHeap ) ) == 0 );
|
||||
&& ( memcmp( memoryHeaps, rhs.memoryHeaps, std::min<uint32_t>( VK_MAX_MEMORY_HEAPS, memoryHeapCount ) * sizeof( VULKAN_HPP_NAMESPACE::MemoryHeap ) ) == 0 );
|
||||
}
|
||||
|
||||
bool operator!=( PhysicalDeviceMemoryProperties const& rhs ) const VULKAN_HPP_NOEXCEPT
|
||||
|
Loading…
Reference in New Issue
Block a user