3#ifndef EXIV2_INCLUDE_SLICE_HPP
4#define EXIV2_INCLUDE_SLICE_HPP
22 throw std::out_of_range(
"Begin must be smaller than end");
29 [[nodiscard]]
inline size_t size() const noexcept {
42 if (index >=
size()) {
43 throw std::out_of_range(
"Index outside of the slice");
81template <
template <
typename data_type>
class storage_type,
typename data_type>
83 using iterator =
typename storage_type<data_type>::iterator;
84 using const_iterator =
typename storage_type<data_type>::const_iterator;
85 using value_type =
typename storage_type<data_type>::value_type;
101 const value_type&
at(
size_t index)
const {
113 [[nodiscard]] const_iterator
cbegin() const noexcept {
120 [[nodiscard]] const_iterator
cend() const noexcept {
121 return storage_.unsafeGetIteratorAt(end_);
132 template <
typename slice_type>
133 [[nodiscard]] slice_type
subSlice(
size_t begin,
size_t end)
const {
141 const size_t new_begin = begin + this->
begin_;
142 const size_t new_end = this->begin_ + end;
143 if (new_end > this->end_) {
144 throw std::out_of_range(
"Invalid input parameters to slice");
146 return slice_type(
storage_.data_, new_begin, new_end);
161template <
template <
typename>
class storage_type,
typename data_type>
164 using iterator =
typename ConstSliceBase<storage_type, data_type>::iterator;
165 using const_iterator =
typename ConstSliceBase<storage_type, data_type>::const_iterator;
166 using value_type =
typename ConstSliceBase<storage_type, data_type>::value_type;
174 value_type&
at(
size_t index) {
179 const value_type&
at(
size_t index)
const {
194 return this->
storage_.unsafeGetIteratorAt(this->end_);
229 template <
typename slice_type>
240 const size_t new_end = this->begin_ +
end;
241 if (new_end > this->end_) {
242 throw std::out_of_range(
"Invalid input parameters to slice");
244 return slice_type(this->
storage_.data_, new_begin, new_end);
253template <
typename container>
255 using iterator =
typename container::iterator;
256 using const_iterator =
typename container::const_iterator;
258#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
259 using value_type = std::remove_cv_t<typename container::value_type>;
261 using value_type =
typename std::remove_cv<typename container::value_type>::type;
269 if (end > data.size()) {
270 throw std::out_of_range(
"Invalid input parameters to slice");
280 [[nodiscard]]
const value_type&
unsafeAt(
size_t index)
const {
281 return data_.at(index);
284 [[nodiscard]] value_type&
unsafeAt(
size_t index) {
285 return data_.at(index);
296 assert(index <= data_.size());
298 auto it = data_.begin();
299 std::advance(it, index);
304 assert(index <= data_.size());
306 auto it = data_.begin();
307 std::advance(it, index);
321template <
typename storage_type>
323#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
324 using value_type = std::remove_cv_t<std::remove_pointer_t<storage_type>>;
326 using value_type =
typename std::remove_cv<typename std::remove_pointer<storage_type>::type>::type;
328 using iterator = value_type*;
329 using const_iterator =
const value_type*;
339 throw std::invalid_argument(
"Null pointer passed to slice constructor");
349 [[nodiscard]] value_type&
unsafeAt(
size_t index)
noexcept {
353 [[nodiscard]]
const value_type&
unsafeAt(
size_t index)
const noexcept {
364 return data_ + index;
368 return data_ + index;
420template <
typename container>
423 using iterator =
typename container::iterator;
424 using const_iterator =
typename container::const_iterator;
426#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
427 using value_type = std::remove_cv_t<typename container::value_type>;
429 using value_type =
typename std::remove_cv<typename container::value_type>::type;
457template <
typename container>
460 using iterator =
typename container::iterator;
461 using const_iterator =
typename container::const_iterator;
463#if __cplusplus >= 201402L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201402L))
464 using value_type = std::remove_cv_t<typename container::value_type>;
466 using value_type =
typename std::remove_cv<typename container::value_type>::type;
471 const container>::template subSlice<Slice<const container>>(
begin,
end);
497 Slice(
const T* ptr,
size_t begin,
size_t end) :
517 Slice<T*> subSlice(
size_t begin,
size_t end) {
521 [[nodiscard]]
Slice<const T*> subSlice(
size_t begin,
size_t end)
const {
522 return this->to_const_base().template subSlice<Slice<const T*>>(begin, end);
548template <
typename container>
557template <
typename container>
565template <
typename container>
Class CrwImage to access Canon CRW images. References: The Canon RAW (CRW) File Format by Phil Harv...
Definition asfvideo.hpp:15
Slice< T > makeSlice(T &cont, size_t begin, size_t end)
Return a new slice with the given bounds.
Definition slice.hpp:533
Slice< container > makeSliceUntil(container &cont, size_t end)
Return a new slice spanning until end.
Definition slice.hpp:566
Slice< container > makeSliceFrom(container &cont, size_t begin)
Return a new slice spanning from begin until the end of the container.
Definition slice.hpp:558
This class provides the public-facing const-qualified methods of a slice.
Definition slice.hpp:82
slice_type subSlice(size_t begin, size_t end) const
Definition slice.hpp:133
const_iterator cend() const noexcept
Definition slice.hpp:120
storage_type< data_type > storage_
Definition slice.hpp:153
const_iterator cbegin() const noexcept
Definition slice.hpp:113
const value_type & at(size_t index) const
Definition slice.hpp:101
ConstSliceBase(data_type &data, size_t begin, size_t end)
Definition slice.hpp:92
iterator unsafeGetIteratorAt(size_t index)
Definition slice.hpp:294
ContainerStorage(container &data, size_t, size_t end)
Definition slice.hpp:268
const value_type & unsafeAt(size_t index) const
Definition slice.hpp:280
ConstSliceBase< storage_type, const data_type > to_const_base() const noexcept
Definition slice.hpp:215
iterator end() noexcept
Definition slice.hpp:193
iterator begin() noexcept
Definition slice.hpp:186
slice_type subSlice(size_t begin, size_t end)
Definition slice.hpp:230
value_type & at(size_t index)
Definition slice.hpp:174
Implementation of the storage concept for slices of C arrays.
Definition slice.hpp:322
PtrSliceStorage(storage_type ptr, size_t, size_t)
Definition slice.hpp:337
value_type & unsafeAt(size_t index) noexcept
Definition slice.hpp:349
iterator unsafeGetIteratorAt(size_t index) noexcept
Definition slice.hpp:363
size_t size() const noexcept
Definition slice.hpp:29
size_t begin_
Definition slice.hpp:51
void rangeCheck(size_t index) const
Definition slice.hpp:41
Slice(const T *ptr, size_t begin, size_t end)
Definition slice.hpp:497
Slice (= view) for STL containers.
Definition slice.hpp:421
Slice subSlice(size_t begin, size_t end)
Definition slice.hpp:441
Slice< const container > subSlice(size_t begin, size_t end) const
Definition slice.hpp:449