Support arrays of enums in structures.

This commit is contained in:
asuessenbach 2020-03-10 09:47:59 +01:00 committed by Markus Tavenrath
parent 87cecae683
commit 434c0326f4
2 changed files with 28 additions and 7 deletions

View File

@ -1477,6 +1477,29 @@ void VulkanHppGenerator::appendEnums(std::string & str) const
}
}
void VulkanHppGenerator::appendEnumInitializer(std::string& str, TypeData const& type, std::vector<std::string> const& arraySizes, std::vector<EnumValueData> const& values) const
{
// enum arguments might need special initialization
assert(type.prefix.empty() && !values.empty());
std::string value = "VULKAN_HPP_NAMESPACE::" + stripPrefix(type.type, "Vk") + "::" + values.front().vkValue;
if (arraySizes.empty())
{
str += value;
}
else
{
assert(arraySizes.size() == 1);
int count = std::stoi(arraySizes[0]);
assert(1 < count);
str += "{ " + value;
for (int i = 1; i < count; i++)
{
str += ", " + value;
}
str += " }";
}
}
void VulkanHppGenerator::appendEnumToString(std::string & str, std::pair<std::string, EnumData> const& enumData) const
{
std::string enumName = stripPrefix(enumData.first, "Vk");
@ -2915,9 +2938,7 @@ bool VulkanHppGenerator::appendStructConstructorArgument(std::string & str, bool
auto enumIt = m_enums.find(memberData.type.type);
if (enumIt != m_enums.end() && memberData.type.postfix.empty())
{
// enum arguments might need special initialization
assert(memberData.type.prefix.empty() && memberData.arraySizes.empty() && !enumIt->second.values.empty());
str += "VULKAN_HPP_NAMESPACE::" + stripPrefix(memberData.type.type, "Vk") + "::" + enumIt->second.values.front().vkValue;
appendEnumInitializer(str, memberData.type, memberData.arraySizes, enumIt->second.values);
}
else
{
@ -2993,16 +3014,15 @@ void VulkanHppGenerator::appendStructMembers(std::string & str, std::pair<std::s
}
else
{
str += constructCArraySizes(member.arraySizes) + " = ";
auto enumIt = m_enums.find(member.type.type);
if (enumIt != m_enums.end() && member.type.postfix.empty())
{
// enum arguments might need special initialization
assert(member.type.prefix.empty() && member.arraySizes.empty() && !enumIt->second.values.empty());
str += " = VULKAN_HPP_NAMESPACE::" + stripPrefix(member.type.type, "Vk") + "::" + enumIt->second.values.front().vkValue;
appendEnumInitializer(str, member.type, member.arraySizes, enumIt->second.values);
}
else
{
str += constructCArraySizes(member.arraySizes) + " = {}";
str += "{}";
}
}
}

View File

@ -227,6 +227,7 @@ class VulkanHppGenerator
void appendCall(std::string &str, std::pair<std::string, CommandData> const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool firstCall, bool singular) const;
void appendCommand(std::string & str, std::string const& indentation, std::string const& name, std::pair<std::string, CommandData> const& commandData, bool definition) const;
void appendEnum(std::string & str, std::pair<std::string, EnumData> const& enumData) const;
void appendEnumInitializer(std::string& str, TypeData const& type, std::vector<std::string> const& arraySizes, std::vector<EnumValueData> const& values) const;
void appendEnumToString(std::string & str, std::pair<std::string, EnumData> const& enumData) const;
void appendFunction(std::string & str, std::string const& indentation, std::string const& name, std::pair<std::string, CommandData> const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, std::string const& enhancedReturnType, bool definition, bool enhanced, bool singular, bool unique, bool isStructureChain, bool withAllocator) const;
void appendFunctionBodyEnhanced(std::string & str, std::string const& indentation, std::string const& commandName, std::pair<std::string, CommandData> const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, std::string const& enhancedReturnType, bool singular, bool unique, bool isStructureChain, bool withAllocator) const;