stored_range.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_STORED_RANGE_H 00021 #define LIBMESH_STORED_RANGE_H 00022 00023 // Local includes 00024 #include "libmesh/threads.h" 00025 00026 // C++ includes 00027 #include <vector> 00028 00029 namespace libMesh 00030 { 00031 00032 00050 template <typename iterator_type, typename object_type> 00051 class StoredRange 00052 { 00053 public: 00057 typedef typename std::vector<object_type>::const_iterator const_iterator; 00058 00064 StoredRange (const unsigned int new_grainsize = 1000) : 00065 _end(), 00066 _begin(), 00067 _last(), 00068 _first(), 00069 _grainsize(new_grainsize), 00070 _objs() 00071 {} 00072 00079 StoredRange (const iterator_type &first, 00080 const iterator_type &last, 00081 const unsigned int new_grainsize = 1000) : 00082 _end(), 00083 _begin(), 00084 _last(), 00085 _first(), 00086 _grainsize(new_grainsize), 00087 _objs() 00088 { 00089 this->reset(first, last); 00090 } 00091 00105 StoredRange (const StoredRange<iterator_type,object_type> &er): 00106 _end(er._end), 00107 _begin(er._begin), 00108 _last(er._last), 00109 _first(er._first), 00110 _grainsize(er._grainsize), 00111 _objs() 00112 { 00113 // specifically, do *not* copy the vector 00114 } 00115 00121 StoredRange (StoredRange<iterator_type,object_type> &r, Threads::split ) : 00122 _end(r._end), 00123 _begin(r._begin), 00124 _last(r._last), 00125 _first(r._first), 00126 _grainsize(r._grainsize), 00127 _objs() 00128 { 00129 const_iterator 00130 beginning = r._begin, 00131 ending = r._end, 00132 middle = beginning + std::distance(beginning, ending)/2u; 00133 00134 r._end = _begin = middle; 00135 00136 std::size_t 00137 first = r._first, 00138 last = r._last, 00139 half = first + (last-first)/2u; 00140 00141 r._last = _first = half; 00142 } 00143 00149 StoredRange<iterator_type, object_type> & 00150 reset (const iterator_type &first, 00151 const iterator_type &last) 00152 { 00153 _objs.clear(); 00154 00155 for (iterator_type it=first; it!=last; ++it) 00156 _objs.push_back(*it); 00157 00158 _begin = _objs.begin(); 00159 _end = _objs.end(); 00160 00161 _first = 0; 00162 _last = _objs.size(); 00163 00164 return *this; 00165 } 00166 00174 StoredRange<iterator_type, object_type> & reset () 00175 { 00176 _begin = _objs.begin(); 00177 _end = _objs.end(); 00178 00179 _first = 0; 00180 _last = _objs.size(); 00181 00182 return *this; 00183 } 00184 00188 const_iterator begin () const { return _begin; } 00189 00193 const_iterator end () const { return _end; } 00194 00198 std::size_t first_idx () const { return _first; } 00199 00203 std::size_t last_idx () const { return _last; } 00204 00209 std::size_t grainsize () const {return _grainsize;} 00210 00214 void grainsize (const unsigned int &gs) {_grainsize = gs;} 00215 00219 std::size_t size () const { return std::distance(_begin, _end); } 00220 00221 //------------------------------------------------------------------------ 00222 // Methods that implement Range concept 00223 //------------------------------------------------------------------------ 00224 00228 bool empty() const { return (_begin == _end); } 00229 00233 bool is_divisible() const { return this->grainsize() < static_cast<unsigned int>(std::distance(_begin, _end)); } 00234 00235 private: 00236 00237 const_iterator _end; 00238 const_iterator _begin; 00239 std::size_t _last; 00240 std::size_t _first; 00241 std::size_t _grainsize; 00242 std::vector<object_type> _objs; 00243 }; 00244 00245 } // namespace libMesh 00246 00247 #endif // LIBMESH_STORED_RANGE_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: