Flow123d  release_3.0.0-506-g34af125
range_wrapper.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file range_wrapper.hh
15  * @brief Implementation of range helper class.
16  */
17 
18 #ifndef RANGE_WRAPPER_HH_
19 #define RANGE_WRAPPER_HH_
20 
21 #include "mesh/mesh.h"
23 
24 /**
25  * @brief Range helper class.
26  *
27  * Allow iterate in bounds given by begin and end range. Class can be used for iterable accessor classes.
28  */
29 template<class Object>
30 class Range
31 {
32 public:
33  Range(const Mesh * mesh, unsigned int begin, unsigned int end)
34  : mesh_(mesh), begin_(begin), end_(end) {
35  ASSERT_LE(begin, end).error("Invalid range, begin is greater than end!");
36  }
37 
39  return make_iter<Object>( Object(mesh_, begin_) );
40  }
41 
43  return make_iter<Object>( Object(mesh_, end_) );
44  }
45 
46  inline unsigned int size() const {
47  return end_ - begin_;
48  }
49 private:
50  const Mesh * mesh_;
51  unsigned int begin_;
52  unsigned int end_;
53 };
54 
55 #endif // RANGE_WRAPPER_HH_
const Mesh * mesh_
unsigned int end_
Range helper class.
Definition: mesh.h:52
Definition: mesh.h:80
Template Iter serves as general template for internal iterators.
#define ASSERT_LE(a, b)
Definition of comparative assert macro (Less or Equal)
Definition: asserts.hh:303
unsigned int begin_
Iter< Object > end()
General iterator template. Provides iterator over objects in some container.
Range(const Mesh *mesh, unsigned int begin, unsigned int end)
Iter< Object > begin()
unsigned int size() const