Loading...
Searching...
No Matches
piercedKernelIterator.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_PIERCED_KERNEL_ITERATOR_HPP__
26#define __BITPIT_PIERCED_KERNEL_ITERATOR_HPP__
27
28#include <cassert>
29#include <iterator>
30#include <limits>
31#include <type_traits>
32
33namespace bitpit{
34
35template<typename id_t>
36class PiercedKernel;
37
45template<typename id_t = long>
47{
48
49template<typename PK_id_t>
50friend class PiercedKernel;
51
52template<typename PSI_value_t, typename PSI_id_t, typename PSI_value_no_cv_t>
53friend class PiercedStorageIterator;
54
55private:
59 template<typename PK_id_t>
60 using Kernel = PiercedKernel<PK_id_t>;
61
68 typedef Kernel<id_t> kernel_t;
69
70public:
74 using iterator_category = std::bidirectional_iterator_tag;
75
79 using value_type = id_t;
80
84 using difference_type = std::ptrdiff_t;
85
89 using pointer = id_t *;
90
94 using reference = id_t &;
95
99 typedef kernel_t kernel_type;
100
104 typedef id_t id_type;
105
106 // Constructors
108
109 // General methods
110 void swap(PiercedKernelIterator& other) noexcept;
111
112 const kernel_type & getKernel() const;
113
114 // Methos to extract information on the current element
115 id_t getId(const id_t &fallback = -1) const noexcept;
116 std::size_t getRawIndex() const noexcept;
117 std::size_t getPos() const noexcept;
118
119 // Operators
121 PiercedKernelIterator operator++(int);
122
124 PiercedKernelIterator operator--(int);
125
126 const id_t & operator*() const;
127 const id_t * operator->() const;
128
132 bool operator==(const PiercedKernelIterator &rhs) const
133 {
134 return (m_kernel == rhs.m_kernel) && (m_pos == rhs.m_pos);
135 }
136
140 bool operator!=(const PiercedKernelIterator &rhs) const
141 {
142 return (m_kernel != rhs.m_kernel) || (m_pos != rhs.m_pos);
143 }
144
145private:
149 const kernel_t *m_kernel;
150
154 std::size_t m_pos;
155
156 // Constructors
157 explicit PiercedKernelIterator(const kernel_t *kernel, std::size_t pos);
158
159};
160
161}
162
163// Include the implementation
164#include "piercedKernelIterator.tpp"
165
166#endif
std::bidirectional_iterator_tag iterator_category
bool operator!=(const PiercedKernelIterator &rhs) const
void swap(PiercedKernelIterator &other) noexcept
std::size_t getPos() const noexcept
std::size_t getRawIndex() const noexcept
id_t getId(const id_t &fallback=-1) const noexcept
const kernel_type & getKernel() const
Metafunction for generating a pierced kernel.