From 0bdb0cdcabfdf0a970ae77ed686725c4d1892283 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 7 Jul 2021 10:36:13 +0200 Subject: [PATCH] Make functions returning a single value of type void (getting a void* as argument) a templated function. --- VulkanHppGenerator.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index c3c9948..a17a394 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3580,12 +3580,18 @@ std::string VulkanHppGenerator::constructCommandResultGetValue( std::string cons std::string returnBaseType = commandData.params[nonConstPointerIndex].type.compose(); assert( endsWith( returnBaseType, "*" ) ); returnBaseType.pop_back(); + std::string typenameT; + if ( returnBaseType == "void" ) + { + returnBaseType = "T"; + typenameT = "typename T, "; + } std::string returnType = constructReturnType( commandData, returnBaseType ); if ( definition ) { std::string const functionTemplate = - R"( template + R"( template <${typenameT}typename Dispatch> ${nodiscard}VULKAN_HPP_INLINE ${returnType} ${className}${classSeparator}${commandName}( ${argumentList} )${const} { ${returnBaseType} ${returnValueName}; @@ -3609,12 +3615,13 @@ std::string VulkanHppGenerator::constructCommandResultGetValue( std::string cons { "nodiscard", nodiscard }, { "returnType", returnType }, { "successCodeList", constructSuccessCodeList( commandData.successCodes ) }, + { "typenameT", typenameT }, { "vkCommand", name } } ); } else { std::string const functionTemplate = - R"( template + R"( template <${typenameT}typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> ${nodiscard}${returnType} ${commandName}( ${argumentList} )${const};)"; return replaceWithMap( functionTemplate, @@ -3622,7 +3629,8 @@ std::string VulkanHppGenerator::constructCommandResultGetValue( std::string cons { "commandName", commandName }, { "const", commandData.handle.empty() ? "" : " const" }, { "nodiscard", nodiscard }, - { "returnType", returnType } } ); + { "returnType", returnType }, + { "typenameT", typenameT } } ); } } @@ -7150,12 +7158,18 @@ std::string VulkanHppGenerator::constructRAIIHandleMemberFunctionResultSingleGet constructArgumentListEnhanced( commandIt->second.params, skippedParameters, {}, definition, false, false, false ); std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags ); std::string returnType = stripPostfix( commandIt->second.params[nonConstPointerParamIndices[0]].type.compose(), "*" ); + std::string typenameT; + if ( returnType == "void" ) + { + returnType = "T"; + typenameT = "template "; + } if ( definition ) { std::string const definitionTemplate = R"( - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE ${returnType} ${className}::${commandName}( ${argumentList} ) const + ${typenameT}VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE ${returnType} ${className}::${commandName}( ${argumentList} ) const {${functionPointerCheck} ${returnType} ${valueName}; VULKAN_HPP_NAMESPACE::Result result = static_cast( getDispatcher()->${vkCommand}( ${callArguments} ) ); @@ -7184,21 +7198,21 @@ std::string VulkanHppGenerator::constructRAIIHandleMemberFunctionResultSingleGet { "functionPointerCheck", constructFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) }, { "valueName", valueName }, { "returnType", returnType }, + { "typenameT", typenameT }, { "vkCommand", commandIt->first } } ); } else { std::string const declarationTemplate = R"( - VULKAN_HPP_NODISCARD ${returnType} ${commandName}( ${argumentList} ) const; + ${typenameT}VULKAN_HPP_NODISCARD ${returnType} ${commandName}( ${argumentList} ) const; )"; return replaceWithMap( declarationTemplate, - { - { "argumentList", argumentList }, + { { "argumentList", argumentList }, { "commandName", commandName }, { "returnType", returnType }, - } ); + { "typenameT", typenameT } } ); } }