qtconcurrentfunctionwrappers.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtCore module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QTCONCURRENT_FUNCTIONWRAPPERS_H
00043 #define QTCONCURRENT_FUNCTIONWRAPPERS_H
00044 
00045 #include <QtCore/qglobal.h>
00046 
00047 #ifndef QT_NO_CONCURRENT
00048 
00049 QT_BEGIN_HEADER
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Core)
00053 
00054 #ifndef qdoc
00055 
00056 namespace QtConcurrent {
00057 
00058 template <typename T>
00059 class FunctionWrapper0
00060 {
00061 public:
00062     typedef T (*FunctionPointerType)();
00063     typedef T result_type;
00064     inline FunctionWrapper0(FunctionPointerType _functionPointer)
00065     :functionPointer(_functionPointer) { }
00066 
00067     inline T operator()()
00068     {
00069         return functionPointer();
00070     }
00071 private:
00072     FunctionPointerType functionPointer;
00073 };
00074 
00075 template <typename T, typename U>
00076 class FunctionWrapper1
00077 {
00078 public:
00079     typedef T (*FunctionPointerType)(U u);
00080     typedef T result_type;
00081     inline FunctionWrapper1(FunctionPointerType _functionPointer)
00082     :functionPointer(_functionPointer) { }
00083 
00084     inline T operator()(U u)
00085     {
00086         return functionPointer(u);
00087     }
00088 
00089 private:
00090     FunctionPointerType functionPointer;
00091 };
00092 
00093 template <typename T, typename U, typename V>
00094 class FunctionWrapper2
00095 {
00096 public:
00097     typedef T (*FunctionPointerType)(U u, V v);
00098     typedef T result_type;
00099     inline FunctionWrapper2(FunctionPointerType _functionPointer)
00100     :functionPointer(_functionPointer) { }
00101 
00102     inline T operator()(U u, V v)
00103     {
00104         return functionPointer(u, v);
00105     }
00106 private:
00107     FunctionPointerType functionPointer;
00108 };
00109 
00110 template <typename T, typename C>
00111 class MemberFunctionWrapper
00112 {
00113 public:
00114     typedef T (C::*FunctionPointerType)();
00115     typedef T result_type;
00116     inline MemberFunctionWrapper(FunctionPointerType _functionPointer)
00117     :functionPointer(_functionPointer) { }
00118 
00119     inline T operator()(C &c)
00120     {
00121         return (c.*functionPointer)();
00122     }
00123 private:
00124     FunctionPointerType functionPointer;
00125 };
00126 
00127 template <typename T, typename C, typename U>
00128 class MemberFunctionWrapper1
00129 {
00130 public:
00131     typedef T (C::*FunctionPointerType)(U);
00132     typedef T result_type;
00133 
00134     inline MemberFunctionWrapper1(FunctionPointerType _functionPointer)
00135         : functionPointer(_functionPointer)
00136     { }
00137 
00138     inline T operator()(C &c, U u)
00139     {
00140         return (c.*functionPointer)(u);
00141     }
00142 
00143 private:
00144     FunctionPointerType functionPointer;
00145 };
00146 
00147 template <typename T, typename C>
00148 class ConstMemberFunctionWrapper
00149 {
00150 public:
00151     typedef T (C::*FunctionPointerType)() const;
00152     typedef T result_type;
00153     inline ConstMemberFunctionWrapper(FunctionPointerType _functionPointer)
00154     :functionPointer(_functionPointer) { }
00155 
00156     inline T operator()(const C &c) const
00157     {
00158         return (c.*functionPointer)();
00159     }
00160 private:
00161     FunctionPointerType functionPointer;
00162 };
00163 
00164 } // namespace QtConcurrent.
00165 
00166 #endif //qdoc
00167 
00168 QT_END_NAMESPACE
00169 QT_END_HEADER
00170 
00171 #endif // QT_NO_CONCURRENT
00172 
00173 #endif