bit7z 4.1.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitindicesview.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef BITINDICESVIEW_HPP
11#define BITINDICESVIEW_HPP
12
13#include "bitdefines.hpp"
14
15#include <array>
16#include <cstddef>
17#include <cstdint>
18#include <iterator>
19#include <vector>
20
21namespace bit7z {
26
32template< std::size_t N >
34
35// NOLINTBEGIN(*-explicit-conversions, *-avoid-c-arrays, *-pro-bounds-pointer-arithmetic)
44class BitIndicesView final {
45 public:
46 // BitIndicesView is basically a C++20's std::span< const std::uint32_t >.
47 // Note: still not using C++14's traits style as bit7z's public API must be written in C++11.
48 using element_type = const std::uint32_t; // T in std::span<T>.
49 using value_type = std::remove_cv< element_type >::type;
50 using size_type = std::uint32_t; // 7-Zip uses 32-bits for the size of the indices array.
51 using difference_type = std::ptrdiff_t;
52 using pointer = element_type*;
53 using const_pointer = const element_type*;
54 using reference = element_type&;
55 using const_reference = const element_type&;
56 using iterator = pointer;
57 using const_iterator = const_pointer;
58 using reverse_iterator = std::reverse_iterator< iterator >;
59 using const_reverse_iterator = std::reverse_iterator< const_iterator >;
60
64 constexpr BitIndicesView() noexcept : mIndices{ nullptr }, mSize{ 0 } {}
65
71 /* implicit */ constexpr BitIndicesView( const_reference index ) noexcept
72 : mIndices{ &index }, mSize{ 1 } {}
73
81 /* implicit */ BitIndicesView( const IndicesVector& indices ) noexcept
82 : BitIndicesView{ indices.data(), indices.size() } {}
83
90 template< std::size_t N >
91 /* implicit */ constexpr BitIndicesView( element_type (&indices)[ N ] ) noexcept
92 : BitIndicesView{ static_cast< const_pointer >( indices ), N } {}
93
101 template<
102 typename U,
103 std::size_t N,
104 typename = typename std::enable_if< std::is_convertible< U(*)[ ], element_type(*)[ ] >::value >::type
105 >
106 /* implicit */ constexpr BitIndicesView( const std::array< U, N >& indices ) noexcept
107 : BitIndicesView{ indices.data(), indices.size() } {}
108
115 : BitIndicesView{ indices.begin(), indices.size() } {}
116
120 BIT7Z_NODISCARD
121 constexpr auto data() const noexcept -> const_pointer {
122 return mIndices;
123 }
124
128 BIT7Z_NODISCARD
129 constexpr auto size() const noexcept -> size_type {
130 return mSize;
131 }
132
136 BIT7Z_NODISCARD
137 constexpr auto begin() const noexcept -> iterator {
138 return cbegin();
139 }
140
144 BIT7Z_NODISCARD
145 constexpr auto end() const noexcept -> iterator {
146 return cend();
147 }
148
152 BIT7Z_NODISCARD
153 constexpr auto cbegin() const noexcept -> const_iterator {
154 return mIndices;
155 }
156
160 BIT7Z_NODISCARD
161 constexpr auto cend() const noexcept -> const_iterator {
162 return mIndices + mSize;
163 }
164
168 BIT7Z_NODISCARD
169 constexpr auto empty() const noexcept -> bool {
170 return mIndices == nullptr;
171 }
172
173 private:
174 const_pointer mIndices;
175 size_type mSize;
176
177 constexpr BitIndicesView( const_pointer indices, std::size_t size ) noexcept
178 : mIndices{ size == 0 ? nullptr : indices },
179 mSize{ static_cast< size_type >( size ) } {}
180};
181// NOLINTEND(*-explicit-conversions, *-avoid-c-arrays, *-pro-bounds-pointer-arithmetic)
182} // namespace bit7z
183
184#endif //BITINDICESVIEW_HPP
BitIndicesView(std::initializer_list< value_type > indices) noexcept
Constructs a BitIndicesView referencing the indices in the given initializer list.
Definition bitindicesview.hpp:114
constexpr BitIndicesView() noexcept
Constructs an empty BitIndicesView.
Definition bitindicesview.hpp:64
BitIndicesView(const IndicesVector &indices) noexcept
Constructs a BitIndicesView referencing the indices stored in the given vector.
Definition bitindicesview.hpp:81
constexpr auto cbegin() const noexcept -> const_iterator
Definition bitindicesview.hpp:153
constexpr BitIndicesView(const std::array< U, N > &indices) noexcept
Constructs a BitIndicesView referencing the indices stored in the given std::array.
Definition bitindicesview.hpp:106
constexpr auto end() const noexcept -> iterator
Definition bitindicesview.hpp:145
constexpr auto begin() const noexcept -> iterator
Definition bitindicesview.hpp:137
constexpr auto empty() const noexcept -> bool
Definition bitindicesview.hpp:169
constexpr BitIndicesView(const_reference index) noexcept
Constructs a BitIndicesView referencing a single index.
Definition bitindicesview.hpp:71
constexpr auto data() const noexcept -> const_pointer
Definition bitindicesview.hpp:121
constexpr BitIndicesView(element_type(&indices)[N]) noexcept
Constructs a BitIndicesView referencing the indices stored in the given C array.
Definition bitindicesview.hpp:91
constexpr auto size() const noexcept -> size_type
Definition bitindicesview.hpp:129
constexpr auto cend() const noexcept -> const_iterator
Definition bitindicesview.hpp:161
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:29
std::vector< std::uint32_t > IndicesVector
A dynamically-sized vector of archive item indices.
Definition bitindicesview.hpp:25
std::array< std::uint32_t, N > IndicesArray
A fixed-size array of N archive item indices.
Definition bitindicesview.hpp:33