Add support for classname suffixes
This commit is contained in:
@@ -12,12 +12,17 @@ namespace openVulkanoCpp
|
||||
{
|
||||
class NamedEventProcessor final : public INamedEventProcessor
|
||||
{
|
||||
std::vector<std::string> m_classNamePrefixes;
|
||||
std::vector<std::string> 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>& parameters) const override;
|
||||
};
|
||||
}
|
||||
@@ -101,15 +101,19 @@ namespace openVulkanoCpp
|
||||
return init;
|
||||
}
|
||||
|
||||
Class FindGenericEventClass(const std::vector<std::string>& prefixes, const std::string& eventName)
|
||||
{
|
||||
for (const std::string& prefix : prefixes)
|
||||
Class FindGenericEventClass(const std::vector<std::string>& prefixes,
|
||||
const std::vector<std::string>& 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>& 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)))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user