mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #21 from mtavenrath/getString
Add getString(VkEnum)/getString(VKFlags) support
This commit is contained in:
commit
ce702938a8
@ -109,6 +109,12 @@ vk::ImageCreateInfo ci(
|
|||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
# String conversions
|
||||||
|
|
||||||
|
At development time it can be quite handy to have a utility function that can convert an enum or flags to a string for debugging purposes. To achieve this,
|
||||||
|
we have implemented <code>getString(type)</code> functions for all enums and flags. Calling <code>getString(vk::SharingMode::eExclusive)</code> will return 'Exclusive' and calling
|
||||||
|
<code>getString(vk::QueueFlagBits::eGraphics | vk::QueueFlagBits::eCompute)</code> will return the concatenated string 'Graphics | Compute'.
|
||||||
|
|
||||||
# Alternative Initialization of Structs
|
# Alternative Initialization of Structs
|
||||||
|
|
||||||
Another nice feature of those constructors is that sType is being initialized internally and thus is always correct.
|
Another nice feature of those constructors is that sType is being initialized internally and thus is always correct.
|
||||||
|
@ -1655,6 +1655,55 @@ void writeTypeEnum( std::ofstream & ofs, DependencyData const& dependencyData, E
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeEnumToString(std::ofstream & ofs, DependencyData const& dependencyData, EnumData const& enumData)
|
||||||
|
{
|
||||||
|
ofs << " static const char * getString(" << dependencyData.name << " value)" << std::endl
|
||||||
|
<< " {" << std::endl
|
||||||
|
<< " switch (value)" << std::endl
|
||||||
|
<< " {" << std::endl;
|
||||||
|
for (auto itMember = enumData.members.begin(); itMember != enumData.members.end(); ++itMember)
|
||||||
|
{
|
||||||
|
ofs << " case " << dependencyData.name << "::" << itMember->name << ": return \"" << itMember->name.substr(1) << "\";" << std::endl;
|
||||||
|
}
|
||||||
|
ofs << " default: return \"unknown\";" << std::endl
|
||||||
|
<< " }" << std::endl
|
||||||
|
<< " }" << std::endl
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeFlagsTostring(std::ofstream & ofs, DependencyData const& dependencyData, EnumData const &enumData)
|
||||||
|
{
|
||||||
|
std::string enumPrefix = "vk::" + *dependencyData.dependencies.begin() + "::";
|
||||||
|
ofs << " static std::string getString(" << dependencyData.name << " value)" << std::endl
|
||||||
|
<< " {" << std::endl
|
||||||
|
<< " if (!value) return std::string();" << std::endl
|
||||||
|
<< " std::string result;" << std::endl;
|
||||||
|
|
||||||
|
for (auto itMember = enumData.members.begin(); itMember != enumData.members.end(); ++itMember)
|
||||||
|
{
|
||||||
|
ofs << " if (value & " << enumPrefix + itMember->name << ") result += \"" << itMember->name.substr(1) << " | \";" << std::endl;
|
||||||
|
}
|
||||||
|
ofs << " return result.substr(0, result.size() - 3);" << std::endl
|
||||||
|
<< " }" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeEnumsToString(std::ofstream & ofs, std::vector<DependencyData> const& dependencyData, std::map<std::string, EnumData> const& enums)
|
||||||
|
{
|
||||||
|
for (auto it = dependencyData.begin(); it != dependencyData.end(); ++it)
|
||||||
|
{
|
||||||
|
switch (it->category)
|
||||||
|
{
|
||||||
|
case DependencyData::Category::ENUM:
|
||||||
|
assert(enums.find(it->name) != enums.end());
|
||||||
|
writeEnumToString(ofs, *it, enums.find(it->name)->second);
|
||||||
|
break;
|
||||||
|
case DependencyData::Category::FLAGS:
|
||||||
|
writeFlagsTostring(ofs, *it, enums.find(*it->dependencies.begin())->second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void writeTypeFlags( std::ofstream & ofs, DependencyData const& dependencyData )
|
void writeTypeFlags( std::ofstream & ofs, DependencyData const& dependencyData )
|
||||||
{
|
{
|
||||||
assert( dependencyData.dependencies.size() == 1 );
|
assert( dependencyData.dependencies.size() == 1 );
|
||||||
@ -1936,5 +1985,10 @@ int main( int argc, char **argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sortedDependencies.size(); i++)
|
||||||
|
{
|
||||||
|
writeEnumsToString(ofs, sortedDependencies[i], enums);
|
||||||
|
}
|
||||||
|
|
||||||
ofs << "}" << std::endl;
|
ofs << "}" << std::endl;
|
||||||
}
|
}
|
||||||
|
1597
vulkan/vk_cpp.h
1597
vulkan/vk_cpp.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user