From 8cb8332923fbed868b135fd143e7734380ff191b Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Sun, 13 Aug 2023 12:15:18 +0200 Subject: [PATCH] Add support for classname suffixes --- openVulkanoCpp/Host/iOS/NamedEventProcessor.h | 9 +++++++-- .../Host/iOS/NamedEventProcessor.mm | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.h b/openVulkanoCpp/Host/iOS/NamedEventProcessor.h index 4d47496..055c335 100644 --- a/openVulkanoCpp/Host/iOS/NamedEventProcessor.h +++ b/openVulkanoCpp/Host/iOS/NamedEventProcessor.h @@ -12,12 +12,17 @@ namespace openVulkanoCpp { class NamedEventProcessor final : public INamedEventProcessor { - std::vector m_classNamePrefixes; + std::vector m_classNamePrefixes, m_classNameSuffixes; public: - NamedEventProcessor() { RegisterClassNamePrefix(""); } + NamedEventProcessor() + : m_classNamePrefixes({ "", "Event" }) + , m_classNameSuffixes({ "Event", "" }) + {} void RegisterClassNamePrefix(const std::string& prefix) { m_classNamePrefixes.push_back(prefix); } + void RegisterClassNameSuffix(const std::string& suffix) { m_classNameSuffixes.push_back(suffix); } + void Notify(const std::string& eventName, const std::vector& parameters) const override; }; } \ No newline at end of file diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm b/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm index 0fd6f64..0d0a112 100644 --- a/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm +++ b/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm @@ -101,15 +101,19 @@ namespace openVulkanoCpp return init; } - Class FindGenericEventClass(const std::vector& prefixes, const std::string& eventName) - { - for (const std::string& prefix : prefixes) + Class FindGenericEventClass(const std::vector& prefixes, + const std::vector& suffixes, + const std::string& eventName) + { // Searching for class with all registered prefix/suffix combinations + for (const std::string& suffix : suffixes) { - // look for class in all registered class prefixes - NSString* eventClassName = [NSString stringWithUTF8String:(prefix + eventName).c_str()]; - if (Class eventClass = NSClassFromString(eventClassName)) + for (const std::string& prefix: prefixes) { - return eventClass; + NSString* eventClassName = [NSString stringWithUTF8String:(prefix + eventName + suffix).c_str()]; + if (Class eventClass = NSClassFromString(eventClassName)) + { + return eventClass; + } } } return nullptr; @@ -118,7 +122,7 @@ namespace openVulkanoCpp void NamedEventProcessor::Notify(const std::string& eventName, const std::vector& parameters) const { - if (auto eventClass = FindGenericEventClass(m_classNamePrefixes, eventName)) + if (auto eventClass = FindGenericEventClass(m_classNamePrefixes, m_classNameSuffixes, eventName)) { if (auto init = GetInitForClass(eventClass, BuildTypeName(parameters))) {