libXDispatch 0.3.1
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 "dispatch.h"
00031 
00032 #include <string>
00033 
00034 __XDISPATCH_BEGIN_NAMESPACE
00035 
00045 class XDISPATCH_EXPORT operation
00046 {
00047     public:
00048     operation() : auto_del(false){}
00049 
00050     virtual void operator()() = 0;
00056     virtual void set_auto_delete(bool a){ auto_del = a; }
00061     virtual bool auto_delete(){ return auto_del; }
00062 
00063     private:
00064     bool auto_del;
00065 };
00066 
00074 class XDISPATCH_EXPORT iteration_operation
00075 {
00076 public:
00077     iteration_operation() : auto_del(false){}
00078 
00079     virtual void operator()(size_t index) = 0;
00085     virtual void set_auto_delete(bool a){ auto_del = a; }
00090     virtual bool auto_delete(){ return auto_del; }
00091 
00092 private:
00093     bool auto_del;
00094 };
00095 
00100 template <class T>  class ptr_operation : public operation
00101 {
00102 public:
00103     ptr_operation(T* object, void(T::*function)())
00104         : obj(object), func(function) {}
00105     virtual void operator()() {
00106         (*obj.*func)();
00107     }
00108 
00109 private:
00110     T* obj;
00111     void (T::*func)();
00112 };
00113 
00118 template <class T> class  ptr_iteration_operation : public iteration_operation
00119 {
00120 public:
00121     ptr_iteration_operation(T* object, void(T::*function)(size_t))
00122         : obj(object), func(function) {}
00123     virtual void operator()(size_t index) {
00124         (*obj.*func)(index);
00125     }
00126 
00127 private:
00128     T* obj;
00129     void (T::*func)(size_t);
00130 };
00131 
00132 
00133 class queue;
00134 
00139 enum queue_priority { HIGH =2, DEFAULT =1, LOW =0 };
00147 XDISPATCH_EXPORT queue main_queue();
00158 XDISPATCH_EXPORT queue global_queue(queue_priority p = DEFAULT);
00163 XDISPATCH_EXPORT queue current_queue();
00167 XDISPATCH_EXPORT dispatch_time_t as_dispatch_time(struct tm*);
00171 XDISPATCH_EXPORT struct tm as_struct_tm(dispatch_time_t t);
00177 XDISPATCH_EXPORT dispatch_time_t as_delayed_time(uint64_t delay, dispatch_time_t base = DISPATCH_TIME_NOW);
00184 XDISPATCH_EXPORT void exec();
00185 
00186 __XDISPATCH_END_NAMESPACE
00187 
00188 #endif /* XDISPATCH_BASE_H_ */

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