XDispatch 0.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
once.h
Go to the documentation of this file.
00001 
00002 /*
00003 * Copyright (c) 2011-2012 MLBA-Team. 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_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         // we define our own block class
00119         // as the block_operation does a
00120         // copy of the stored block, something
00121         // we do not need in here
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         // we define our own function class
00137         // as the function_operation does a
00138         // copy of the stored block, something
00139         // we do not need in here
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 /* XDISPATCH_ONCE_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Oct 28 2012 22:12:47 for XDispatch by Doxygen 1.7.6.1
© 2010-2012 MLBA (about | privacy) All Rights reserved.