Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

runnable.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00029 #ifndef header_runnable
00030 #define header_runnable
00031 
00032 class CL_Runnable
00033 {
00035 public:
00036         CL_Runnable();
00037 
00038         virtual ~CL_Runnable();
00039 
00041 public:
00042 
00044 public:
00045         virtual void run() = 0;
00046 
00048 private:
00049 };
00050 
00051 template<class C>
00052 class CL_RunnableMember_v0 : public CL_Runnable
00053 {
00055 public:
00056         typedef void (C::*PtrMemberFunc)();
00057 
00058         CL_RunnableMember_v0(C *instance, PtrMemberFunc func)
00059         : instance(instance), func(func)
00060         {
00061         }
00062 
00064 public:
00065         virtual void run()
00066         {
00067                 C *local_instance = instance;
00068                 PtrMemberFunc local_func = func;
00069                 delete this;
00070                 (local_instance->*local_func)();
00071         }
00072 
00074 private:
00075         C *instance;
00076         
00077         PtrMemberFunc func;
00078 };
00079 
00080 template<class C, class P1>
00081 class CL_RunnableMember_v1 : public CL_Runnable
00082 {
00084 public:
00085         typedef void (C::*PtrMemberFunc)(P1 p1);
00086 
00087         CL_RunnableMember_v1(C *instance, PtrMemberFunc func, P1 p1)
00088         : instance(instance), func(func), p1(p1)
00089         {
00090         }
00091 
00093 public:
00094         virtual void run()
00095         {
00096                 C *local_instance = instance;
00097                 PtrMemberFunc local_func = func;
00098                 P1 local_p1 = p1;
00099                 delete this;
00100                 (local_instance->*local_func)(local_p1);
00101         }
00102 
00104 private:
00105         C *instance;
00106         
00107         PtrMemberFunc func;
00108         
00109         P1 p1;
00110 };
00111 
00112 template<class C, class P1, class P2>
00113 class CL_RunnableMember_v2 : public CL_Runnable
00114 {
00116 public:
00117         typedef void (C::*PtrMemberFunc)(P1 p1, P2 p2);
00118 
00119         CL_RunnableMember_v2(C *instance, PtrMemberFunc func, P1 p1, P2 p2)
00120         : instance(instance), func(func), p1(p1), p2(p2)
00121         {
00122         }
00123 
00125 public:
00126         virtual void run()
00127         {
00128                 C *local_instance = instance;
00129                 PtrMemberFunc local_func = func;
00130                 P1 local_p1 = p1;
00131                 P2 local_p2 = p2;
00132                 delete this;
00133                 (local_instance->*local_func)(local_p1, local_p2);
00134         }
00135 
00137 private:
00138         C *instance;
00139         
00140         PtrMemberFunc func;
00141         
00142         P1 p1;
00143         
00144         P2 p2;
00145 };
00146 
00147 template<class C, class P1, class P2, class P3>
00148 class CL_RunnableMember_v3 : public CL_Runnable
00149 {
00151 public:
00152         typedef void (C::*PtrMemberFunc)(P1 p1, P2 p2, P3 p3);
00153 
00154         CL_RunnableMember_v3(C *instance, PtrMemberFunc func, P1 p1, P2 p2, P3 p3)
00155         : instance(instance), func(func), p1(p1), p2(p2), p3(p3)
00156         {
00157         }
00158 
00160 public:
00161         virtual void run()
00162         {
00163                 C *local_instance = instance;
00164                 PtrMemberFunc local_func = func;
00165                 P1 local_p1 = p1;
00166                 P2 local_p2 = p2;
00167                 P3 local_p3 = p3;
00168                 delete this;
00169                 (local_instance->*local_func)(local_p1, local_p2, local_p3);
00170         }
00171 
00173 private:
00174         C *instance;
00175         
00176         PtrMemberFunc func;
00177         
00178         P1 p1;
00179         
00180         P2 p2;
00181         
00182         P3 p3;
00183 };
00184 
00185 template<class C, class P1, class P2, class P3, class P4>
00186 class CL_RunnableMember_v4 : public CL_Runnable
00187 {
00189 public:
00190         typedef void (C::*PtrMemberFunc)(P1 p1, P2 p2, P3 p3, P4 p4);
00191 
00192         CL_RunnableMember_v4(C *instance, PtrMemberFunc func, P1 p1, P2 p2, P3 p3, P4 p4)
00193         : instance(instance), func(func), p1(p1), p2(p2), p3(p3), p4(p4)
00194         {
00195         }
00196 
00198 public:
00199         virtual void run()
00200         {
00201                 C *local_instance = instance;
00202                 PtrMemberFunc local_func = func;
00203                 P1 local_p1 = p1;
00204                 P2 local_p2 = p2;
00205                 P3 local_p3 = p3;
00206                 P4 local_p4 = p4;
00207                 delete this;
00208                 (local_instance->*local_func)(local_p1, local_p2, local_p3, local_p4);
00209         }
00210 
00212 private:
00213         C *instance;
00214         
00215         PtrMemberFunc func;
00216         
00217         P1 p1;
00218         
00219         P2 p2;
00220         
00221         P3 p3;
00222         
00223         P4 p4;
00224 };
00225 
00226 template<class C, class P1, class P2, class P3, class P4, class P5>
00227 class CL_RunnableMember_v5 : public CL_Runnable
00228 {
00230 public:
00231         typedef void (C::*PtrMemberFunc)(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5);
00232 
00233         CL_RunnableMember_v5(C *instance, PtrMemberFunc func, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
00234         : instance(instance), func(func), p1(p1), p2(p2), p3(p3), p4(p4), p5(p5)
00235         {
00236         }
00237 
00239 public:
00240         virtual void run()
00241         {
00242                 C *local_instance = instance;
00243                 PtrMemberFunc local_func = func;
00244                 P1 local_p1 = p1;
00245                 P2 local_p2 = p2;
00246                 P3 local_p3 = p3;
00247                 P4 local_p4 = p4;
00248                 P5 local_p5 = p5;
00249                 delete this;
00250                 (local_instance->*local_func)(local_p1, local_p2, local_p3, local_p4, local_p5);
00251         }
00252 
00254 private:
00255         C *instance;
00256         
00257         PtrMemberFunc func;
00258         
00259         P1 p1;
00260         
00261         P2 p2;
00262         
00263         P3 p3;
00264         
00265         P4 p4;
00266         
00267         P5 p5;
00268 };
00269 
00270 #endif

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1