From 0bc12cc0c168b8944b1f31efbb05eb148a05ee5a Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 15 Jun 2020 13:55:23 +0200 Subject: [PATCH] Support optional ArrayProxy as function arguments --- VulkanHppGenerator.cpp | 52 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 0b2ec26..63e8e66 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -2745,43 +2745,37 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string bool withAllocator ) const { assert( param.type.postfix.back() == '*' ); - // it's optional, if it's marked as optional and there's no size specified bool optional = param.optional && !hasSizeParam; - if ( 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 ? " & " : ""); + + if ( useString ) { - // it's a char-vector -> use a std::string (either optional or a const-reference - if ( optional ) + // it's a char-vector -> use a std::string + assert( param.type.prefix.find( "const" ) != std::string::npos ); + str += optionalBegin + "const std::string" + optionalEnd + strippedParameterName; + if ( optional && withDefaults && !withAllocator ) { - str += "Optional " + strippedParameterName; - if ( withDefaults && !withAllocator ) - { - str += " = nullptr"; - } - } - else - { - str += "const std::string & " + strippedParameterName; + str += " = nullptr"; } } + else if ( singular ) + { + // in singular case, change from pointer to reference + assert( !optional ); // never encounterd such a case + str += param.type.prefix + ( param.type.prefix.empty() ? "" : " " ) + stripPrefix( param.type.type, "Vk" ) + " & " + + stripPluralS( strippedParameterName ); + } else { - // it's a non-char vector (they are never optional) - assert( !optional ); - if ( singular ) - { - // in singular case, change from pointer to reference - str += param.type.prefix + ( param.type.prefix.empty() ? "" : " " ) + stripPrefix( param.type.type, "Vk" ) + - " & " + stripPluralS( strippedParameterName ); - } - else - { - // otherwise, use our ArrayProxy - bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos ); - str += "ArrayProxy<" + - ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + - strippedParameterName; - } + // 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; } }