CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MemoryView.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
14
15#include <algorithm>
16#include <cmath>
17#include <cstddef>
18#include <iterator>
19
20#if defined(CE_MEMORY_VIEW_NO_DEBUG_BOUNDS_CHECK)
21#define CE_MEMORY_VIEW_BOUNDS_CHECK(i)
22#else
23#include <cassert>
24#define CE_MEMORY_VIEW_BOUNDS_CHECK(i) CE_ASSERT((i) < this->size())
25#endif
26
27namespace CeresEngine {
28
62 template<typename T> class MemoryView {
63 public:
64 using value_type = T;
67 using reference = T&;
68 using const_reference = const T&;
69 using pointer = T*;
70 using const_pointer = const T*;
71 using iterator = T*;
72 using const_iterator = const T*;
73 using reverse_iterator = std::reverse_iterator<iterator>;
74 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
75
87
88 static constexpr bool isMutable = !std::is_const_v<T>;
89
90 private:
92 T* mPointer = nullptr;
93
96
97 public:
99 MemoryView() = default;
100
102 MemoryView(std::nullptr_t) {}
103
105 MemoryView(T* ptr, const SizeType size) : mPointer(ptr), mSize(size) {}
106
110 template<typename U> explicit MemoryView(const MemoryView<U>& view) : MemoryView(view.template as<T>()) {}
111
116 template<typename Container> MemoryView(Container& container, SizeType offset = 0) : MemoryView(container.data() + offset, container.size() - offset) {}
117
118 MemoryView(const MemoryView&) = default;
119 MemoryView(MemoryView&&) = default;
120
121 MemoryView& operator=(const MemoryView&) = default;
123
127 void reset(Pointer ptr = nullptr, const SizeType size = 0) {
128 mPointer = ptr;
129 mSize = size;
130 }
131
134 void reset(const SizeType size) { mSize = size; }
135
145 [[nodiscard]] MemoryView<T> slice(SizeType offset, SizeType length = ~0ul) const noexcept {
146 offset = std::clamp(offset, size_t(0), mSize);
147 length = std::clamp(length, size_t(0), mSize - offset);
148
149// if(offset > mSize) {
150// offset = mSize;
151// length = 0;
152// } else if((offset + length) > mSize || length == ~0ul) {
153// length = mSize - offset;
154// }
155
156 CE_ASSERT(mSize >= (offset + length));
157 return MemoryView<T>(mPointer + offset, length);
158 }
159
161 explicit operator bool() const { return mPointer != nullptr; }
162
165 {
166 return mPointer;
167 }
168
171
180 {
182 return *(mPointer + index);
183 }
184
188 return *(mPointer + index);
189 }
190
191 // Gets the element at the given `index` in the memory view.
198 [[nodiscard]] ConstReference operator[](SizeType index) const { return *(mPointer + index); }
199
202 {
203 return *(mPointer + index);
204 }
205
208 [[nodiscard]] ConstReference front() const { return at(0); }
209
212 {
213 return at(0);
214 }
215
218 [[nodiscard]] ConstReference back() const { return at(mSize - 1); }
219
222 {
223 return at(mSize - 1);
224 }
225
231
237
238 public: // Iterators
241 {
242 return data();
243 }
244
247
250
253 {
254 return data() + mSize;
255 }
256
259
262
269
272
275
282
285
288
289 public: // Capacity
291 [[nodiscard]] bool empty() const noexcept { return mSize == 0; }
292
295
300 template<typename U> [[nodiscard]] MemoryView<U> as() const noexcept {
301 return MemoryView<U>(reinterpret_cast<U*>(mPointer), mSize * sizeof(T) / sizeof(U));
302 }
303
304 public:
306 void hexdump(std::ostream& stream) const;
307
308 [[nodiscard]] String toHex() const;
309 void toHex(std::ostream& stream) const;
310 };
311
312 namespace internal {
314 void memoryViewHexdump(const MemoryView<Byte>& memoryView, std::ostream& stream);
315
317 void memoryViewToHex(const MemoryView<Byte>& memoryView, std::ostream& stream);
318 } // namespace internal
319
320 template<typename T> String MemoryView<T>::hexdump() const {
321 if constexpr(std::is_same_v<T, Byte>) {
322 return internal::memoryViewHexdump(*this);
323 } else {
325 }
326 }
327
328 template<typename T> void MemoryView<T>::hexdump(std::ostream& stream) const {
329 if constexpr(std::is_same_v<T, Byte>) {
330 internal::memoryViewHexdump(*this, stream);
331 } else {
333 }
334 }
335
336 template<typename T> String MemoryView<T>::toHex() const {
337 if constexpr(std::is_same_v<T, Byte>) {
338 return internal::memoryViewToHex(*this);
339 } else {
341 }
342 }
343
344 template<typename T> void MemoryView<T>::toHex(std::ostream& stream) const {
345 if constexpr(std::is_same_v<T, Byte>) {
346 internal::memoryViewToHex(*this, stream);
347 } else {
349 }
350 }
351
352 // ---------------------------------------------------------------------------------------------
353
359 template<typename T> MemoryView<T> make_memory_view(T* ptr, size_t size) { return MemoryView<T>(ptr, size); }
360
362 template<typename T> MemoryView<const T> make_memory_view(const T* ptr, size_t size) { return MemoryView<const T>(ptr, size); }
363
369 template<typename T, size_t N> MemoryView<T> make_memory_view(T (&array)[N]) { return MemoryView<T>(array, N); }
370
376 template<typename Container> MemoryView<typename Container::value_type> make_memory_view(Container& container, size_t offset = 0) {
377 return MemoryView<typename Container::value_type>(container.data() + offset, container.size() - offset);
378 }
379
381 template<typename Container> MemoryView<const typename Container::value_type> make_memory_view(const Container& c, size_t offset = 0) {
382 return MemoryView<const typename Container::value_type>(c.data() + offset, c.size() - offset);
383 }
384
385 // ---------------------------------------------------------------------------------------------
386
389
390 // ---------------------------------------------------------------------------------------------
391 // ---------------------------------------------------------------------------------------------
392
393 namespace impl {
404 template<typename T> T* advanceBytes(T* pointer, std::ptrdiff_t bytes) {
405 using ByteType = std::conditional_t<std::is_const_v<T>, const Byte, Byte>;
406 return reinterpret_cast<T*>(reinterpret_cast<ByteType*>(pointer) + bytes);
407 }
408 } // namespace impl
409
439 template<typename T> class StridedMemoryView {
440 public:
441 template<bool IsConstIterator> class IteratorImpl;
442
443 using value_type = T;
446 using reference = T&;
447 using const_reference = const T&;
448 using pointer = T*;
449 using const_pointer = const T*;
452 using reverse_iterator = std::reverse_iterator<iterator>;
453 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
454
466
467 static constexpr bool isConst = std::is_const_v<T>;
468 static constexpr SizeType defaultStride = sizeof(T);
469
470 private:
471 Pointer mPointer = nullptr;
474
475 public:
477 StridedMemoryView() = default;
478
480 StridedMemoryView(std::nullptr_t) {}
481
485
489 template<typename U> explicit StridedMemoryView(const StridedMemoryView<U>& view) : StridedMemoryView(view.template as<T>()) {}
490
493
496
501 void reset(T* ptr = nullptr, const SizeType size = 0, const SizeType stride = defaultStride) {
502 mPointer = ptr;
503 mSize = size;
504 mStride = stride;
505 }
506
511 mSize = size;
512 mStride = stride;
513 }
514
527 if(offset > mSize) {
528 offset = mSize;
529 length = 0;
530 } else if((offset + length) > mSize) {
531 length = mSize - offset;
532 }
533
534 CE_ASSERT(mSize >= (offset + length));
536 }
537
539 explicit operator bool() const { return !!mPointer; }
540
543 {
544 return mPointer;
545 }
546
549
556
562
564 [[nodiscard]] ConstReference operator[](const SizeType i) const { return at(i); }
565
568 {
569 return at(i);
570 }
571
573 [[nodiscard]] ConstReference front() const { return at(0); }
574
577 {
578 return at(0);
579 }
580
582 [[nodiscard]] ConstReference back() const { return at(mSize - 1); }
583
586 {
587 return at(mSize - 1);
588 }
589
592
595
596 public: // Iterators
599 {
600 return iterator{this, 0};
601 }
602
605
608
611 {
612 return iterator{this, mSize};
613 }
614
617
620
626
629
632
638
641
644
645 public: // Capacity
647 [[nodiscard]] bool empty() const noexcept { return mSize == 0; }
648
651
654
657
665 template<typename U> [[nodiscard]] StridedMemoryView<U> as() const noexcept {
666 return StridedMemoryView<U>(reinterpret_cast<U*>(mPointer), mSize * sizeof(T) / sizeof(U), mStride);
667 }
668
669 template<bool IsConstIterator> class IteratorImpl {
670 public:
671 using Self = std::conditional_t<IsConstIterator, const StridedMemoryView, StridedMemoryView>;
672
673 using iterator_category = std::random_access_iterator_tag;
674 using difference_type = std::ptrdiff_t;
675 using value_type = typename Self::value_type;
676 using pointer = typename Self::pointer;
677 using const_pointer = typename Self::const_pointer;
678 using reference = typename Self::reference;
679 using const_reference = typename Self::const_reference;
680
687
688 Self* mMemoryView = nullptr;
690
691 public:
692 explicit IteratorImpl(Self& memoryView, const SizeType index = 0) : mMemoryView(&memoryView), mIndex(index) {}
693 explicit IteratorImpl(Self* memoryView, const SizeType index = 0) : mMemoryView(memoryView), mIndex(index) {}
694
703
705 {
706 return &(*mMemoryView)[mIndex];
707 }
709 {
710 return &(*mMemoryView)[mIndex];
711 }
712
713 IteratorImpl operator++(int) noexcept {
714 IteratorImpl copy = *this;
715 mIndex++;
716 return copy;
717 }
718
720 mIndex++;
721 return *this;
722 }
723
725 IteratorImpl copy = *this;
726 mIndex = std::clamp(mIndex + n, 0, mMemoryView->size());
727 return copy;
728 }
729
730 IteratorImpl operator--(int) noexcept {
731 IteratorImpl copy = *this;
732 if(mIndex == 0) {
733 return copy;
734 }
735
736 mIndex--;
737 return copy;
738 }
739
741 if(mIndex == 0) {
742 return *this;
743 }
744 mIndex--;
745 return *this;
746 }
747
749 IteratorImpl copy = *this;
750 mIndex = std::clamp(mIndex - n, 0, mMemoryView->size());
751 return copy;
752 }
753
754 friend bool operator==(const IteratorImpl& lhs, const IteratorImpl& rhs) { return rhs.mMemoryView == lhs.mMemoryView && lhs.mIndex == rhs.mIndex; }
755
756 friend bool operator!=(const IteratorImpl& lhs, const IteratorImpl& rhs) { return !(lhs == rhs); }
757 };
758 };
759
760 // ---------------------------------------------------------------------------------------------
761
768 template<typename T> StridedMemoryView<T> make_strided_memory_view(T* ptr, size_t size, size_t stride = StridedMemoryView<T>::defaultStride) {
769 return StridedMemoryView<T>(ptr, size, stride);
770 }
771
773 template<typename T> StridedMemoryView<const T> make_strided_memory_view(const T* ptr, size_t size, size_t stride = StridedMemoryView<T>::defaultStride) {
774 return StridedMemoryView<const T>(ptr, size, stride);
775 }
776
782 template<typename T, size_t N> StridedMemoryView<const T> make_strided_memory_view(const T (&ar)[N]) { return StridedMemoryView<const T>(ar, N); }
783
789 template<typename Container> StridedMemoryView<typename Container::value_type> make_strided_memory_view(Container& container, size_t offset = 0) {
790 return StridedMemoryView<typename Container::value_type>(container.data() + offset, container.size() - offset);
791 }
792
794 template<typename Container>
796 return StridedMemoryView<const typename Container::value_type>(container.data() + offset, container.size() - offset);
797 }
798
799 // ---------------------------------------------------------------------------------------------
800
803
804} // namespace CeresEngine
#define CE_ASSERT(...)
Definition Macros.hpp:323
#define CE_MEMORY_VIEW_BOUNDS_CHECK(i)
Definition MemoryView.hpp:24
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally c...
Definition MemoryView.hpp:62
static constexpr bool isMutable
Definition MemoryView.hpp:88
String hexdump() const
Definition MemoryView.hpp:320
ConstReference back() const
Gets the last element on the memory view.
Definition MemoryView.hpp:218
ConstIterator begin() const noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:246
const_reference ConstReference
Definition MemoryView.hpp:80
MemoryView(std::nullptr_t)
Creates a new memory view with length 0.
Definition MemoryView.hpp:102
T value_type
Definition MemoryView.hpp:64
ConstIterator cend() const noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:261
const T & const_reference
Definition MemoryView.hpp:68
MemoryView & operator=(const MemoryView &)=default
difference_type DifferenceType
Definition MemoryView.hpp:78
SizeType mSize
The length of the view, in multiples of sizeof(T).
Definition MemoryView.hpp:95
ConstPointer get() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:170
MemoryView(const MemoryView &)=default
T * mPointer
A raw pointer that points to the beginning of the memory view.
Definition MemoryView.hpp:92
ConstReverseIterator crend() const noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:287
bool empty() const noexcept
Checks if the view is empty and has zero elements.
Definition MemoryView.hpp:291
void hexdump(std::ostream &stream) const
Definition MemoryView.hpp:328
ConstReverseIterator rbegin() const noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:271
MemoryView()=default
Creates a new memory view with length 0.
iterator Iterator
Definition MemoryView.hpp:83
SizeType size() const noexcept
Gets the size of the view as number of elements.
Definition MemoryView.hpp:294
MemoryView(T *ptr, const SizeType size)
Creates a new memory view from a raw pointer and length.
Definition MemoryView.hpp:105
Reference back()
Gets the last element on the memory view.
Definition MemoryView.hpp:221
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition MemoryView.hpp:74
std::reverse_iterator< iterator > reverse_iterator
Definition MemoryView.hpp:73
value_type ValueType
Definition MemoryView.hpp:76
ConstIterator cbegin() const noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:249
String toHex() const
Definition MemoryView.hpp:336
Reference at(SizeType index)
Gets the element at the given index in the memory view.
Definition MemoryView.hpp:179
MemoryView< U > as() const noexcept
Casts the memory view from type T to type U.
Definition MemoryView.hpp:300
Iterator begin() noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:240
ReverseIterator rend() noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:278
Iterator end() noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:252
const_iterator ConstIterator
Definition MemoryView.hpp:84
MemoryView(const MemoryView< U > &view)
Creates a new memory view by casting the value of another.
Definition MemoryView.hpp:110
ConstReverseIterator crbegin() const noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:274
const_pointer ConstPointer
Definition MemoryView.hpp:82
size_t size_type
Definition MemoryView.hpp:65
T * pointer
Definition MemoryView.hpp:69
void toHex(std::ostream &stream) const
Definition MemoryView.hpp:344
const T * const_iterator
Definition MemoryView.hpp:72
MemoryView(Container &container, SizeType offset=0)
Creates a new memory view from an STL-compatible contiguous container.
Definition MemoryView.hpp:116
MemoryView & operator=(MemoryView &&)=default
pointer Pointer
Definition MemoryView.hpp:81
void reset(const SizeType size)
Resets the memory view size.
Definition MemoryView.hpp:134
MemoryView< T > slice(SizeType offset, SizeType length=~0ul) const noexcept
Slices the memory view by taking the element that starts at offset and returns a new view with the gi...
Definition MemoryView.hpp:145
reverse_iterator ReverseIterator
Definition MemoryView.hpp:85
void reset(Pointer ptr=nullptr, const SizeType size=0)
Resets the memory view and sets it's value a new pointer.
Definition MemoryView.hpp:127
const T * const_pointer
Definition MemoryView.hpp:70
ConstPointer data() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:227
T & reference
Definition MemoryView.hpp:67
ConstIterator end() const noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:258
MemoryView(MemoryView &&)=default
ConstReference at(SizeType index) const
Gets the element at the given index in the memory view.
Definition MemoryView.hpp:186
ConstReference front() const
Gets the first element on the memory view.
Definition MemoryView.hpp:208
ConstReverseIterator rend() const noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:284
ReverseIterator rbegin() noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:265
Pointer get() noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:164
size_type SizeType
Definition MemoryView.hpp:77
Pointer data() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:233
ptrdiff_t difference_type
Definition MemoryView.hpp:66
reference Reference
Definition MemoryView.hpp:79
Reference operator[](SizeType index)
Definition MemoryView.hpp:201
Reference front()
Gets the first element on the memory view.
Definition MemoryView.hpp:211
const_reverse_iterator ConstReverseIterator
Definition MemoryView.hpp:86
ConstReference operator[](SizeType index) const
Definition MemoryView.hpp:198
T * iterator
Definition MemoryView.hpp:71
IteratorImpl(Self *memoryView, const SizeType index=0)
Definition MemoryView.hpp:693
IteratorImpl operator+(const DifferenceType n) noexcept
Definition MemoryView.hpp:724
typename Self::value_type value_type
Definition MemoryView.hpp:675
const_reference operator*() const noexcept
Definition MemoryView.hpp:699
IteratorImpl & operator++() noexcept
Definition MemoryView.hpp:719
IteratorImpl operator++(int) noexcept
Definition MemoryView.hpp:713
IteratorImpl operator-(const DifferenceType n) noexcept
Definition MemoryView.hpp:748
const_reference ConstReference
Definition MemoryView.hpp:686
pointer Pointer
Definition MemoryView.hpp:683
std::random_access_iterator_tag iterator_category
Definition MemoryView.hpp:673
IteratorImpl(Self &memoryView, const SizeType index=0)
Definition MemoryView.hpp:692
value_type ValueType
Definition MemoryView.hpp:682
const_pointer ConstPointer
Definition MemoryView.hpp:684
reference operator*() const noexcept
Definition MemoryView.hpp:695
IteratorImpl & operator--() noexcept
Definition MemoryView.hpp:740
difference_type DifferenceType
Definition MemoryView.hpp:681
typename Self::const_reference const_reference
Definition MemoryView.hpp:679
IteratorImpl operator--(int) noexcept
Definition MemoryView.hpp:730
typename Self::reference reference
Definition MemoryView.hpp:678
typename Self::const_pointer const_pointer
Definition MemoryView.hpp:677
SizeType mIndex
Definition MemoryView.hpp:689
friend bool operator==(const IteratorImpl &lhs, const IteratorImpl &rhs)
Definition MemoryView.hpp:754
std::ptrdiff_t difference_type
Definition MemoryView.hpp:674
std::conditional_t< IsConstIterator, const StridedMemoryView, StridedMemoryView > Self
Definition MemoryView.hpp:671
pointer operator->() const noexcept
Definition MemoryView.hpp:704
typename Self::pointer pointer
Definition MemoryView.hpp:676
friend bool operator!=(const IteratorImpl &lhs, const IteratorImpl &rhs)
Definition MemoryView.hpp:756
reference Reference
Definition MemoryView.hpp:685
const_pointer operator->() const noexcept
Definition MemoryView.hpp:708
Self * mMemoryView
Definition MemoryView.hpp:688
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally c...
Definition MemoryView.hpp:439
ConstReverseIterator rend() const noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:640
size_t size_type
Definition MemoryView.hpp:444
const T & const_reference
Definition MemoryView.hpp:447
ConstIterator cend() const noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:619
Pointer data() noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:594
IteratorImpl< false > iterator
Definition MemoryView.hpp:450
StridedMemoryView(std::nullptr_t)
Creates a new strided memory view with length 0.
Definition MemoryView.hpp:480
bool empty() const noexcept
Checks if the view is empty and has zero elements.
Definition MemoryView.hpp:647
void reset(T *ptr=nullptr, const SizeType size=0, const SizeType stride=defaultStride)
Resets the memory view and sets it's value a new pointer.
Definition MemoryView.hpp:501
Pointer get() noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:542
SizeType byteSize() const noexcept
Returns the size of view in bytes.
Definition MemoryView.hpp:656
StridedMemoryView(StridedMemoryView &&)=default
ConstIterator begin() const noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:604
std::reverse_iterator< iterator > reverse_iterator
Definition MemoryView.hpp:452
T value_type
Definition MemoryView.hpp:443
ConstIterator end() const noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:616
StridedMemoryView & operator=(StridedMemoryView &&)=default
Reference front()
Gets the first element on the memory view.
Definition MemoryView.hpp:576
Reference at(SizeType i)
Gets the element at the given index in the memory view.
Definition MemoryView.hpp:551
StridedMemoryView(const Pointer ptr, const SizeType size, const SizeType stride)
Creates a new memory view from a raw pointer and length and a custom stride.
Definition MemoryView.hpp:484
StridedMemoryView()=default
Creates a new strided memory view with length 0.
StridedMemoryView(const StridedMemoryView< U > &view)
Creates a new strided memory view by casting the value of another.
Definition MemoryView.hpp:489
ReverseIterator rbegin() noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:622
SizeType size() const noexcept
Gets the size of the view as number of elements.
Definition MemoryView.hpp:650
const_reference ConstReference
Definition MemoryView.hpp:459
Pointer mPointer
Definition MemoryView.hpp:471
void reset(const SizeType size, const SizeType stride=defaultStride)
Resets the memory view size and stride.
Definition MemoryView.hpp:510
size_type SizeType
Definition MemoryView.hpp:456
ConstReverseIterator rbegin() const noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:628
reference Reference
Definition MemoryView.hpp:458
StridedMemoryView(const StridedMemoryView &)=default
StridedMemoryView< T > slice(SizeType offset, SizeType length) const
Slices the memory view by taking the element that starts at offset and returns a new view with the gi...
Definition MemoryView.hpp:526
Reference back()
Gets the last element on the memory view.
Definition MemoryView.hpp:585
const_pointer ConstPointer
Definition MemoryView.hpp:461
ConstIterator cbegin() const noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:607
Reference operator[](const SizeType i)
Definition MemoryView.hpp:567
value_type ValueType
Definition MemoryView.hpp:455
SizeType mStride
Definition MemoryView.hpp:473
static constexpr bool isConst
Definition MemoryView.hpp:467
StridedMemoryView< U > as() const noexcept
Casts the memory view from type T to type U.
Definition MemoryView.hpp:665
SizeType stride() const noexcept
Returns the stride of view, in bytes.
Definition MemoryView.hpp:653
ConstReference operator[](const SizeType i) const
Definition MemoryView.hpp:564
Pointer data() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:591
T * pointer
Definition MemoryView.hpp:448
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition MemoryView.hpp:453
difference_type DifferenceType
Definition MemoryView.hpp:457
Iterator begin() noexcept
Returns an iterator to the first element in the view.
Definition MemoryView.hpp:598
ConstPointer get() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:548
static constexpr SizeType defaultStride
Definition MemoryView.hpp:468
const_reverse_iterator ConstReverseIterator
Definition MemoryView.hpp:465
ReverseIterator rend() noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:634
IteratorImpl< true > const_iterator
Definition MemoryView.hpp:451
ConstReference front() const
Gets the first element on the memory view.
Definition MemoryView.hpp:573
Iterator end() noexcept
Returns an iterator to the past-the-last element in the view.
Definition MemoryView.hpp:610
ConstReverseIterator crend() const noexcept
Returns an iterator to the past-the-last element in the view while iterating in reverse.
Definition MemoryView.hpp:643
pointer Pointer
Definition MemoryView.hpp:460
SizeType mSize
Definition MemoryView.hpp:472
T & reference
Definition MemoryView.hpp:446
StridedMemoryView & operator=(const StridedMemoryView &)=default
const T * const_pointer
Definition MemoryView.hpp:449
ConstReference back() const
Gets the last element on the memory view.
Definition MemoryView.hpp:582
ConstReverseIterator crbegin() const noexcept
Returns an iterator to the first element in the view while iterating in reverse.
Definition MemoryView.hpp:631
reverse_iterator ReverseIterator
Definition MemoryView.hpp:464
ptrdiff_t difference_type
Definition MemoryView.hpp:445
ConstReference at(SizeType i) const
Gets the element at the given index in the memory view.
Definition MemoryView.hpp:558
T * advanceBytes(T *pointer, std::ptrdiff_t bytes)
Utility function that advances a pointer by a fixed number of bytes, independent of the size of T.
Definition MemoryView.hpp:404
String memoryViewToHex(const MemoryView< Byte > &memoryView)
String memoryViewHexdump(const MemoryView< Byte > &memoryView)
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
MemoryView< T > make_memory_view(T *ptr, size_t size)
Makes a new memory from a raw pointer and length.
Definition MemoryView.hpp:359
StridedMemoryView< T > make_strided_memory_view(T *ptr, size_t size, size_t stride=StridedMemoryView< T >::defaultStride)
Makes a new strided memory from a raw pointer and length.
Definition MemoryView.hpp:768
void copy(const A &a, B &b, T &&t=T())
Copies values from one container to another.
Definition Iterator.hpp:564
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25