libXDispatch 0.4
include/xdispatch/base.h
Go to the documentation of this file.
00001 
00002 /*
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 #ifndef XDISPATCH_BASE_H_
00024 #define XDISPATCH_BASE_H_
00025 
00026 #ifndef __XDISPATCH_INDIRECT__
00027 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00028 #endif
00029 
00030 #include <string>
00031 
00032 __XDISPATCH_BEGIN_NAMESPACE
00033 
00043 class XDISPATCH_EXPORT operation
00044 {
00045     public:
00046     operation() : auto_del(false){}
00047 
00048     virtual void operator()() = 0;
00054     virtual void set_auto_delete(bool a){ auto_del = a; }
00059     virtual bool auto_delete(){ return auto_del; }
00060 
00061     private:
00062     bool auto_del;
00063 };
00064 
00072 class XDISPATCH_EXPORT iteration_operation
00073 {
00074 public:
00075     iteration_operation() : auto_del(false){}
00076 
00077     virtual void operator()(size_t index) = 0;
00083     virtual void set_auto_delete(bool a){ auto_del = a; }
00088     virtual bool auto_delete(){ return auto_del; }
00089 
00090 private:
00091     bool auto_del;
00092 };
00093 
00098 template <class T>  class ptr_operation : public operation
00099 {
00100 public:
00101     ptr_operation(T* object, void(T::*function)())
00102         : obj(object), func(function) {}
00103     virtual void operator()() {
00104         (*obj.*func)();
00105     }
00106 
00107 private:
00108     T* obj;
00109     void (T::*func)();
00110 };
00111 
00116 template <class T> class  ptr_iteration_operation : public iteration_operation
00117 {
00118 public:
00119     ptr_iteration_operation(T* object, void(T::*function)(size_t))
00120         : obj(object), func(function) {}
00121     virtual void operator()(size_t index) {
00122         (*obj.*func)(index);
00123     }
00124 
00125 private:
00126     T* obj;
00127     void (T::*func)(size_t);
00128 };
00129 
00130 #ifdef XDISPATCH_HAS_BLOCKS
00131 
00135 class block_operation : public operation {
00136 public:
00137     block_operation(dispatch_block_t b) : block(XDISPATCH_BLOCK_COPY(b)) {}
00138     block_operation(const block_operation& other) : block(XDISPATCH_BLOCK_COPY(other.block)) {}
00139     ~block_operation() { XDISPATCH_BLOCK_RELEASE(block); }
00140 
00141     void operator ()(){
00142         block();
00143     };
00144 
00145 private:
00146     dispatch_block_t block;
00147 };
00148 #endif
00149 
00150 
00151 class queue;
00152 
00157 enum queue_priority { HIGH =2, DEFAULT =1, LOW =0 };
00165 XDISPATCH_EXPORT queue main_queue();
00176 XDISPATCH_EXPORT queue global_queue(queue_priority p = DEFAULT);
00181 XDISPATCH_EXPORT queue current_queue();
00185 XDISPATCH_EXPORT dispatch_time_t as_dispatch_time(struct tm*);
00189 XDISPATCH_EXPORT struct tm as_struct_tm(dispatch_time_t t);
00195 XDISPATCH_EXPORT dispatch_time_t as_delayed_time(uint64_t delay, dispatch_time_t base = DISPATCH_TIME_NOW);
00202 XDISPATCH_EXPORT void exec();
00203 
00204 __XDISPATCH_END_NAMESPACE
00205 
00206 #endif /* XDISPATCH_BASE_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.