EventRegistry: remove uses of PDict

This commit is contained in:
Tim Wojtulewicz 2019-07-26 12:41:34 -07:00
parent 6fa0f4ac49
commit acff8d5a2b
3 changed files with 45 additions and 68 deletions

View file

@ -4,85 +4,67 @@
void EventRegistry::Register(EventHandlerPtr handler)
{
HashKey key(handler->Name());
handlers.Insert(&key, handler.Ptr());
handlers[string(handler->Name())] = handler.Ptr();
}
EventHandler* EventRegistry::Lookup(const char* name)
EventHandler* EventRegistry::Lookup(const string& name)
{
HashKey key(name);
return handlers.Lookup(&key);
auto it = handlers.find(name);
if ( it != handlers.end() )
return it->second;
return nullptr;
}
EventRegistry::string_list* EventRegistry::Match(RE_Matcher* pattern)
EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern)
{
string_list* names = new string_list;
string_list names;
IterCookie* c = handlers.InitForIteration();
HashKey* k;
EventHandler* v;
while ( (v = handlers.NextEntry(k, c)) )
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) )
names->push_back(v->Name());
delete k;
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list* EventRegistry::UnusedHandlers()
EventRegistry::string_list EventRegistry::UnusedHandlers()
{
string_list* names = new string_list;
string_list names;
IterCookie* c = handlers.InitForIteration();
HashKey* k;
EventHandler* v;
while ( (v = handlers.NextEntry(k, c)) )
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && ! v->Used() )
names->push_back(v->Name());
delete k;
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list* EventRegistry::UsedHandlers()
EventRegistry::string_list EventRegistry::UsedHandlers()
{
string_list* names = new string_list;
string_list names;
IterCookie* c = handlers.InitForIteration();
HashKey* k;
EventHandler* v;
while ( (v = handlers.NextEntry(k, c)) )
for ( const auto& entry : handlers )
{
EventHandler* v = entry.second;
if ( v->LocalHandler() && v->Used() )
names->push_back(v->Name());
delete k;
names.push_back(entry.first);
}
return names;
}
EventRegistry::string_list* EventRegistry::AllHandlers()
EventRegistry::string_list EventRegistry::AllHandlers()
{
string_list* names = new string_list(handlers.Length());
string_list names;
IterCookie* c = handlers.InitForIteration();
HashKey* k;
EventHandler* v;
while ( (v = handlers.NextEntry(k, c)) )
for ( const auto& entry : handlers )
{
names->push_back(v->Name());
delete k;
names.push_back(entry.first);
}
return names;
@ -90,13 +72,9 @@ EventRegistry::string_list* EventRegistry::AllHandlers()
void EventRegistry::PrintDebug()
{
IterCookie* c = handlers.InitForIteration();
HashKey* k;
EventHandler* v;
while ( (v = handlers.NextEntry(k, c)) )
for ( const auto& entry : handlers )
{
delete k;
EventHandler* v = entry.second;
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
v->LocalHandler()? "local" : "no",
*v ? "active" : "not active"
@ -104,7 +82,7 @@ void EventRegistry::PrintDebug()
}
}
void EventRegistry::SetErrorHandler(const char* name)
void EventRegistry::SetErrorHandler(const string& name)
{
EventHandler* eh = Lookup(name);
@ -115,6 +93,6 @@ void EventRegistry::SetErrorHandler(const char* name)
}
reporter->InternalWarning(
"unknown event handler '%s' in SetErrorHandler()", name);
"unknown event handler '%s' in SetErrorHandler()", name.c_str());
}