libXDispatch 0.4
include/xdispatch/lambda_blocks.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
00003 * Copyright (c) 2011 MLBA. All rights reserved.
00004 *
00005 * @MLBA_OPEN_LICENSE_HEADER_START@
00006 *
00007 * Licensed under the Apache License, Version 2.0 (the "License");
00008 * you may not use this file except in compliance with the License.
00009 * You may obtain a copy of the License at
00010 * 
00011 *     http://www.apache.org/licenses/LICENSE-2.0
00012 * 
00013 * Unless required by applicable law or agreed to in writing, software
00014 * distributed under the License is distributed on an "AS IS" BASIS,
00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 * See the License for the specific language governing permissions and
00017 * limitations under the License.
00018 *
00019 * @MLBA_OPEN_LICENSE_HEADER_END@
00020 */
00021 
00022 
00023 /* When building on 10.6 with gcc 4.5.1 we can bypass
00024     Apple's lambda functions implementation in C++ as we have lambdas.
00025        This prevents a lot of errors from occuring
00026        */
00027 
00028 #ifndef XDISPATCH_BLOCKS_H_
00029 #define XDISPATCH_BLOCKS_H_
00030 
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034 
00091 // clang 2.0, gcc 4.3 from mac os 10.6
00092 #ifdef __BLOCKS__
00093 
00094 # include <Block.h>
00095 # include <stddef.h>
00096 # define XDISPATCH_BLOCK ^
00097 # ifndef XDISPATCH_NO_KEYWORDS
00098 #  define $ ^
00099 # endif
00100 # define XDISPATCH_BLOCK_COPY(A) Block_copy(A)
00101 # define XDISPATCH_BLOCK_RELEASE(A) Block_release(A)
00102   //typedef void (^dispatch_block_t)(void);
00103   typedef void (^dispatch_iteration_block_t)(size_t);
00104 # define XDISPATCH_HAS_BLOCKS
00105 # if defined(__cplusplus) && !defined(__clang__)
00106 #  warning "Sadly blocks are currently broken in C++ on this platform, we recommend using gcc 4.5.1 or clang 2.0 instead"
00107 # endif
00108 
00109 // visual studio 2010
00110 #elif _MSC_VER >= 1600
00111 
00112 # include <functional>
00113 # define XDISPATCH_BLOCK [=]
00114 # ifndef XDISPATCH_NO_KEYWORDS
00115 #  define $ [=]
00116 # endif
00117 # define XDISPATCH_BLOCK_COPY(A) A
00118 # define Block_copy(A) XDISPATCH_BLOCK_COPY(A)
00119 # define XDISPATCH_BLOCK_RELEASE(A) {}
00120 # define Block_release(A) XDISPATCH_BLOCK_RELEASE(A)
00121  typedef std::tr1::function< void (void) > dispatch_block_t;
00122  typedef std::tr1::function< void (size_t) > dispatch_iteration_block_t;
00123 # define XDISPATCH_HAS_BLOCKS
00124 
00125 // gcc 4.5 with c++0x enabled
00126 #elif defined __GXX_EXPERIMENTAL_CXX0X__
00127 
00128 # include <tr1/functional>
00129 # define XDISPATCH_BLOCK [=]
00130 # ifndef XDISPATCH_NO_KEYWORDS
00131 #  define $ [=]
00132 # endif
00133 # define XDISPATCH_BLOCK_COPY(A) A
00134 # define Block_copy(A) XDISPATCH_BLOCK_COPY(A)
00135 # define XDISPATCH_BLOCK_RELEASE(A) {}
00136 # define Block_release(A) XDISPATCH_BLOCK_RELEASE(A)
00137  typedef std::tr1::function< void (void) > dispatch_block_t;
00138  typedef std::tr1::function< void (size_t) > dispatch_iteration_block_t;
00139 # define XDISPATCH_HAS_BLOCKS
00140 
00141 #else
00142 
00143 # define XDISPATCH_BLOCK "No Block support!"
00144 
00145 #endif
00146 
00147 #if defined(XDISPATCH_HAS_BLOCKS) && !defined(__BLOCKS__)
00148 
00149 #ifndef XDISPATCH_EXPORT
00150 # ifdef _WIN32
00151 #  ifdef XDISPATCH_MAKEDLL
00152 #   define XDISPATCH_EXPORT __declspec(dllexport)
00153 #  else
00154 #   define XDISPATCH_EXPORT __declspec(dllimport)
00155 #  endif
00156 # else
00157 #  define XDISPATCH_EXPORT __attribute__((visibility("default")))
00158 # endif
00159 #endif
00160 
00161 XDISPATCH_EXPORT void dispatch_async(dispatch_queue_t queue, dispatch_block_t function);
00162 
00163 XDISPATCH_EXPORT void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t function);
00164 
00165 XDISPATCH_EXPORT void dispatch_sync(dispatch_queue_t queue, dispatch_block_t function);
00166 
00167 XDISPATCH_EXPORT void dispatch_apply(size_t iterations, dispatch_queue_t queue, dispatch_iteration_block_t function);
00168 
00169 XDISPATCH_EXPORT void dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t function);
00170 
00171 XDISPATCH_EXPORT void dispatch_group_notify(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);
00172 
00173 XDISPATCH_EXPORT void dispatch_source_set_event_handler(dispatch_source_t source, dispatch_block_t handler);
00174 
00175 XDISPATCH_EXPORT void dispatch_source_set_cancel_handler(dispatch_source_t source, dispatch_block_t cancel_handler);
00176 
00177 XDISPATCH_EXPORT void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
00178 
00179 #endif
00180 
00181 #endif /* XDISPATCH_BLOCKS_H_ */

Generated on Wed Feb 22 2012 19:51:17 for libXDispatch by Doxygen 1.7.4
Content © 2011-2012 MLBA (about | privacy) – Design © 2010-2012 Emzeat. All Rights reserved.