Merge pull request #728 from asuessenbach/assignment

Simplified assignment operator of structs
This commit is contained in:
Andreas Süßenbach 2020-09-01 11:13:17 +02:00 committed by GitHub
commit 33b7dc8167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2537 additions and 2412 deletions

View File

@ -3631,36 +3631,15 @@ ${prefix}{
${prefix} *this = *reinterpret_cast<VULKAN_HPP_NAMESPACE::${structName} const *>( &rhs ); ${prefix} *this = *reinterpret_cast<VULKAN_HPP_NAMESPACE::${structName} const *>( &rhs );
${prefix} return *this; ${prefix} return *this;
${prefix}} ${prefix}}
)";
str += replaceWithMap( assignmentFromVulkanType,
{ { "prefix", prefix }, { "structName", stripPrefix( structData.first, "Vk" ) } } );
// we need an assignment operator if there is constant member in this struct
if ( std::find_if( structData.second.members.begin(), structData.second.members.end(), []( MemberData const & md ) {
return md.values.size() == 1;
} ) != structData.second.members.end() )
{
std::string assignments;
for ( auto member : structData.second.members )
{
if ( member.values.size() != 1 )
{
assignments += prefix + member.name + " = rhs." + member.name + ";\n";
}
}
static const std::string assignmentTemplate = R"(
${prefix}${structName} & operator=( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT ${prefix}${structName} & operator=( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
${prefix}{ ${prefix}{
${assignments} ${prefix} memcpy( static_cast<void *>( this ), &rhs, sizeof( ${structName} ) );
${prefix} return *this; ${prefix} return *this;
${prefix}} ${prefix}}
)"; )";
str += replaceWithMap( assignmentTemplate, str += replaceWithMap( assignmentFromVulkanType,
{ { "assignments", assignments }, { { "prefix", prefix }, { "structName", stripPrefix( structData.first, "Vk" ) } } );
{ "prefix", prefix },
{ "structName", stripPrefix( structData.first, "Vk" ) } } );
}
} }
void VulkanHppGenerator::appendStructCompareOperators( std::string & str, void VulkanHppGenerator::appendStructCompareOperators( std::string & str,
@ -3750,6 +3729,8 @@ ${prefix}${constexpr}${structName}(${arguments}) VULKAN_HPP_NOEXCEPT
${prefix}${initializers} ${prefix}${initializers}
${prefix}{} ${prefix}{}
${prefix}${constexpr}${structName}( ${structName} const & rhs ) VULKAN_HPP_NOEXCEPT = default;
${prefix}${structName}( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT ${prefix}${structName}( Vk${structName} const & rhs ) VULKAN_HPP_NOEXCEPT
${prefix}{ ${prefix}{
${prefix} *this = rhs; ${prefix} *this = rhs;

File diff suppressed because it is too large Load Diff