mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Introduce operator==() and operator!=() on structs.
This commit is contained in:
parent
65a8e02601
commit
cd0335bd42
@ -497,6 +497,7 @@ struct StructData
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
bool returnedOnly;
|
bool returnedOnly;
|
||||||
|
bool isUnion;
|
||||||
std::vector<MemberData> members;
|
std::vector<MemberData> members;
|
||||||
std::string protect;
|
std::string protect;
|
||||||
};
|
};
|
||||||
@ -1429,6 +1430,7 @@ void readTypeStruct( tinyxml2::XMLElement * element, VkData & vkData )
|
|||||||
assert( vkData.structs.find( name ) == vkData.structs.end() );
|
assert( vkData.structs.find( name ) == vkData.structs.end() );
|
||||||
std::map<std::string,StructData>::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first;
|
std::map<std::string,StructData>::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first;
|
||||||
it->second.returnedOnly = !!element->Attribute( "returnedonly" );
|
it->second.returnedOnly = !!element->Attribute( "returnedonly" );
|
||||||
|
it->second.isUnion = false;
|
||||||
|
|
||||||
tinyxml2::XMLElement * child = element->FirstChildElement();
|
tinyxml2::XMLElement * child = element->FirstChildElement();
|
||||||
do
|
do
|
||||||
@ -1530,6 +1532,7 @@ void readTypeUnion( tinyxml2::XMLElement * element, VkData & vkData )
|
|||||||
|
|
||||||
assert( vkData.structs.find( name ) == vkData.structs.end() );
|
assert( vkData.structs.find( name ) == vkData.structs.end() );
|
||||||
std::map<std::string,StructData>::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first;
|
std::map<std::string,StructData>::iterator it = vkData.structs.insert( std::make_pair( name, StructData() ) ).first;
|
||||||
|
it->second.isUnion = true;
|
||||||
|
|
||||||
tinyxml2::XMLElement * child = element->FirstChildElement();
|
tinyxml2::XMLElement * child = element->FirstChildElement();
|
||||||
do
|
do
|
||||||
@ -2706,6 +2709,21 @@ void writeTypeScalar( std::ofstream & ofs, DependencyData const& dependencyData
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool containsUnion(std::string const& type, std::map<std::string, StructData> const& structs)
|
||||||
|
{
|
||||||
|
std::map<std::string, StructData>::const_iterator sit = structs.find(type);
|
||||||
|
bool found = (sit != structs.end());
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
found = sit->second.isUnion;
|
||||||
|
for (std::vector<MemberData>::const_iterator mit = sit->second.members.begin(); mit != sit->second.members.end() && !found; ++mit)
|
||||||
|
{
|
||||||
|
found = (mit->type == mit->pureType) && containsUnion(mit->type, structs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData const& dependencyData, std::map<std::string,std::string> const& defaultValues )
|
void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData const& dependencyData, std::map<std::string,std::string> const& defaultValues )
|
||||||
{
|
{
|
||||||
std::map<std::string,StructData>::const_iterator it = vkData.structs.find( dependencyData.name );
|
std::map<std::string,StructData>::const_iterator it = vkData.structs.find( dependencyData.name );
|
||||||
@ -2737,6 +2755,42 @@ void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData
|
|||||||
<< " }" << std::endl
|
<< " }" << std::endl
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
// operator==() and operator!=()
|
||||||
|
// only structs without a union as a member can have a meaningfull == and != operation; we filter them out
|
||||||
|
if (!containsUnion(dependencyData.name, vkData.structs))
|
||||||
|
{
|
||||||
|
ofs << " bool operator==( " << dependencyData.name << " const& rhs ) const" << std::endl
|
||||||
|
<< " {" << std::endl
|
||||||
|
<< " return ";
|
||||||
|
for (size_t i = 0; i < it->second.members.size(); i++)
|
||||||
|
{
|
||||||
|
if (i != 0)
|
||||||
|
{
|
||||||
|
ofs << std::endl << " && ";
|
||||||
|
}
|
||||||
|
if (!it->second.members[i].arraySize.empty())
|
||||||
|
{
|
||||||
|
ofs << "( memcmp( " << it->second.members[i].name << ", rhs." << it->second.members[i].name << ", " << it->second.members[i].arraySize << " * sizeof( " << it->second.members[i].type << " ) ) == 0 )";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ofs << "( " << it->second.members[i].name << " == rhs." << it->second.members[i].name << " )";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ofs << ";" << std::endl
|
||||||
|
<< " }" << std::endl
|
||||||
|
<< std::endl
|
||||||
|
<< " bool operator!=( " << dependencyData.name << " const& rhs ) const" << std::endl
|
||||||
|
<< " {" << std::endl
|
||||||
|
<< " return !operator==( rhs );" << std::endl
|
||||||
|
<< " }" << std::endl
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int a = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// the member variables
|
// the member variables
|
||||||
for (size_t i = 0; i < it->second.members.size(); i++)
|
for (size_t i = 0; i < it->second.members.size(); i++)
|
||||||
{
|
{
|
||||||
@ -2758,10 +2812,9 @@ void writeTypeStruct( std::ofstream & ofs, VkData const& vkData, DependencyData
|
|||||||
ofs << ";" << std::endl;
|
ofs << ";" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ofs << " };" << std::endl;
|
ofs << " };" << std::endl
|
||||||
#if 1
|
<< " static_assert( sizeof( " << dependencyData.name << " ) == sizeof( Vk" << dependencyData.name << " ), \"struct and wrapper have different size!\" );" << std::endl;
|
||||||
ofs << " static_assert( sizeof( " << dependencyData.name << " ) == sizeof( Vk" << dependencyData.name << " ), \"struct and wrapper have different size!\" );" << std::endl;
|
|
||||||
#endif
|
|
||||||
leaveProtect(ofs, it->second.protect);
|
leaveProtect(ofs, it->second.protect);
|
||||||
ofs << std::endl;
|
ofs << std::endl;
|
||||||
}
|
}
|
||||||
|
2021
vulkan/vulkan.hpp
2021
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user