Remove constructors for "returnedonly" structures; introduce member inialization for pNext and sType, instead. (#168)

This commit is contained in:
Andreas Süßenbach 2018-01-05 09:25:38 +01:00 committed by Markus Tavenrath
parent c4fcc08e95
commit c548ea4bf2
2 changed files with 628 additions and 1832 deletions

View File

@ -3954,8 +3954,6 @@ void VulkanHppGenerator::writeStructConstructor(std::ostream & os, std::string c
// the constructor with all the elements as arguments, with defaults // the constructor with all the elements as arguments, with defaults
os << " " << name << "( "; os << " " << name << "( ";
bool listedArgument = false; bool listedArgument = false;
if (!structData.returnedOnly)
{
for (size_t i = 0; i < structData.members.size(); i++) for (size_t i = 0; i < structData.members.size(); i++)
{ {
if (listedArgument) if (listedArgument)
@ -3992,45 +3990,21 @@ void VulkanHppGenerator::writeStructConstructor(std::ostream & os, std::string c
listedArgument = true; listedArgument = true;
} }
} }
}
os << " )" << std::endl; os << " )" << std::endl;
// copy over the simple arguments // copy over the simple arguments
bool firstArgument = true; bool firstArgument = true;
for (size_t i = 0; i < structData.members.size(); i++) for (size_t i = 0; i < structData.members.size(); i++)
{ {
if (structData.members[i].arraySize.empty()) // skip members 'pNext' and 'sType' are directly set by initializers
if ((structData.members[i].name != "pNext") && (structData.members[i].name != "sType") && (structData.members[i].arraySize.empty()))
{ {
// here, we can only handle non-array arguments // here, we can only handle non-array arguments
std::string templateString = " ${sep} ${member}( ${value} )\n"; std::string templateString = " ${sep} ${member}( ${value} )\n";
std::string sep = firstArgument ? ":" : ","; std::string sep = firstArgument ? ":" : ",";
std::string member = structData.members[i].name; std::string member = structData.members[i].name;
std::string value; std::string value = structData.members[i].name + "_"; // the elements are initialized by the corresponding argument (with trailing '_', as mentioned above)
// 'pNext' and 'sType' don't get an argument, use nullptr and the correct StructureType enum value to initialize them
if (structData.members[i].name == "pNext")
{
value = "nullptr";
}
else if (structData.members[i].name == "sType")
{
assert(!structData.members[i].values.empty());
auto nameIt = m_nameMap.find(structData.members[i].values);
assert(nameIt != m_nameMap.end());
value = nameIt->second;
}
else
{
if (!structData.returnedOnly)
{
// the other elements are initialized by the corresponding argument (with trailing '_', as mentioned above)
value = structData.members[i].name + "_";
}
else
{
templateString = "";
}
}
os << replaceWithMap(templateString, { { "sep", sep },{ "member", member },{ "value", value } }); os << replaceWithMap(templateString, { { "sep", sep },{ "member", member },{ "value", value } });
firstArgument = false; firstArgument = false;
} }
@ -4038,8 +4012,6 @@ void VulkanHppGenerator::writeStructConstructor(std::ostream & os, std::string c
// the body of the constructor, copying over data from argument list into wrapped struct // the body of the constructor, copying over data from argument list into wrapped struct
os << " {" << std::endl; os << " {" << std::endl;
if (!structData.returnedOnly)
{
for (size_t i = 0; i < structData.members.size(); i++) for (size_t i = 0; i < structData.members.size(); i++)
{ {
if (!structData.members[i].arraySize.empty()) if (!structData.members[i].arraySize.empty())
@ -4053,7 +4025,6 @@ void VulkanHppGenerator::writeStructConstructor(std::ostream & os, std::string c
{ { "member", member },{ "arraySize", arraySize },{ "type", type } }); { { "member", member },{ "arraySize", arraySize },{ "type", type } });
} }
} }
}
os << " }\n\n"; os << " }\n\n";
std::string templateString = std::string templateString =
@ -4536,7 +4507,11 @@ void VulkanHppGenerator::writeTypeStruct(std::ostream & os, DependencyData const
os << " struct " << dependencyData.name << std::endl os << " struct " << dependencyData.name << std::endl
<< " {" << std::endl; << " {" << std::endl;
// only structs that are not returnedOnly get a constructor!
if (!it->second.returnedOnly)
{
writeStructConstructor(os, dependencyData.name, it->second, defaultValues); writeStructConstructor(os, dependencyData.name, it->second, defaultValues);
}
// create the setters // create the setters
if (!it->second.returnedOnly) if (!it->second.returnedOnly)
@ -4593,15 +4568,22 @@ void VulkanHppGenerator::writeTypeStruct(std::ostream & os, DependencyData const
if (it->second.members[i].type == "StructureType") if (it->second.members[i].type == "StructureType")
{ {
assert((i == 0) && (it->second.members[i].name == "sType")); assert((i == 0) && (it->second.members[i].name == "sType"));
assert(!it->second.members[i].values.empty());
auto nameIt = m_nameMap.find(it->second.members[i].values);
assert(nameIt != m_nameMap.end());
os << " private:" << std::endl os << " private:" << std::endl
<< " StructureType sType;" << std::endl << " StructureType sType = " << nameIt->second << ";" << std::endl
<< std::endl << std::endl
<< " public:" << std::endl; << " public:" << std::endl;
} }
else else
{ {
os << " " << it->second.members[i].type << " " << it->second.members[i].name; os << " " << it->second.members[i].type << " " << it->second.members[i].name;
if (!it->second.members[i].arraySize.empty()) if (it->second.members[i].name == "pNext")
{
os << " = nullptr";
}
else if (!it->second.members[i].arraySize.empty())
{ {
os << "[" << it->second.members[i].arraySize << "]"; os << "[" << it->second.members[i].arraySize << "]";
} }

File diff suppressed because it is too large Load Diff