Loading...
Searching...
No Matches
piercedStorageIterator.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_STORAGE_ITERATOR_HPP__
26#define __BITPIT_PIERCED_STORAGE_ITERATOR_HPP__
27
28#include <cassert>
29#include <iterator>
30#include <limits>
31#include <type_traits>
32
33#define __PSI_REFERENCE__ typename PiercedStorageIterator<value_t, id_t, value_no_cv_t>::reference
34#define __PSI_POINTER__ typename PiercedStorageIterator<value_t, id_t, value_no_cv_t>::pointer
35
36namespace bitpit{
37
38template<typename value_t, typename id_t>
39class PiercedStorage;
40
49template<typename value_t, typename id_t = long,
50 typename value_no_cv_t = typename std::remove_cv<value_t>::type>
52 : protected PiercedKernelIterator<id_t>
53{
54
55friend class PiercedStorageIterator<typename std::add_const<value_t>::type, id_t, value_no_cv_t>;
56
57template<typename PS_value_t, typename PS_id_t>
58friend class PiercedStorage;
59
60private:
64 template<typename PS_value_t, typename PS_id_t>
65 using Storage = PiercedStorage<PS_value_t, PS_id_t>;
66
73 typedef
74 typename std::conditional<std::is_const<value_t>::value,
75 const Storage<value_no_cv_t, id_t>,
76 Storage<value_no_cv_t, id_t>
77 >::type
78
79 storage_t;
80
81public:
85 typedef id_t id_type;
86
90 typedef std::bidirectional_iterator_tag iterator_category;
91
95 typedef value_t value_type;
96
100 typedef std::ptrdiff_t difference_type;
101
105 typedef
106 typename std::conditional<std::is_const<value_t>::value,
107 typename Storage<value_no_cv_t, id_t>::const_pointer,
108 typename Storage<value_no_cv_t, id_t>::pointer
109 >::type
110
112
116 typedef
117 typename std::conditional<std::is_const<value_t>::value,
118 typename Storage<value_no_cv_t, id_t>::const_reference,
119 typename Storage<value_no_cv_t, id_t>::reference
120 >::type
121
123
127 typedef storage_t storage_type;
128
129 // Constructors
131
132 template<typename other_value_t, typename std::enable_if<std::is_const<value_t>::value && !std::is_const<other_value_t>::value && std::is_same<other_value_t, typename std::remove_cv<value_t>::type>::value, int>::type = 0>
133 PiercedStorageIterator(const PiercedStorageIterator<other_value_t, id_t, value_no_cv_t> &other);
134
135 // General methods
136 void swap(PiercedStorageIterator& other) noexcept;
137
138 storage_type & getStorage() const;
139
140 const PiercedKernelIterator<id_t> & getKernelIterator() const;
141
142 // Methos to extract information on the current element
145
146 __PSI_REFERENCE__ getValue(std::size_t k = 0) const;
147
148 // Operators
149 PiercedStorageIterator& operator++();
150 PiercedStorageIterator operator++(int);
151
152 PiercedStorageIterator& operator--();
153 PiercedStorageIterator operator--(int);
154
155 __PSI_REFERENCE__ operator*() const;
156 __PSI_POINTER__ operator->() const;
157
158 template<typename other_value_t, typename std::enable_if<std::is_const<value_t>::value && !std::is_const<other_value_t>::value && std::is_same<other_value_t, typename std::remove_cv<value_t>::type>::value, int>::type = 0>
159 PiercedStorageIterator & operator=(const PiercedStorageIterator<other_value_t, id_t, value_no_cv_t> &other);
160
164 bool operator==(const PiercedStorageIterator &rhs) const
165 {
166 return (PiercedKernelIterator<id_t>::operator==(rhs) && m_storage == rhs.m_storage);
167 }
168
172 bool operator!=(const PiercedStorageIterator &rhs) const
173 {
174 return (PiercedKernelIterator<id_t>::operator!=(rhs) || m_storage != rhs.m_storage);
175 }
176
177private:
181 storage_t *m_storage;
182
183 // Constructors
184 explicit PiercedStorageIterator(storage_t *storage, std::size_t pos);
185 explicit PiercedStorageIterator(storage_t *storage, const bitpit::PiercedKernelIterator<id_t> &iterator);
186
187};
188
189}
190
191// Include the implementation
192#include "piercedStorageIterator.tpp"
193
194#endif
Iterator for the class PiercedKernel.
std::size_t getRawIndex() const noexcept
id_t getId(const id_t &fallback=-1) const noexcept
Iterator for the class PiercedStorage.
void swap(PiercedStorageIterator &other) noexcept
std::conditional< std::is_const< value_t >::value, typenameStorage< value_no_cv_t, id_t >::const_pointer, typenameStorage< value_no_cv_t, id_t >::pointer >::type pointer
bool operator!=(const PiercedStorageIterator &rhs) const
__PSI_REFERENCE__ getValue(std::size_t k=0) const
std::conditional< std::is_const< value_t >::value, typenameStorage< value_no_cv_t, id_t >::const_reference, typenameStorage< value_no_cv_t, id_t >::reference >::type reference
const PiercedKernelIterator< id_t > & getKernelIterator() const
std::bidirectional_iterator_tag iterator_category
Metafunction for generating a pierced storage.
--- layout: doxygen_footer ---