stored_range.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_STORED_RANGE_H
21 #define LIBMESH_STORED_RANGE_H
22 
23 // Local includes
24 #include "libmesh/threads.h"
25 
26 // C++ includes
27 #include <vector>
28 
29 namespace libMesh
30 {
31 
32 
50 template <typename iterator_type, typename object_type>
52 {
53 public:
57  typedef typename std::vector<object_type>::const_iterator const_iterator;
58 
64  StoredRange (const unsigned int new_grainsize = 1000) :
65  _end(),
66  _begin(),
67  _last(),
68  _first(),
69  _grainsize(new_grainsize),
70  _objs()
71  {}
72 
79  StoredRange (const iterator_type &first,
80  const iterator_type &last,
81  const unsigned int new_grainsize = 1000) :
82  _end(),
83  _begin(),
84  _last(),
85  _first(),
86  _grainsize(new_grainsize),
87  _objs()
88  {
89  this->reset(first, last);
90  }
91 
106  _end(er._end),
107  _begin(er._begin),
108  _last(er._last),
109  _first(er._first),
111  _objs()
112  {
113  // specifically, do *not* copy the vector
114  }
115 
134  const const_iterator &begin_range,
135  const const_iterator &end_range):
136  _end(end_range),
137  _begin(begin_range),
138  _last(0), // Initialize these in a moment
139  _first(0),
141  _objs()
142  {
143  // specifically, do *not* copy the vector
144 
145  _first = std::distance(er._begin, _begin);
146  _last = _first + std::distance(_begin, _end);
147  }
148 
155  _end(r._end),
156  _begin(r._begin),
157  _last(r._last),
158  _first(r._first),
160  _objs()
161  {
163  beginning = r._begin,
164  ending = r._end,
165  middle = beginning + std::distance(beginning, ending)/2u;
166 
167  r._end = _begin = middle;
168 
169  std::size_t
170  first = r._first,
171  last = r._last,
172  half = first + (last-first)/2u;
173 
174  r._last = _first = half;
175  }
176 
183  reset (const iterator_type &first,
184  const iterator_type &last)
185  {
186  _objs.clear();
187 
188  for (iterator_type it=first; it!=last; ++it)
189  _objs.push_back(*it);
190 
191  _begin = _objs.begin();
192  _end = _objs.end();
193 
194  _first = 0;
195  _last = _objs.size();
196 
197  return *this;
198  }
199 
208  {
209  _begin = _objs.begin();
210  _end = _objs.end();
211 
212  _first = 0;
213  _last = _objs.size();
214 
215  return *this;
216  }
217 
221  const_iterator begin () const { return _begin; }
222 
226  const_iterator end () const { return _end; }
227 
231  std::size_t first_idx () const { return _first; }
232 
236  std::size_t last_idx () const { return _last; }
237 
242  std::size_t grainsize () const {return _grainsize;}
243 
247  void grainsize (const unsigned int &gs) {_grainsize = gs;}
248 
252  std::size_t size () const { return std::distance(_begin, _end); }
253 
254  //------------------------------------------------------------------------
255  // Methods that implement Range concept
256  //------------------------------------------------------------------------
257 
261  bool empty() const { return (_begin == _end); }
262 
266  bool is_divisible() const { return this->grainsize() < static_cast<unsigned int>(std::distance(_begin, _end)); }
267 
268 private:
269 
272  std::size_t _last;
273  std::size_t _first;
274  std::size_t _grainsize;
275  std::vector<object_type> _objs;
276 };
277 
278 } // namespace libMesh
279 
280 #endif // LIBMESH_STORED_RANGE_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo