opm-grid
Loading...
Searching...
No Matches
IteratorRange.hpp
1/*
2 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
3 Copyright 2009, 2010 Statoil ASA.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef OPM_ITERATOR_RANGE_HEADER
21#define OPM_ITERATOR_RANGE_HEADER
22
23#include <iterator>
24#include <type_traits>
25
26#if HAVE_OPM_COMMON
27#include <opm/common/utility/gpuDecorators.hpp>
28#else
29#define OPM_HOST_DEVICE
30#endif
31
32namespace Opm {
33
34template <class DataType>
35struct iterator_range_pod {
36 OPM_HOST_DEVICE iterator_range_pod(const DataType* begin, const DataType* end) : begin_(begin), end_(end) {}
37 iterator_range_pod() = default;
38
39 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
40 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
41 OPM_HOST_DEVICE bool operator==(const iterator_range_pod<DataType>& rhs) const
42 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
43
44 OPM_HOST_DEVICE const DataType& operator[](int idx) const { return begin_[idx]; }
45
46 OPM_HOST_DEVICE const DataType* begin() const { return begin_; }
47 OPM_HOST_DEVICE const DataType* end() const { return end_; }
48
49protected:
50 const DataType* begin_;
51 const DataType* end_;
52
53};
54
55template <class Iter>
56struct iterator_range {
57 OPM_HOST_DEVICE iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
58 iterator_range() = default;
59
60 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
61 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
62 OPM_HOST_DEVICE bool operator==(const iterator_range<Iter>& rhs) const
63 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
64
65 OPM_HOST_DEVICE const typename Iter::value_type& operator[](int idx) const
66 { return *(begin_+ idx); }
67
68 OPM_HOST_DEVICE Iter begin() const { return begin_; }
69 OPM_HOST_DEVICE Iter end() const { return end_; }
70
71protected:
72 Iter begin_, end_;
73};
74
75template<typename Iter>
76struct mutable_iterator_range {
77 OPM_HOST_DEVICE mutable_iterator_range(Iter begin, Iter end) : begin_(begin), end_(end) {}
78 mutable_iterator_range() = default;
79
80 OPM_HOST_DEVICE size_t size() const { return std::distance(begin_,end_); }
81 OPM_HOST_DEVICE bool empty() const { return begin_ == end_; }
82 OPM_HOST_DEVICE bool operator==(const Iter& rhs) const
83 { return (begin_ == rhs.begin_) && (end_ == rhs.end_); }
84
85 OPM_HOST_DEVICE typename Iter::value_type& operator[](int idx)
86 { return begin_[idx]; }
87
88 OPM_HOST_DEVICE Iter begin() const { return begin_; }
89 OPM_HOST_DEVICE Iter end() const { return end_; }
90
91protected:
92 Iter begin_, end_;
93};
94
95}
96
97#endif // OPM_ITERATOR_RANGE_HEADER
Holds the implementation of the CpGrid as a pimple.
Definition CellQuadrature.cpp:71