Merge pull request #628 from asuessenbach/optional

Support optional ArrayProxy as function arguments
This commit is contained in:
Andreas Süßenbach 2020-06-15 14:15:11 +02:00 committed by GitHub
commit 6896223a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2745,44 +2745,38 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string
bool withAllocator ) const bool withAllocator ) const
{ {
assert( param.type.postfix.back() == '*' ); assert( param.type.postfix.back() == '*' );
// it's optional, if it's marked as optional and there's no size specified // it's optional, if it's marked as optional and there's no size specified
bool optional = param.optional && !hasSizeParam; 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 // it's a char-vector -> use a std::string
if ( optional ) assert( param.type.prefix.find( "const" ) != std::string::npos );
{ str += optionalBegin + "const std::string" + optionalEnd + strippedParameterName;
str += "Optional<const std::string> " + strippedParameterName; if ( optional && withDefaults && !withAllocator )
if ( withDefaults && !withAllocator )
{ {
str += " = nullptr"; str += " = nullptr";
} }
} }
else else if ( singular )
{
str += "const std::string & " + strippedParameterName;
}
}
else
{
// it's a non-char vector (they are never optional)
assert( !optional );
if ( singular )
{ {
// in singular case, change from pointer to reference // in singular case, change from pointer to reference
str += param.type.prefix + ( param.type.prefix.empty() ? "" : " " ) + stripPrefix( param.type.type, "Vk" ) + assert( !optional ); // never encounterd such a case
" & " + stripPluralS( strippedParameterName ); str += param.type.prefix + ( param.type.prefix.empty() ? "" : " " ) + stripPrefix( param.type.type, "Vk" ) + " & " +
stripPluralS( strippedParameterName );
} }
else else
{ {
// otherwise, use our ArrayProxy // otherwise, use our ArrayProxy
bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos ); bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos );
str += "ArrayProxy<" + str += optionalBegin + "ArrayProxy<" +
( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + optionalEnd +
strippedParameterName; strippedParameterName;
} }
}
} }
void VulkanHppGenerator::appendFunctionHeaderArguments( std::string & str, void VulkanHppGenerator::appendFunctionHeaderArguments( std::string & str,