00001 /* 00002 * Copyright (c) 2011-2012 MLBA-Team. All rights reserved. 00003 * 00004 * @MLBA_OPEN_LICENSE_HEADER_START@ 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 * 00018 * @MLBA_OPEN_LICENSE_HEADER_END@ 00019 */ 00020 00021 00022 00023 #ifndef QITERATIONBLOCKRUNNABLE_H_ 00024 #define QITERATIONBLOCKRUNNABLE_H_ 00025 00026 #include "qiterationrunnable.h" 00027 00028 #include "qdispatchglobal.h" 00029 00035 QT_BEGIN_HEADER 00036 QT_BEGIN_NAMESPACE 00037 00038 QT_MODULE(Dispatch) 00039 00040 #if XDISPATCH_HAS_BLOCKS 00041 00048 class Q_DISPATCH_EXPORT QIterationBlockRunnable : public QIterationRunnable { 00049 00050 public: 00058 QIterationBlockRunnable(dispatch_iteration_block_t b) 00059 : QIterationRunnable(), _block(Block_copy(b)) {} 00060 QIterationBlockRunnable(const QIterationBlockRunnable& other) 00061 : QIterationRunnable(other), _block(Block_copy(other._block)) {} 00062 virtual ~QIterationBlockRunnable() { Block_release(_block); } 00063 00064 virtual inline void run(size_t index){ 00065 _block(index); 00066 }; 00067 00068 private: 00069 dispatch_iteration_block_t _block; 00070 00071 }; 00072 #endif 00073 #if XDISPATCH_HAS_FUNCTION 00074 00081 class Q_DISPATCH_EXPORT QIterationLambdaRunnable : public QIterationRunnable { 00082 00083 public: 00091 QIterationLambdaRunnable(const xdispatch::iteration_lambda_function& b) 00092 : QIterationRunnable(), _function(b) {} 00093 QIterationLambdaRunnable(const QIterationLambdaRunnable& other) 00094 : QIterationRunnable(other), _function(other._function) {} 00095 virtual ~QIterationLambdaRunnable() { } 00096 00097 virtual inline void run(size_t index){ 00098 _function(index); 00099 } 00100 00101 private: 00102 xdispatch::iteration_lambda_function _function; 00103 00104 }; 00105 #endif 00106 00107 00108 QT_END_NAMESPACE 00109 QT_END_HEADER 00110 00113 #endif /* QITERATIONBLOCKRUNNABLE_H_ */