MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Hpp / generateStructCompareOperators

Method generateStructCompareOperators

generator/VideoHppGenerator.cpp:340–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338}
339
340std::string VideoHppGenerator::generateStructCompareOperators( std::pair<std::string, StructureData> const & structData ) const
341{
342 static std::set<std::string> const simpleTypes = { "char", "double", "DWORD", "float", "HANDLE", "HINSTANCE", "HMONITOR",
343 "HWND", "int", "int8_t", "int16_t", "int32_t", "int64_t", "LPCWSTR",
344 "size_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t" };
345
346 // two structs are compared by comparing each of the elements
347 std::string compareMembers;
348 std::string intro = "";
349 for ( size_t i = 0; i < structData.second.members.size(); i++ )
350 {
351 MemberData const & member = structData.second.members[i];
352 auto typeIt = m_types.find( member.type.name );
353 assert( typeIt != m_types.end() );
354 if ( ( typeIt->second.category == TypeCategory::ExternalType ) && member.type.postfix.empty() && !simpleTypes.contains( member.type.name ) )
355 {
356 // this type might support operator==() or operator<=>()... that is, use memcmp
357 compareMembers += intro + "( memcmp( &" + member.name + ", &rhs." + member.name + ", sizeof( " + member.type.name + " ) ) == 0 )";
358 }
359 else
360 {
361 assert( member.type.name != "char" );
362 // for all others, we use the operator== of that type
363 compareMembers += intro + "( " + member.name + " == rhs." + member.name + " )";
364 }
365 intro = "\n && ";
366 }
367
368 static std::string const compareTemplate = R"(
369 bool operator==( ${name} const & rhs ) const VULKAN_HPP_NOEXCEPT
370 {
371 return ${compareMembers};
372 }
373
374 bool operator!=( ${name} const & rhs ) const VULKAN_HPP_NOEXCEPT
375 {
376 return !operator==( rhs );
377 }
378)";
379
380 return replaceWithMap( compareTemplate, { { "name", stripPrefix( structData.first, "StdVideo" ) }, { "compareMembers", compareMembers } } );
381}
382
383std::string VideoHppGenerator::generateStructMembers( std::pair<std::string, StructureData> const & structData ) const
384{

Callers

nothing calls this directly

Calls 2

replaceWithMapFunction · 0.85
stripPrefixFunction · 0.85

Tested by

no test coverage detected