Merge pull request #1257 from asuessenbach/constructor

Introduce copy constructor and assignment operator for vk::raii classes that hold handles without a destructor.
This commit is contained in:
Andreas Süßenbach
2022-03-23 08:17:47 +01:00
committed by GitHub
36 changed files with 96 additions and 56 deletions

View File

@@ -4887,7 +4887,7 @@ std::string VulkanHppGenerator::generateCommandSingle( std::string const &
}
else
{
std::string returnVariable;
std::string returnVariable;
if ( chained )
{
std::string dataDeclarationsTemplate = R"(${returnType} ${returnVariable};
@@ -6182,6 +6182,31 @@ std::string VulkanHppGenerator::generateRAIIHandle( std::pair<std::string, Handl
getParent += " }\n";
}
std::string assignmentOperator, copyConstructor;
if ( handle.second.destructorIt == m_commands.end() )
{
// allow copy constructor and assignment operator for classes without destructor
std::string const copyConstructorTemplate =
R"( ${handleType}( ${handleType} const & rhs ) : m_${handleName}( rhs.m_${handleName} ), m_dispatcher( rhs.m_dispatcher ) {})";
copyConstructor += replaceWithMap( copyConstructorTemplate, { { "handleName", handleName }, { "handleType", handleType } } );
std::string assignmentOperatorTemplate = R"( ${handleType} & operator=( ${handleType} const & rhs )
{
m_${handleName} = rhs.m_${handleName};
m_dispatcher = rhs.m_dispatcher;
return *this;
})";
assignmentOperator += replaceWithMap( assignmentOperatorTemplate, { { "handleName", handleName }, { "handleType", handleType } } );
}
else
{
std::string const copyConstructorTemplate = R"( ${handleType}( ${handleType} const & ) = delete;)";
copyConstructor += replaceWithMap( copyConstructorTemplate, { { "handleType", handleType } } );
std::string const assignmentOperatorTemplate = R"( ${handleType} & operator=( ${handleType} const & ) = delete;)";
assignmentOperator += replaceWithMap( assignmentOperatorTemplate, { { "handleType", handleType } } );
}
const std::string handleTemplate = R"(
${enter} class ${handleType}
{
@@ -6201,11 +6226,11 @@ ${singularConstructors}
}
${handleType}() = delete;
${handleType}( ${handleType} const & ) = delete;
${copyConstructor}
${handleType}( ${handleType} && rhs ) VULKAN_HPP_NOEXCEPT
: ${moveConstructorInitializerList}
{}
${handleType} & operator=( ${handleType} const & ) = delete;
${assignmentOperator}
${handleType} & operator=( ${handleType} && rhs ) VULKAN_HPP_NOEXCEPT
{
if ( this != &rhs )
@@ -6246,7 +6271,9 @@ ${memberFunctionsDeclarations}
${leave})";
str += replaceWithMap( handleTemplate,
{ { "clearMembers", clearMembers },
{ { "assignmentOperator", assignmentOperator },
{ "clearMembers", clearMembers },
{ "copyConstructor", copyConstructor },
{ "debugReportObjectType", debugReportObjectType },
{ "dispatcherType", dispatcherType },
{ "enter", enter },
@@ -12751,9 +12778,8 @@ void VulkanHppGenerator::readSPIRVCapabilitiesSPIRVCapabilityEnableProperty( int
}
if ( attribute.first == "requires" )
{
std::vector<std::string>
requires = tokenize( attribute.second, "," );
for ( auto const & r : requires )
std::vector<std::string> requiresAttribute = tokenize( attribute.second, "," );
for ( auto const & r : requiresAttribute )
{
check( ( m_features.find( r ) != m_features.end() ) || ( m_extensions.find( r ) != m_extensions.end() ),
xmlLine,
@@ -12800,9 +12826,8 @@ void VulkanHppGenerator::readSPIRVCapabilitiesSPIRVCapabilityEnableStruct( int x
{
if ( attribute.first == "requires" )
{
std::vector<std::string>
requires = tokenize( attribute.second, "," );
for ( auto const & r : requires )
std::vector<std::string> requiresAttribute = tokenize( attribute.second, "," );
for ( auto const & r : requiresAttribute )
{
check( ( m_features.find( r ) != m_features.end() ) || ( m_extensions.find( r ) != m_extensions.end() ),
xmlLine,