diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.h b/openVulkanoCpp/Host/iOS/NamedEventProcessor.h index 055c335..277f0c5 100644 --- a/openVulkanoCpp/Host/iOS/NamedEventProcessor.h +++ b/openVulkanoCpp/Host/iOS/NamedEventProcessor.h @@ -13,10 +13,12 @@ namespace openVulkanoCpp class NamedEventProcessor final : public INamedEventProcessor { std::vector m_classNamePrefixes, m_classNameSuffixes; + bool m_useClassNameAsEventName; public: - NamedEventProcessor() + NamedEventProcessor(bool classNameAsEventName = false) : m_classNamePrefixes({ "", "Event" }) , m_classNameSuffixes({ "Event", "" }) + , m_useClassNameAsEventName(classNameAsEventName) {} void RegisterClassNamePrefix(const std::string& prefix) { m_classNamePrefixes.push_back(prefix); } diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm b/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm index 0d0a112..61cc6ad 100644 --- a/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm +++ b/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm @@ -122,11 +122,11 @@ namespace openVulkanoCpp void NamedEventProcessor::Notify(const std::string& eventName, const std::vector& parameters) const { - if (auto eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName)) + if (Class eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName)) { - if (auto init = GetInitForClass(eventClass, BuildTypeName(parameters))) + if (SEL init = GetInitForClass(eventClass, BuildTypeName(parameters))) { - auto event = [eventClass alloc]; + NSObject* event = [eventClass alloc]; auto inv = [NSInvocation invocationWithMethodSignature:[event methodSignatureForSelector:init]]; [inv setTarget:event]; [inv setSelector:init]; @@ -138,17 +138,20 @@ namespace openVulkanoCpp [inv invoke]; for (Class clazz = eventClass; clazz && clazz != NSObject.class; clazz = class_getSuperclass(clazz)) { - [[NSNotificationCenter defaultCenter] postNotificationName:NSStringFromClass(clazz) object:event userInfo:nil]; + NSString* notificationName; + if (m_useClassNameAsEventName) notificationName = NSStringFromClass(clazz); + else notificationName = [NSString stringWithUTF8String:eventName.c_str()]; + [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:event userInfo:nil]; } } else { - Logger::MANAGER->error("Cannot find viable constructor for event %s", eventName.c_str()); + Logger::MANAGER->error("Cannot find constructor for named event %s", eventName); } } else { - Logger::MANAGER->debug("Cannot find implementation for event %s", eventName); + Logger::MANAGER->debug("Cannot find implementation for named event %s", eventName); } } }