From 51808b59e9f1f1238926adc55c25226c45a55a91 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 Feb 2014 14:31:24 +0800 Subject: [PATCH] More const reference love in EventDispatcher. --- cocos/2d/CCEventListener.cpp | 2 +- cocos/2d/CCEventListener.h | 2 +- cocos/2d/CCEventListenerAcceleration.cpp | 4 ++-- cocos/2d/CCEventListenerAcceleration.h | 4 ++-- cocos/2d/CCEventListenerCustom.cpp | 4 ++-- cocos/2d/CCEventListenerCustom.h | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCEventListener.cpp b/cocos/2d/CCEventListener.cpp index 3ed1e8b730..766cd2ec93 100644 --- a/cocos/2d/CCEventListener.cpp +++ b/cocos/2d/CCEventListener.cpp @@ -35,7 +35,7 @@ EventListener::~EventListener() CCLOGINFO("In the destructor of EventListener. %p", this); } -bool EventListener::init(Type t, ListenerID listenerID, std::function callback) +bool EventListener::init(Type t, const ListenerID& listenerID, const std::function& callback) { _onEvent = callback; _type = t; diff --git a/cocos/2d/CCEventListener.h b/cocos/2d/CCEventListener.h index 2f921823a2..eb79b5c016 100644 --- a/cocos/2d/CCEventListener.h +++ b/cocos/2d/CCEventListener.h @@ -64,7 +64,7 @@ protected: EventListener(); /** Initializes event with type and callback function */ - bool init(Type t, ListenerID listenerID, std::functioncallback); + bool init(Type t, const ListenerID& listenerID, const std::function& callback); public: /** Destructor */ virtual ~EventListener(); diff --git a/cocos/2d/CCEventListenerAcceleration.cpp b/cocos/2d/CCEventListenerAcceleration.cpp index 72defaa6e0..c0a25afba4 100644 --- a/cocos/2d/CCEventListenerAcceleration.cpp +++ b/cocos/2d/CCEventListenerAcceleration.cpp @@ -39,7 +39,7 @@ EventListenerAcceleration::~EventListenerAcceleration() CCLOGINFO("In the destructor of AccelerationEventListener. %p", this); } -EventListenerAcceleration* EventListenerAcceleration::create(std::function callback) +EventListenerAcceleration* EventListenerAcceleration::create(const std::function& callback) { EventListenerAcceleration* ret = new EventListenerAcceleration(); if (ret && ret->init(callback)) @@ -54,7 +54,7 @@ EventListenerAcceleration* EventListenerAcceleration::create(std::function callback) +bool EventListenerAcceleration::init(const std::function& callback) { auto listener = [this](Event* event){ auto accEvent = static_cast(event); diff --git a/cocos/2d/CCEventListenerAcceleration.h b/cocos/2d/CCEventListenerAcceleration.h index 2f290b8fb8..0410b8e436 100644 --- a/cocos/2d/CCEventListenerAcceleration.h +++ b/cocos/2d/CCEventListenerAcceleration.h @@ -35,7 +35,7 @@ class EventListenerAcceleration : public EventListener public: static const std::string LISTENER_ID; - static EventListenerAcceleration* create(std::function callback); + static EventListenerAcceleration* create(const std::function& callback); virtual ~EventListenerAcceleration(); /// Overrides @@ -44,7 +44,7 @@ public: private: EventListenerAcceleration(); - bool init(std::function callback); + bool init(const std::function& callback); std::function onAccelerationEvent; friend class LuaEventListenerAcceleration; diff --git a/cocos/2d/CCEventListenerCustom.cpp b/cocos/2d/CCEventListenerCustom.cpp index aeebcd5fd4..9240c5939c 100644 --- a/cocos/2d/CCEventListenerCustom.cpp +++ b/cocos/2d/CCEventListenerCustom.cpp @@ -32,7 +32,7 @@ EventListenerCustom::EventListenerCustom() { } -EventListenerCustom* EventListenerCustom::create(const std::string& eventName, std::function callback) +EventListenerCustom* EventListenerCustom::create(const std::string& eventName, const std::function& callback) { EventListenerCustom* ret = new EventListenerCustom(); if (ret && ret->init(eventName, callback)) @@ -46,7 +46,7 @@ EventListenerCustom* EventListenerCustom::create(const std::string& eventName, s return ret; } -bool EventListenerCustom::init(ListenerID listenerId, std::functioncallback) +bool EventListenerCustom::init(const ListenerID& listenerId, const std::function& callback) { bool ret = false; diff --git a/cocos/2d/CCEventListenerCustom.h b/cocos/2d/CCEventListenerCustom.h index 20c4f3497e..7e1d1b2d80 100644 --- a/cocos/2d/CCEventListenerCustom.h +++ b/cocos/2d/CCEventListenerCustom.h @@ -56,7 +56,7 @@ public: * @param eventType The type of the event. * @param callback The callback function when the specified event was emitted. */ - static EventListenerCustom* create(const std::string& eventName, std::function callback); + static EventListenerCustom* create(const std::string& eventName, const std::function& callback); /// Overrides virtual bool checkAvailable() override; @@ -67,7 +67,7 @@ protected: EventListenerCustom(); /** Initializes event with type and callback function */ - bool init(ListenerID listenerId, std::function callback); + bool init(const ListenerID& listenerId, const std::function& callback); std::function _onCustomEvent;