automatically convert enum classes in named events to ints

This commit is contained in:
Georg Hagen
2024-08-02 16:26:14 +02:00
parent bc8cb043e9
commit 057a64710c

View File

@@ -227,12 +227,30 @@ namespace OpenVulkano
{} {}
void Notify(Arguments... args) const override void Notify(Arguments... args) const override
{
NotifyImpl(std::forward<Arguments>(args)...);
}
void NotifyImpl(Arguments... args) const
{ {
if (INamedEventProcessor::HasProcessor()) if (INamedEventProcessor::HasProcessor())
{ {
std::vector<INamedEventProcessor::Parameters> attributes; std::vector<INamedEventProcessor::Parameters> attributes;
attributes.reserve(sizeof...(Arguments)); attributes.reserve(sizeof...(Arguments));
(attributes.emplace_back(args), ...); if constexpr (!std::conjunction_v<std::is_enum<std::remove_reference_t<Arguments>>...>)
{
(attributes.emplace_back(args), ...);
}
else
{
auto fill = [&](auto&& arg) {
if constexpr (std::is_enum_v<std::remove_reference_t<decltype(arg)>>)
attributes.emplace_back(static_cast<int>(arg));
else
attributes.emplace_back(std::forward<decltype(arg)>(arg));
};
(fill(std::forward<Arguments>(args)), ...);
}
INamedEventProcessor::NotifyAll(m_name, attributes); INamedEventProcessor::NotifyAll(m_name, attributes);
} }
} }