19 #ifndef PSTORE_MCREPO_SECTION_SPARRAY_HPP 20 #define PSTORE_MCREPO_SECTION_SPARRAY_HPP 26 #include "pstore/mcrepo/section.hpp" 33 template <
typename CastToType,
typename BaseIterator>
36 using iterator_category =
37 typename std::iterator_traits<BaseIterator>::iterator_category;
38 using value_type = CastToType;
39 using difference_type =
40 typename std::iterator_traits<BaseIterator>::difference_type;
41 using pointer = value_type
const *;
42 using reference = value_type
const &;
45 constexpr
bool operator== (cast_iterator
const & rhs)
const;
46 constexpr
bool operator!= (cast_iterator
const & rhs)
const;
47 constexpr reference operator* ()
const;
48 cast_iterator & operator++ ();
49 cast_iterator operator++ (
int);
50 cast_iterator & operator-- ();
51 cast_iterator operator-- (
int);
52 cast_iterator operator+ (
unsigned x)
const {
return cast_iterator{it_ + x}; }
53 cast_iterator operator- (
unsigned x)
const {
return cast_iterator{it_ - x}; }
57 mutable value_type value_;
59 template <
typename CastToType,
typename BaseIterator>
63 template <
typename CastToType,
typename BaseIterator>
66 return it_ == rhs.it_;
68 template <
typename CastToType,
typename BaseIterator>
71 return !operator== (rhs);
73 template <
typename CastToType,
typename BaseIterator>
76 return value_ =
static_cast<CastToType
> (*it_);
78 template <
typename CastToType,
typename BaseIterator>
84 template <
typename CastToType,
typename BaseIterator>
91 template <
typename CastToType,
typename BaseIterator>
97 template <
typename CastToType,
typename BaseIterator>
109 template <
typename T>
112 using index_type = std::underlying_type_t<section_kind>;
113 static_assert (std::is_unsigned<index_type>::value,
114 "section-kind underlying type should be unsigned");
117 template <
typename Iterator>
118 static constexpr
bool is_section_kind_iterator () {
119 return std::is_same<
typename std::remove_cv<
120 typename std::iterator_traits<Iterator>::value_type>::type,
121 section_kind>::value;
128 using value_type =
typename array_type::value_type;
129 using size_type =
typename array_type::size_type;
130 using iterator =
typename array_type::iterator;
131 using const_iterator =
typename array_type::const_iterator;
132 using reference = value_type &;
133 using const_reference = value_type
const &;
137 template <
typename IndexIterator,
typename =
typename std::enable_if_t<
138 is_section_kind_iterator<IndexIterator> ()>>
143 constexpr value_type & operator[] (section_kind k) noexcept;
144 constexpr value_type
const & operator[] (section_kind k)
const noexcept;
147 constexpr reference front () noexcept;
149 constexpr const_reference front ()
const noexcept;
151 constexpr reference back () noexcept;
153 constexpr const_reference back ()
const noexcept;
159 static constexpr std::size_t size_bytes (std::size_t members) noexcept;
169 iterator
begin () {
return sa_.begin (); }
170 const_iterator
begin ()
const {
return sa_.begin (); }
171 const_iterator cbegin ()
const {
return sa_.cbegin (); }
174 iterator
end () {
return sa_.end (); }
175 const_iterator end ()
const {
return sa_.end (); }
176 const_iterator cend ()
const {
return sa_.cend (); }
183 constexpr
bool empty ()
const noexcept {
return sa_.empty (); }
184 constexpr size_type size ()
const noexcept {
return sa_.size (); }
191 constexpr
bool has_index (section_kind pos)
const noexcept {
192 return sa_.has_index (static_cast<index_type> (pos));
202 typename array_type::indices::const_iterator>;
205 constexpr
explicit indices (
typename array_type::indices
const & i) noexcept
209 constexpr
bool empty ()
const noexcept {
return i_.empty (); }
211 section_kind front ()
const noexcept {
212 return static_cast<section_kind
> (i_.front ());
214 section_kind back ()
const noexcept {
215 return static_cast<section_kind
> (i_.back ());
219 typename array_type::indices
const i_;
222 indices get_indices ()
const noexcept {
return indices{sa_.get_indices ()}; }
230 template <
typename T>
231 template <
typename IndexIterator,
typename>
237 std::numeric_limits<typename array_type::bitmap_type>::radix == 2,
238 "expected numeric radix to be 2 (so that 'digits' is the number of bits)");
239 static_assert (static_cast<index_type> (section_kind::last) <=
240 std::numeric_limits<typename array_type::bitmap_type>::digits,
241 "section_kind does not fit in the member sparse array");
246 template <
typename T>
250 template <
typename T>
256 template <
typename T>
260 template <
typename T>
267 template <
typename T>
269 return sa_[
static_cast<index_type
> (k)];
271 template <
typename T>
273 -> value_type
const & {
274 return sa_[
static_cast<index_type
> (k)];
279 template <
typename T>
281 return array_type::size_bytes (members);
287 #endif // PSTORE_MCREPO_SECTION_SPARRAY_HPP constexpr section_sparray(IndexIterator first, IndexIterator last)
Constructs a sparse array whose available indices are defined by the iterator range from [first...
Definition: section_sparray.hpp:232
iterator begin()
Returns an iterator to the beginning of the container.
Definition: section_sparray.hpp:169
iterator end()
Returns an iterator to the end of the container.
Definition: section_sparray.hpp:174
Implements a sparse array type.
transaction< transaction_lock > begin(database &db, transaction_lock &lock)
Creates a new transaction. Every operation performed on a transaction instance can be potentially und...
Definition: transaction.hpp:311
Definition: section_sparray.hpp:34
constexpr std::size_t size_bytes() const
Returns the number of bytes of storage that are being used by this array instance.
Definition: section_sparray.hpp:161
A wrapper for the sparse_array<> type which is specialized for indices of type section_kind.
Definition: section_sparray.hpp:110
Definition: nonpod2.cpp:40
constexpr reference front() noexcept
Returns the value associated with the first section-kind index in the container.
Definition: section_sparray.hpp:247
A container which can be used to access and iterate over the available index values in the sparse arr...
Definition: section_sparray.hpp:198
constexpr bool has_index(section_kind pos) const noexcept
Returns true if the sparse array has an index pos.
Definition: section_sparray.hpp:191
constexpr reference back() noexcept
Returns the value associated with the last section-kind index in the container.
Definition: section_sparray.hpp:257