Loading...
Searching...
No Matches
piercedKernelRange.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_RANGE_TPP__
26#define __BITPIT_PIERCED_KERNEL_RANGE_TPP__
27
28namespace bitpit {
29
33template<typename id_t>
35 : m_cbegin(),
36 m_cend()
37{
38}
39
45template<typename id_t>
47{
48 initialize(kernel);
49}
50
58template<typename id_t>
59PiercedKernelRange<id_t>::PiercedKernelRange(const kernel_t *kernel, id_t first, id_t last)
60{
61 initialize(kernel, first, last);
62}
63
70template<typename id_t>
73 initialize(begin, end);
74}
81template<typename id_t>
84 m_cbegin = kernel->cbegin();
85 m_cend = kernel->cend();
95template<typename id_t>
96void PiercedKernelRange<id_t>::initialize(const kernel_t *kernel, id_t first, id_t last)
97{
98 m_cbegin = kernel->find(first);
99 m_cend = ++(kernel->find(last));
100}
101
108template<typename id_t>
110{
111 if (&(begin.getKernel()) != &(end.getKernel())) {
112 throw std::runtime_error("The two iterators belong to different kernels");
113 }
114
115 m_cbegin = begin;
116 m_cend = end;
117}
118
124template<typename id_t>
126{
127 std::swap(m_cbegin, other.m_cbegin);
128 std::swap(m_cend, other.m_cend);
129}
130
136template<typename id_t>
138{
139 const PiercedKernel<id_t> &kernel = m_cbegin.getKernel();
140
141 std::size_t flatBegin = kernel.evalFlatIndex(m_cbegin.getId());
142
143 std::size_t flatEnd;
144 if (m_cend.getPos() <= kernel.getLastUsedPos()) {
145 flatEnd = kernel.evalFlatIndex(m_cend.getId()) + 1;
146 } else {
147 flatEnd = kernel.size();
148 }
149
150 std::size_t size = (flatEnd - flatBegin);
151
152 return size;
153}
154
160template<typename id_t>
162{
163 return m_cbegin;
164}
165
173template<typename id_t>
175{
176 return m_cend;
177}
178
184template<typename id_t>
186{
187 return m_cbegin;
188}
189
197template<typename id_t>
199{
200 return m_cend;
201}
202
203}
204
205#endif
Iterator for the class PiercedKernel.
const kernel_type & getKernel() const
The PiercedKernelRange allow to iterate using range-based loops over a PiercedStorage.
const_iterator cend() const noexcept
const_iterator end() const noexcept
void initialize(const kernel_t *kernel)
void swap(PiercedKernelRange &other) noexcept
const_iterator cbegin() const noexcept
const_iterator begin() const noexcept
Metafunction for generating a pierced kernel.
const_iterator cend() const noexcept
const_iterator find(const id_t &id) const noexcept
const_iterator cbegin() const noexcept
std::size_t evalFlatIndex(id_t id) const
std::size_t getLastUsedPos() const
std::size_t size() const
--- layout: doxygen_footer ---