@@ -6,7 +6,7 @@ EventDispatcher::handler_id EventDispatcher::Event::nextId = 1;
66
77std::string EventTarget::toJson () const
88{
9- return parent ? " \" parent\" :{" + parent->toJson () + " }" : " " ;
9+ return parent ? " \" parent\" :{" + parent->toJson () + " }" : " " ;
1010}
1111
1212EventDispatcher::Params::Params (const EventTarget *s) : target(s)
@@ -55,7 +55,7 @@ void EventDispatcher::Event::deactivate() { active = false; }
5555
5656bool EventDispatcher::Event::invoke (Params &¶ms)
5757{
58- params.event = std::const_pointer_cast<Event>( shared_from_this () );
58+ params.event = shared_from_this ();
5959 for (auto &handler : handlers) {
6060 params.handler = handler.first ;
6161 currentlyInvoked = params.handler ;
@@ -102,10 +102,7 @@ bool EventDispatcher::Event::operator()(Params &¶ms)
102102
103103EventDispatcher::~EventDispatcher ()
104104{
105- for (auto &event : eventRegistry) {
106- auto tmp = std::const_pointer_cast<Event>(event.second );
107- tmp->deactivate ();
108- }
105+ for (auto &event : eventRegistry) { event.second ->deactivate (); }
109106}
110107
111108const EventDispatcher::event_ptr EventDispatcher::getEvent (
@@ -137,8 +134,7 @@ bool EventDispatcher::destroyEvent(const char *name)
137134{
138135 auto iter = eventRegistry.find (name);
139136 if (iter == eventRegistry.end ()) return false ;
140- auto tmp = std::const_pointer_cast<Event>(iter->second );
141- tmp->deactivate ();
137+ iter->second ->deactivate ();
142138 eventRegistry.erase (iter);
143139 return true ;
144140}
@@ -162,10 +158,9 @@ void EventDispatcher::registerHandler(uint64_t owner, handler_id id)
162158void EventDispatcher::unregisterHandler (const event_ptr &event,
163159 uint64_t owner)
164160{
165- auto tmp = std::const_pointer_cast<Event>(event);
166161 auto iter = handlerRegistry.find (owner);
167162 if (iter != handlerRegistry.end ()) {
168- for (auto &item : iter->second ) tmp ->detach (item);
163+ for (auto &item : iter->second ) event ->detach (item);
169164 handlerRegistry.erase (iter);
170165 }
171166}
0 commit comments