library of assembled shared sources

http://lass.cocamware.com

thread_fun.h

Go to the documentation of this file.
00001 /*
00002  * *** ATTENTION!  DO NOT MODIFY THIS FILE DIRECTLY! ***
00003  * 
00004  * It has automatically been generated from thread_fun.tmpl.h
00005  * by param_expander.py on Sun Nov 09 16:55:48 2008.
00006  */
00007 
00008 /** @file
00009  *  @author Bram de Greve (bramz@users.sourceforge.net)
00010  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00011  *
00012  *  *** BEGIN LICENSE INFORMATION ***
00013  *  
00014  *  The contents of this file are subject to the Common Public Attribution License 
00015  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00016  *  the License. You may obtain a copy of the License at 
00017  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00018  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00019  *  use of software over a computer network and provide for limited attribution for 
00020  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00021  *  with Exhibit B.
00022  *  
00023  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00024  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00025  *  language governing rights and limitations under the License.
00026  *  
00027  *  The Original Code is LASS - Library of Assembled Shared Sources.
00028  *  
00029  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00030  *  The Original Developer is the Initial Developer.
00031  *  
00032  *  All portions of the code written by the Initial Developer are:
00033  *  Copyright (C) 2004-2007 the Initial Developer.
00034  *  All Rights Reserved.
00035  *  
00036  *  Contributor(s):
00037  *
00038  *  Alternatively, the contents of this file may be used under the terms of the 
00039  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00040  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00041  *  of your version of this file only under the terms of the GPL and not to allow 
00042  *  others to use your version of this file under the CPAL, indicate your decision by 
00043  *  deleting the provisions above and replace them with the notice and other 
00044  *  provisions required by the GPL License. If you do not delete the provisions above,
00045  *  a recipient may use your version of this file under either the CPAL or the GPL.
00046  *  
00047  *  *** END LICENSE INFORMATION ***
00048  */
00049 
00050 /** @class ThreadFun
00051  *  @brief library to run (member) functions in a thread
00052  *  @author [Bramz]
00053  *
00054  *  With these objects/functions, you can run (member) functions in threads instead of calling
00055  *  them directly.  you even can specify the arguments to be used.  Let's illustrate this with
00056  *  a simple example:
00057  *
00058  *  @code
00059  *  void foo(int iNumber, const std::string& iText);
00060  *
00061  *  // direct call
00062  *  foo(5, "hello");
00063  *
00064  *  // through thread
00065  *  threadFun(foo, 5, "hello")->run();
00066  * 
00067  *  @endcode
00068  *
00069  *  threadFun2 allocates a new thread with the necessary information to call the function,
00070  *  then creates and runs the thread.  It returns a pointer to the allocated thread.  If you do
00071  *  nothing, the thread runs in @e detached mode and will kill itself at completion (so you don't
00072  *  have to call @c delete on @c thread yourself.  So you even don't have to catch the return
00073  *  value.  However, if you want to run it in @e joinable, you'll have delete the thread
00074  *  yourself.  DO NOT FORGET THIS!  Maybe we should do something about this situation?
00075  *
00076  *  @code
00077  *  // run two threads at the same time.
00078  *  util::ScopedPtr<Thread> a = threadFun(foo, 5, "hello", threadJoinable);
00079  *  util::ScopedPtr<Thread> b = threadFun(foo, 6, "world!", threadJoinable);
00080  *  a->run();
00081  *  b->run();
00082  *  a->join();
00083  *  b->join();
00084  *  @endcode
00085  *
00086  *  You can also call member functions of specific objects in the thread, both const as non-const
00087  *  member functions.
00088  *
00089  *  @code
00090  *  class Bar
00091  *  {
00092  *      void fun(float iValue) const;
00093  *      void beer();
00094  *  };
00095  *
00096  *  Bar bar;
00097  *  util::ScopedPtr<Thread> a = threadFun(bar, Bar::fun, 3.14, threadJoinable);
00098  *  util::ScopedPtr<Thread> b = threadFun(bar, Bar::beer, threadJoinable);
00099  *  a->run();
00100  *  b->run();
00101  *  a->join();
00102  *  b->join();
00103  *  @endcode
00104  *
00105  *  Limitations:
00106  *  - the functions can't have return values, or they are ignored (who should they pass it
00107  *    through to, anyway?)
00108  *  - You can't have more than 15 arguments (unless you tweak the prebuild ;)
00109  *
00110  *  @warning Only ThreadFun0 and ThreadFun1 are partially tested.
00111  */
00112 
00113 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_THREAD_FUN_H
00114 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_THREAD_FUN_H
00115 
00116 #include "util_common.h"
00117 #include "callback_0.h"
00118 #include "thread.h"
00119 #include "../meta/type_traits.h"
00120 
00121 namespace lass
00122 {
00123 namespace util
00124 {
00125 
00126 class LASS_DLL ThreadFun: public Thread
00127 {
00128 public:
00129     ThreadFun(const Callback0& fun, ThreadKind kind = threadDetached);
00130 private:
00131     void doRun();
00132     Callback0 fun_;
00133 };
00134 
00135 // --- 0 arguments ---------------------------------------------------------------------------------
00136 
00137 template <typename Function>
00138 ThreadFun* threadFun(
00139     Function function,
00140     ThreadKind kind = threadDetached);
00141 
00142 template <typename ObjectPtr, typename Method>
00143 ThreadFun* threadMemFun(
00144     ObjectPtr object, Method method,
00145     ThreadKind kind = threadDetached);
00146 
00147 
00148 // --- 1 argument(s) ----------------------------------------------------------------------------
00149 
00150 template <typename P1, typename Function>
00151 ThreadFun* threadFun(
00152     Function function,
00153     const P1& iP1,
00154     ThreadKind kind = threadDetached);
00155 
00156 template <typename P1, typename ObjectPtr, typename Method>
00157 ThreadFun* threadMemFun(
00158     ObjectPtr object, Method method,
00159     const P1& iP1,
00160     ThreadKind kind = threadDetached);
00161 
00162 // --- 2 argument(s) ----------------------------------------------------------------------------
00163 
00164 template <typename P1, typename P2, typename Function>
00165 ThreadFun* threadFun(
00166     Function function,
00167     const P1& iP1, const P2& iP2,
00168     ThreadKind kind = threadDetached);
00169 
00170 template <typename P1, typename P2, typename ObjectPtr, typename Method>
00171 ThreadFun* threadMemFun(
00172     ObjectPtr object, Method method,
00173     const P1& iP1, const P2& iP2,
00174     ThreadKind kind = threadDetached);
00175 
00176 // --- 3 argument(s) ----------------------------------------------------------------------------
00177 
00178 template <typename P1, typename P2, typename P3, typename Function>
00179 ThreadFun* threadFun(
00180     Function function,
00181     const P1& iP1, const P2& iP2, const P3& iP3,
00182     ThreadKind kind = threadDetached);
00183 
00184 template <typename P1, typename P2, typename P3, typename ObjectPtr, typename Method>
00185 ThreadFun* threadMemFun(
00186     ObjectPtr object, Method method,
00187     const P1& iP1, const P2& iP2, const P3& iP3,
00188     ThreadKind kind = threadDetached);
00189 
00190 // --- 4 argument(s) ----------------------------------------------------------------------------
00191 
00192 template <typename P1, typename P2, typename P3, typename P4, typename Function>
00193 ThreadFun* threadFun(
00194     Function function,
00195     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4,
00196     ThreadKind kind = threadDetached);
00197 
00198 template <typename P1, typename P2, typename P3, typename P4, typename ObjectPtr, typename Method>
00199 ThreadFun* threadMemFun(
00200     ObjectPtr object, Method method,
00201     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4,
00202     ThreadKind kind = threadDetached);
00203 
00204 // --- 5 argument(s) ----------------------------------------------------------------------------
00205 
00206 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename Function>
00207 ThreadFun* threadFun(
00208     Function function,
00209     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5,
00210     ThreadKind kind = threadDetached);
00211 
00212 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename ObjectPtr, typename Method>
00213 ThreadFun* threadMemFun(
00214     ObjectPtr object, Method method,
00215     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5,
00216     ThreadKind kind = threadDetached);
00217 
00218 // --- 6 argument(s) ----------------------------------------------------------------------------
00219 
00220 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename Function>
00221 ThreadFun* threadFun(
00222     Function function,
00223     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6,
00224     ThreadKind kind = threadDetached);
00225 
00226 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename ObjectPtr, typename Method>
00227 ThreadFun* threadMemFun(
00228     ObjectPtr object, Method method,
00229     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6,
00230     ThreadKind kind = threadDetached);
00231 
00232 // --- 7 argument(s) ----------------------------------------------------------------------------
00233 
00234 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename Function>
00235 ThreadFun* threadFun(
00236     Function function,
00237     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7,
00238     ThreadKind kind = threadDetached);
00239 
00240 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename ObjectPtr, typename Method>
00241 ThreadFun* threadMemFun(
00242     ObjectPtr object, Method method,
00243     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7,
00244     ThreadKind kind = threadDetached);
00245 
00246 // --- 8 argument(s) ----------------------------------------------------------------------------
00247 
00248 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename Function>
00249 ThreadFun* threadFun(
00250     Function function,
00251     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8,
00252     ThreadKind kind = threadDetached);
00253 
00254 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename ObjectPtr, typename Method>
00255 ThreadFun* threadMemFun(
00256     ObjectPtr object, Method method,
00257     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8,
00258     ThreadKind kind = threadDetached);
00259 
00260 // --- 9 argument(s) ----------------------------------------------------------------------------
00261 
00262 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename Function>
00263 ThreadFun* threadFun(
00264     Function function,
00265     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9,
00266     ThreadKind kind = threadDetached);
00267 
00268 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename ObjectPtr, typename Method>
00269 ThreadFun* threadMemFun(
00270     ObjectPtr object, Method method,
00271     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9,
00272     ThreadKind kind = threadDetached);
00273 
00274 // --- 10 argument(s) ----------------------------------------------------------------------------
00275 
00276 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename Function>
00277 ThreadFun* threadFun(
00278     Function function,
00279     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10,
00280     ThreadKind kind = threadDetached);
00281 
00282 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename ObjectPtr, typename Method>
00283 ThreadFun* threadMemFun(
00284     ObjectPtr object, Method method,
00285     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10,
00286     ThreadKind kind = threadDetached);
00287 
00288 // --- 11 argument(s) ----------------------------------------------------------------------------
00289 
00290 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename Function>
00291 ThreadFun* threadFun(
00292     Function function,
00293     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11,
00294     ThreadKind kind = threadDetached);
00295 
00296 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename ObjectPtr, typename Method>
00297 ThreadFun* threadMemFun(
00298     ObjectPtr object, Method method,
00299     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11,
00300     ThreadKind kind = threadDetached);
00301 
00302 // --- 12 argument(s) ----------------------------------------------------------------------------
00303 
00304 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename Function>
00305 ThreadFun* threadFun(
00306     Function function,
00307     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12,
00308     ThreadKind kind = threadDetached);
00309 
00310 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename ObjectPtr, typename Method>
00311 ThreadFun* threadMemFun(
00312     ObjectPtr object, Method method,
00313     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12,
00314     ThreadKind kind = threadDetached);
00315 
00316 // --- 13 argument(s) ----------------------------------------------------------------------------
00317 
00318 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename Function>
00319 ThreadFun* threadFun(
00320     Function function,
00321     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13,
00322     ThreadKind kind = threadDetached);
00323 
00324 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename ObjectPtr, typename Method>
00325 ThreadFun* threadMemFun(
00326     ObjectPtr object, Method method,
00327     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13,
00328     ThreadKind kind = threadDetached);
00329 
00330 // --- 14 argument(s) ----------------------------------------------------------------------------
00331 
00332 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename Function>
00333 ThreadFun* threadFun(
00334     Function function,
00335     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13, const P14& iP14,
00336     ThreadKind kind = threadDetached);
00337 
00338 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename ObjectPtr, typename Method>
00339 ThreadFun* threadMemFun(
00340     ObjectPtr object, Method method,
00341     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13, const P14& iP14,
00342     ThreadKind kind = threadDetached);
00343 
00344 // --- 15 argument(s) ----------------------------------------------------------------------------
00345 
00346 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15, typename Function>
00347 ThreadFun* threadFun(
00348     Function function,
00349     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13, const P14& iP14, const P15& iP15,
00350     ThreadKind kind = threadDetached);
00351 
00352 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12, typename P13, typename P14, typename P15, typename ObjectPtr, typename Method>
00353 ThreadFun* threadMemFun(
00354     ObjectPtr object, Method method,
00355     const P1& iP1, const P2& iP2, const P3& iP3, const P4& iP4, const P5& iP5, const P6& iP6, const P7& iP7, const P8& iP8, const P9& iP9, const P10& iP10, const P11& iP11, const P12& iP12, const P13& iP13, const P14& iP14, const P15& iP15,
00356     ThreadKind kind = threadDetached);
00357 
00358 
00359 }
00360 
00361 }
00362 
00363 #include "thread_fun.inl"
00364 
00365 #endif
00366 
00367 // EOF

Generated on Mon Nov 10 14:21:40 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo