![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 #ifndef __TBB_blocked_range_H 00030 #define __TBB_blocked_range_H 00031 00032 #include "tbb_stddef.h" 00033 00034 namespace tbb { 00035 00045 00046 00047 template<typename Value> 00048 class blocked_range { 00049 public: 00051 00053 typedef Value const_iterator; 00054 00056 typedef std::size_t size_type; 00057 00059 00060 blocked_range() : my_end(), my_begin() {} 00061 00063 blocked_range( Value begin_, Value end_, size_type grainsize_=1 ) : 00064 my_end(end_), my_begin(begin_), my_grainsize(grainsize_) 00065 { 00066 __TBB_ASSERT( my_grainsize>0, "grainsize must be positive" ); 00067 } 00068 00070 const_iterator begin() const {return my_begin;} 00071 00073 const_iterator end() const {return my_end;} 00074 00076 00077 size_type size() const { 00078 __TBB_ASSERT( !(end()<begin()), "size() unspecified if end()<begin()" ); 00079 return size_type(my_end-my_begin); 00080 } 00081 00083 size_type grainsize() const {return my_grainsize;} 00084 00085 //------------------------------------------------------------------------ 00086 // Methods that implement Range concept 00087 //------------------------------------------------------------------------ 00088 00090 bool empty() const {return !(my_begin<my_end);} 00091 00093 00094 bool is_divisible() const {return my_grainsize<size();} 00095 00097 00099 blocked_range( blocked_range& r, split ) : 00100 my_end(r.my_end), 00101 my_begin(do_split(r)), 00102 my_grainsize(r.my_grainsize) 00103 {} 00104 00105 private: 00107 Value my_end; 00108 Value my_begin; 00109 size_type my_grainsize; 00110 00112 00113 static Value do_split( blocked_range& r ) { 00114 __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" ); 00115 Value middle = r.my_begin + (r.my_end-r.my_begin)/2u; 00116 r.my_end = middle; 00117 return middle; 00118 } 00119 00120 template<typename RowValue, typename ColValue> 00121 friend class blocked_range2d; 00122 00123 template<typename RowValue, typename ColValue, typename PageValue> 00124 friend class blocked_range3d; 00125 }; 00126 00127 } // namespace tbb 00128 00129 #endif /* __TBB_blocked_range_H */
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.