Add getString(VkEnum)/getString(VKFlags) support

This commit is contained in:
Markus Tavenrath 2016-02-18 12:12:55 +01:00
parent 4aa2b3f4dc
commit be14a994fb
3 changed files with 1657 additions and 0 deletions

View File

@ -109,6 +109,12 @@ vk::ImageCreateInfo ci(
</code>
</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
Another nice feature of those constructors is that sType is being initialized internally and thus is always correct.

View File

@ -1655,6 +1655,55 @@ void writeTypeEnum( std::ofstream & ofs, DependencyData const& dependencyData, E
<< 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 )
{
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;
}

File diff suppressed because it is too large Load Diff