Add constructors for readonly structures (#153)

This commit is contained in:
Markus Tavenrath 2017-11-29 14:53:57 +01:00 committed by Andreas Süßenbach
parent 509a3df5bb
commit 1a32a6c072
2 changed files with 900 additions and 46 deletions

View File

@ -3604,6 +3604,8 @@ void writeStructConstructor( std::ostream & os, std::string const& name, StructD
// 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)
@ -3640,6 +3642,7 @@ void writeStructConstructor( std::ostream & os, std::string const& name, StructD
listedArgument = true; listedArgument = true;
} }
} }
}
os << " )" << std::endl; os << " )" << std::endl;
// copy over the simple arguments // copy over the simple arguments
@ -3667,10 +3670,17 @@ void writeStructConstructor( std::ostream & os, std::string const& name, StructD
value = nameIt->second; value = nameIt->second;
} }
else else
{
if (!structData.returnedOnly)
{ {
// the other elements are initialized by the corresponding argument (with trailing '_', as mentioned above) // the other elements are initialized by the corresponding argument (with trailing '_', as mentioned above)
value = structData.members[i].name + "_"; 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;
} }
@ -3678,6 +3688,8 @@ void writeStructConstructor( std::ostream & os, std::string const& name, StructD
// 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())
@ -3691,8 +3703,8 @@ void writeStructConstructor( std::ostream & os, std::string const& name, StructD
{ {"member", member}, {"arraySize", arraySize }, {"type", type} }); { {"member", member}, {"arraySize", arraySize }, {"type", type} });
} }
} }
os << " }" << std::endl }
<< std::endl; os << " }\n\n";
std::string templateString = std::string templateString =
R"( ${name}( Vk${name} const & rhs ) R"( ${name}( Vk${name} const & rhs )
@ -4344,11 +4356,7 @@ void writeTypeStruct( std::ostream & os, VkData const& vkData, DependencyData co
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, vkData.vkTypes, vkData.nameMap, defaultValues ); writeStructConstructor( os, dependencyData.name, it->second, vkData.vkTypes, vkData.nameMap, defaultValues );
}
// create the setters // create the setters
if (!it->second.returnedOnly) if (!it->second.returnedOnly)

File diff suppressed because it is too large Load Diff