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_OPERATION_H_
00024 #define XDISPATCH_OPERATION_H_
00025
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034
00035 #include <string>
00036
00037 __XDISPATCH_BEGIN_NAMESPACE
00038
00048 class XDISPATCH_EXPORT operation
00049 {
00050 public:
00051 operation() : auto_del(true){}
00052 virtual ~operation(){}
00053
00054 virtual void operator()() = 0;
00055
00061 virtual void auto_delete(bool a){ auto_del = a; }
00066 virtual bool auto_delete() const { return auto_del; }
00067
00068 private:
00069 bool auto_del;
00070 };
00071
00079 class XDISPATCH_EXPORT iteration_operation
00080 {
00081 public:
00082 iteration_operation() : auto_del(true){}
00083 virtual ~iteration_operation(){}
00084
00085 virtual void operator()(size_t index) = 0;
00091 virtual void auto_delete(bool a){ auto_del = a; }
00096 virtual bool auto_delete() const { return auto_del; }
00097
00098 private:
00099 bool auto_del;
00100 };
00101
00106 template <class T> class ptr_operation : public operation
00107 {
00108 public:
00109 ptr_operation(T* object, void(T::*function)())
00110 : obj(object), func(function) {}
00111 virtual void operator()() {
00112 (*obj.*func)();
00113 }
00114
00115 private:
00116 T* obj;
00117 void (T::*func)();
00118 };
00119
00124 template <class T> class ptr_iteration_operation : public iteration_operation
00125 {
00126 public:
00127
00128 ptr_iteration_operation(T* object, void(T::*function)(size_t))
00129 : obj(object), func(function) {}
00130 virtual void operator()(size_t index) {
00131 (*obj.*func)(index);
00132 }
00133
00134 private:
00135 T* obj;
00136 void (T::*func)(size_t);
00137 };
00138
00139
00140 #if XDISPATCH_HAS_BLOCKS
00141
00145 class block_operation : public operation {
00146 public:
00147 block_operation(dispatch_block_t b)
00148 : operation(), _block(Block_copy(b)) {}
00149 block_operation(const block_operation& other)
00150 : operation(other), _block(Block_copy(other._block)) {}
00151 ~block_operation() {
00152 Block_release(_block);
00153 }
00154
00155 void operator ()(){
00156 _block();
00157 };
00158
00159 private:
00160 dispatch_block_t _block;
00161 };
00162
00167 class block_iteration_operation : public iteration_operation {
00168 public:
00169 block_iteration_operation(dispatch_iteration_block_t b)
00170 : iteration_operation(), _block(Block_copy(b)) {}
00171 block_iteration_operation(const block_iteration_operation& other)
00172 : iteration_operation(other), _block(Block_copy(other._block)) {}
00173 ~block_iteration_operation() { Block_release(_block); }
00174
00175 void operator ()(size_t index){
00176 _block(index);
00177 };
00178
00179 private:
00180 dispatch_iteration_block_t _block;
00181 };
00182 #endif // XDISPATCH_HAS_BLOCKS
00183
00184 #if XDISPATCH_HAS_FUNCTION
00185
00189 class function_operation : public operation {
00190 public:
00191 function_operation(const lambda_function& b)
00192 : operation(), _function(b) {}
00193 function_operation(const function_operation& other)
00194 : operation(other), _function(other._function) {}
00195 ~function_operation() {}
00196
00197 void operator ()(){
00198 _function();
00199 };
00200
00201 private:
00202 lambda_function _function;
00203 };
00204
00209 class function_iteration_operation : public iteration_operation {
00210 public:
00211 function_iteration_operation(const iteration_lambda_function b)
00212 : iteration_operation(), _function(b) {}
00213 function_iteration_operation(const function_iteration_operation& other)
00214 : iteration_operation(other), _function(other._function) {}
00215 ~function_iteration_operation() {}
00216
00217 void operator ()(size_t index){
00218 _function(index);
00219 };
00220
00221 private:
00222 iteration_lambda_function _function;
00223 };
00224 #endif // XDISPATCH_HAS_FUNCTION
00225
00226 __XDISPATCH_END_NAMESPACE
00227
00230 #endif