// Copyright 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CCThreadTask_h #define CCThreadTask_h #include "CCThread.h" #include #include namespace cc { template class CCThreadTask0 : public CCThread::Task { public: typedef void (T::*Method)(); typedef CCThreadTask0 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method) { return adoptPtr(new CCThreadTaskImpl(instance, method)); } private: CCThreadTask0(T* instance, Method method) : CCThread::Task(instance) , m_method(method) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(); } private: Method m_method; }; template class CCThreadTask1 : public CCThread::Task { public: typedef void (T::*Method)(MP1); typedef CCThreadTask1 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method, P1 parameter1) { return adoptPtr(new CCThreadTaskImpl(instance, method, parameter1)); } private: CCThreadTask1(T* instance, Method method, P1 parameter1) : CCThread::Task(instance) , m_method(method) , m_parameter1(parameter1) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(m_parameter1); } private: Method m_method; P1 m_parameter1; }; template class CCThreadTask2 : public CCThread::Task { public: typedef void (T::*Method)(MP1, MP2); typedef CCThreadTask2 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method, P1 parameter1, P2 parameter2) { return adoptPtr(new CCThreadTaskImpl(instance, method, parameter1, parameter2)); } private: CCThreadTask2(T* instance, Method method, P1 parameter1, P2 parameter2) : CCThread::Task(instance) , m_method(method) , m_parameter1(parameter1) , m_parameter2(parameter2) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(m_parameter1, m_parameter2); } private: Method m_method; P1 m_parameter1; P2 m_parameter2; }; template class CCThreadTask3 : public CCThread::Task { public: typedef void (T::*Method)(MP1, MP2, MP3); typedef CCThreadTask3 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3) { return adoptPtr(new CCThreadTaskImpl(instance, method, parameter1, parameter2, parameter3)); } private: CCThreadTask3(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3) : CCThread::Task(instance) , m_method(method) , m_parameter1(parameter1) , m_parameter2(parameter2) , m_parameter3(parameter3) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3); } private: Method m_method; P1 m_parameter1; P2 m_parameter2; P3 m_parameter3; }; template class CCThreadTask4 : public CCThread::Task { public: typedef void (T::*Method)(MP1, MP2, MP3, MP4); typedef CCThreadTask4 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4) { return adoptPtr(new CCThreadTaskImpl(instance, method, parameter1, parameter2, parameter3, parameter4)); } private: CCThreadTask4(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4) : CCThread::Task(instance) , m_method(method) , m_parameter1(parameter1) , m_parameter2(parameter2) , m_parameter3(parameter3) , m_parameter4(parameter4) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3, m_parameter4); } private: Method m_method; P1 m_parameter1; P2 m_parameter2; P3 m_parameter3; P4 m_parameter4; }; template class CCThreadTask5 : public CCThread::Task { public: typedef void (T::*Method)(MP1, MP2, MP3, MP4, MP5); typedef CCThreadTask5 CCThreadTaskImpl; static PassOwnPtr create(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4, P5 parameter5) { return adoptPtr(new CCThreadTaskImpl(instance, method, parameter1, parameter2, parameter3, parameter4, parameter5)); } private: CCThreadTask5(T* instance, Method method, P1 parameter1, P2 parameter2, P3 parameter3, P4 parameter4, P5 parameter5) : CCThread::Task(instance) , m_method(method) , m_parameter1(parameter1) , m_parameter2(parameter2) , m_parameter3(parameter3) , m_parameter4(parameter4) , m_parameter5(parameter5) { } virtual void performTask() OVERRIDE { (*static_cast(instance()).*m_method)(m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5); } private: Method m_method; P1 m_parameter1; P2 m_parameter2; P3 m_parameter3; P4 m_parameter4; P5 m_parameter5; }; template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)()); template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)()) { return CCThreadTask0::create( callee, method); } template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)(MP1), const P1& parameter1) { return CCThreadTask1::create( callee, method, parameter1); } template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)(MP1, MP2), const P1& parameter1, const P2& parameter2) { return CCThreadTask2::create( callee, method, parameter1, parameter2); } template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)(MP1, MP2, MP3), const P1& parameter1, const P2& parameter2, const P3& parameter3) { return CCThreadTask3::create( callee, method, parameter1, parameter2, parameter3); } template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)(MP1, MP2, MP3, MP4), const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4) { return CCThreadTask4::create( callee, method, parameter1, parameter2, parameter3, parameter4); } template PassOwnPtr createCCThreadTask( T* const callee, void (T::*method)(MP1, MP2, MP3, MP4, MP5), const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4& parameter4, const P5& parameter5) { return CCThreadTask5::create( callee, method, parameter1, parameter2, parameter3, parameter4, parameter5); } } // namespace cc #endif // CCThreadTask_h