Loading...
Searching...
No Matches
piercedKernelIterator.tpp
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_TPP__
26#define __BITPIT_PIERCED_KERNEL_ITERATOR_TPP__
27
28namespace bitpit {
29
33template<typename id_t>
35 : m_kernel(nullptr), m_pos(0)
36{
37}
38
43template<typename id_t>
44PiercedKernelIterator<id_t>::PiercedKernelIterator(const kernel_t *kernel, std::size_t pos)
45 : m_kernel(kernel), m_pos(pos)
46{
47}
48
55template<typename id_t>
57{
58 std::swap(m_kernel, other.m_kernel);
59 std::swap(m_pos, other.m_pos);
60}
61
67template<typename id_t>
69{
70 return *m_kernel;
71}
72
79template<typename id_t>
80id_t PiercedKernelIterator<id_t>::getId(const id_t &fallback) const noexcept
81{
82 id_t id;
83 if (m_pos >= m_kernel->m_end_pos) {
84 id = fallback;
85 return id;
86 }
87
88 id = m_kernel->m_ids[m_pos];
89 if (id >= 0) {
90 return id;
91 } else {
92 id = fallback;
93 return id;
94 }
95}
96
102template<typename id_t>
104{
105 return getPos();
106}
107
113template<typename id_t>
114std::size_t PiercedKernelIterator<id_t>::getPos() const noexcept
115{
116 return m_pos;
126template<typename id_t>
129 if (m_pos >= m_kernel->m_end_pos) {
130 return *this;
131 }
132
133 auto basePosItr = m_kernel->m_ids.begin();
134 auto endPosItr = basePosItr + m_kernel->m_end_pos;
135 auto currentPosItr = basePosItr + m_pos + 1;
136
137 while (currentPosItr < endPosItr) {
138 id_t id = *currentPosItr;
139 if (id >= 0) {
140 break;
141 }
142
143 currentPosItr -= id;
144 }
145
146 m_pos = currentPosItr - basePosItr;
147
148 return *this;
149}
150
158template<typename id_t>
160{
161 PiercedKernelIterator tmp(m_kernel, m_pos);
162
163 ++(*this);
164
165 return tmp;
166}
167
175template<typename id_t>
177{
178 if (m_pos <= m_kernel->m_begin_pos) {
179 return *this;
180 }
181
182 auto basePosItr = m_kernel->m_ids.begin();
183 auto beginPosItr = basePosItr + m_kernel->m_begin_pos;
184 auto currentPosItr = basePosItr + m_pos - 1;
185
186 while (currentPosItr > beginPosItr) {
187 id_t id = *currentPosItr;
188 if (id >= 0) {
189 break;
190 }
191
192 --currentPosItr;
193 }
194
195 m_pos = currentPosItr - basePosItr;
196
197 return *this;
198}
199
207template<typename id_t>
209{
210 PiercedKernelIterator tmp(m_kernel, m_pos);
211
212 --(*this);
213
214 return tmp;
215}
216
222template<typename id_t>
224{
225 return m_kernel->m_ids[m_pos];
226}
227
233template<typename id_t>
235{
236 return m_kernel->m_ids[m_pos];
237}
238
239}
240
241#endif
Iterator for the class PiercedKernel.
void swap(PiercedKernelIterator &other) noexcept
std::size_t getPos() const noexcept
PiercedKernelIterator & operator++()
std::size_t getRawIndex() const noexcept
PiercedKernelIterator & operator--()
id_t getId(const id_t &fallback=-1) const noexcept
const kernel_type & getKernel() const
Metafunction for generating a pierced kernel.
--- layout: doxygen_footer ---