Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef XDISPATCH_ONCE_H_
00024 #define XDISPATCH_ONCE_H_
00025
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034
00035 #include <iostream>
00036
00037 __XDISPATCH_BEGIN_NAMESPACE
00038
00039 class operation;
00040
00051 class XDISPATCH_EXPORT once {
00052
00053 public:
00058 once();
00064 once( dispatch_once_t* );
00065
00070 dispatch_once_t* native_once() const;
00071
00083 void operator()(operation&);
00084 #if XDISPATCH_HAS_BLOCKS
00085
00093 inline void operator()(dispatch_block_t b) {
00094 once_block op(b);
00095 operator()( op );
00096 }
00097 #endif
00098 #if XDISPATCH_HAS_FUNCTION
00099
00107 inline void operator()(const lambda_function& b) {
00108 once_function op(b);
00109 operator()( op );
00110 }
00111 #endif
00112
00113 private:
00114 dispatch_once_t _once_obj;
00115 dispatch_once_t* _once;
00116
00117 #if XDISPATCH_HAS_BLOCKS
00118
00119
00120
00121
00122 class once_block : public operation {
00123 public:
00124 once_block(dispatch_block_t b)
00125 : operation(), _block( b ) {}
00126
00127 void operator()() {
00128 _block();
00129 }
00130
00131 private:
00132 dispatch_block_t _block;
00133 };
00134 #endif
00135 #if XDISPATCH_HAS_FUNCTION
00136
00137
00138
00139
00140 class once_function : public operation {
00141 public:
00142 once_function(const lambda_function& b)
00143 : operation(), _function( b ) {}
00144
00145 void operator()() {
00146 _function();
00147 }
00148
00149 private:
00150 const lambda_function& _function;
00151 };
00152 #endif
00153
00154 friend XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once& );
00155 };
00156
00157 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once* );
00158 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once& );
00159
00160 __XDISPATCH_END_NAMESPACE
00161
00164 #endif