XDispatch 0.6.1
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 # include <Block.h>
00094 # include <stddef.h>
00095 # define XDISPATCH_BLOCK ^
00096 # ifndef XDISPATCH_NO_KEYWORDS
00097 #  define $ ^
00098 # endif
00099 # define XDISPATCH_BLOCK_PERSIST(A) Block_copy(A)
00100 # define XDISPATCH_BLOCK_COPY(A) Block_copy(A)
00101 # define XDISPATCH_BLOCK_DELETE(A) Block_release(A)
00102 # define XDISPATCH_BLOCK_EXEC(A) (A)
00103   //typedef void (^dispatch_block_t)(void);
00104  typedef void (^dispatch_iteration_block_t)(size_t);
00105  typedef dispatch_block_t dispatch_block_store;
00106  typedef dispatch_iteration_block_t dispatch_iteration_block_store;
00107 # define XDISPATCH_HAS_BLOCKS
00108 # if defined(__cplusplus) && !defined(__clang__)
00109 #  warning "Sadly blocks are currently broken in C++ on this platform, we recommend using gcc 4.5.1 or clang 2.0 instead"
00110 # endif
00111 
00112 // visual studio 2010
00113 #elif _MSC_VER >= 1600
00114 
00115 # include <functional>
00116 # define XDISPATCH_BLOCK [=]
00117 # ifndef XDISPATCH_NO_KEYWORDS
00118 #  define $ [=]
00119 # endif
00120 # define XDISPATCH_BLOCK_PERSIST(A) (A)
00121 # define XDISPATCH_BLOCK_COPY(A) (A)
00122 # define XDISPATCH_BLOCK_DELETE(A) {}
00123 # define XDISPATCH_BLOCK_EXEC(A) (A)
00124  typedef const std::tr1::function< void (void) >& dispatch_block_t;
00125  typedef const std::tr1::function< void (size_t) >& dispatch_iteration_block_t;
00126  typedef std::tr1::function< void (void) > dispatch_block_store;
00127  typedef std::tr1::function< void (size_t) > dispatch_iteration_block_store;
00128 # define XDISPATCH_HAS_BLOCKS
00129 
00130 // gcc 4.5 with c++0x enabled
00131 #elif defined __GXX_EXPERIMENTAL_CXX0X__
00132 
00133 # include <tr1/functional>
00134 # define XDISPATCH_BLOCK [=]
00135 # ifndef XDISPATCH_NO_KEYWORDS
00136 #  define $ [=]
00137 # endif
00138 # define XDISPATCH_BLOCK_PERSIST(A) (A)
00139 # define XDISPATCH_BLOCK_COPY(A) (A)
00140 # define XDISPATCH_BLOCK_DELETE(A) {}
00141 # define XDISPATCH_BLOCK_EXEC(A) (A)
00142  typedef const std::tr1::function< void (void) >& dispatch_block_t;
00143  typedef const std::tr1::function< void (size_t) >& dispatch_iteration_block_t;
00144  typedef std::tr1::function< void (void) > dispatch_block_store;
00145  typedef std::tr1::function< void (size_t) > dispatch_iteration_block_store;
00146 # define XDISPATCH_HAS_BLOCKS
00147 
00148 #else
00149 
00150 # define XDISPATCH_BLOCK "No Block support!"
00151 
00152 #endif
00153 
00154 #if defined(XDISPATCH_HAS_BLOCKS) && !defined(__BLOCKS__)
00155 
00156 #ifndef XDISPATCH_EXPORT
00157 # ifdef _WIN32
00158 #  ifdef XDISPATCH_MAKEDLL
00159 #   define XDISPATCH_EXPORT __declspec(dllexport)
00160 #  else
00161 #   define XDISPATCH_EXPORT __declspec(dllimport)
00162 #  endif
00163 # else
00164 #  define XDISPATCH_EXPORT __attribute__((visibility("default")))
00165 # endif
00166 #endif
00167 
00168 XDISPATCH_EXPORT void dispatch_async(dispatch_queue_t queue, dispatch_block_t function);
00169 
00170 XDISPATCH_EXPORT void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t function);
00171 
00172 XDISPATCH_EXPORT void dispatch_sync(dispatch_queue_t queue, dispatch_block_t function);
00173 
00174 XDISPATCH_EXPORT void dispatch_apply(size_t iterations, dispatch_queue_t queue, dispatch_iteration_block_t function);
00175 
00176 XDISPATCH_EXPORT void dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t function);
00177 
00178 XDISPATCH_EXPORT void dispatch_group_notify(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block);
00179 
00180 XDISPATCH_EXPORT void dispatch_source_set_event_handler(dispatch_source_t source, dispatch_block_t handler);
00181 
00182 XDISPATCH_EXPORT void dispatch_source_set_cancel_handler(dispatch_source_t source, dispatch_block_t cancel_handler);
00183 
00184 XDISPATCH_EXPORT void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
00185 
00186 #endif
00187 
00188 #endif /* XDISPATCH_BLOCKS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Thu Apr 12 2012 09:50:43 for XDispatch by Doxygen 1.7.4
© 2010-2012 MLBA (about | privacy) All Rights reserved.