|
CeresEngine 0.2.0
A game development framework
|
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally changing its type) with a Vector-like interface, excluding the methods which change a vector's size.
More...
#include <CeresEngine/Foundation/Container/MemoryView.hpp>
Classes | |
| class | IteratorImpl |
Public Types | |
| using | value_type = T |
| using | size_type = size_t |
| using | difference_type = ptrdiff_t |
| using | reference = T & |
| using | const_reference = const T & |
| using | pointer = T * |
| using | const_pointer = const T * |
| using | iterator = IteratorImpl< false > |
| using | const_iterator = IteratorImpl< true > |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
| using | ValueType = value_type |
| using | SizeType = size_type |
| using | DifferenceType = difference_type |
| using | Reference = reference |
| using | ConstReference = const_reference |
| using | Pointer = pointer |
| using | ConstPointer = const_pointer |
| using | Iterator = iterator |
| using | ConstIterator = const_iterator |
| using | ReverseIterator = reverse_iterator |
| using | ConstReverseIterator = const_reverse_iterator |
Public Member Functions | |
| StridedMemoryView ()=default | |
| Creates a new strided memory view with length 0. | |
| StridedMemoryView (std::nullptr_t) | |
| Creates a new strided memory view with length 0. | |
| 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. | |
| template<typename U > | |
| StridedMemoryView (const StridedMemoryView< U > &view) | |
| Creates a new strided memory view by casting the value of another. | |
| StridedMemoryView (const StridedMemoryView &)=default | |
| StridedMemoryView (StridedMemoryView &&)=default | |
| StridedMemoryView & | operator= (const StridedMemoryView &)=default |
| StridedMemoryView & | operator= (StridedMemoryView &&)=default |
| 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. | |
| void | reset (const SizeType size, const SizeType stride=defaultStride) |
| Resets the memory view size and stride. | |
| 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 given length. | |
| operator bool () const | |
| Checks if the memory view is valid. | |
| Pointer | get () noexcept |
| Gets a pointer to the first element in the view. | |
| ConstPointer | get () const noexcept |
| Gets a pointer to the first element in the view. | |
| Reference | at (SizeType i) |
Gets the element at the given index in the memory view. | |
| ConstReference | at (SizeType i) const |
Gets the element at the given index in the memory view. | |
| ConstReference | operator[] (const SizeType i) const |
| Reference | operator[] (const SizeType i) |
| ConstReference | front () const |
| Gets the first element on the memory view. | |
| Reference | front () |
| Gets the first element on the memory view. | |
| ConstReference | back () const |
| Gets the last element on the memory view. | |
| Reference | back () |
| Gets the last element on the memory view. | |
| Pointer | data () const noexcept |
| Gets a pointer to the first element in the view. | |
| Pointer | data () noexcept |
| Gets a pointer to the first element in the view. | |
| Iterator | begin () noexcept |
| Returns an iterator to the first element in the view. | |
| ConstIterator | begin () const noexcept |
| Returns an iterator to the first element in the view. | |
| ConstIterator | cbegin () const noexcept |
| Returns an iterator to the first element in the view. | |
| Iterator | end () noexcept |
| Returns an iterator to the past-the-last element in the view. | |
| ConstIterator | end () const noexcept |
| Returns an iterator to the past-the-last element in the view. | |
| ConstIterator | cend () const noexcept |
| Returns an iterator to the past-the-last element in the view. | |
| ReverseIterator | rbegin () noexcept |
| Returns an iterator to the first element in the view while iterating in reverse. | |
| ConstReverseIterator | rbegin () const noexcept |
| Returns an iterator to the first element in the view while iterating in reverse. | |
| ConstReverseIterator | crbegin () const noexcept |
| Returns an iterator to the first element in the view while iterating in reverse. | |
| ReverseIterator | rend () noexcept |
| Returns an iterator to the past-the-last element in the view while iterating in reverse. | |
| ConstReverseIterator | rend () const noexcept |
| Returns an iterator to the past-the-last element in the view while iterating in reverse. | |
| ConstReverseIterator | crend () const noexcept |
| Returns an iterator to the past-the-last element in the view while iterating in reverse. | |
| bool | empty () const noexcept |
| Checks if the view is empty and has zero elements. | |
| SizeType | size () const noexcept |
| Gets the size of the view as number of elements. | |
| SizeType | stride () const noexcept |
| Returns the stride of view, in bytes. | |
| SizeType | byteSize () const noexcept |
| Returns the size of view in bytes. | |
| template<typename U > | |
| StridedMemoryView< U > | as () const noexcept |
Casts the memory view from type T to type U. | |
Static Public Attributes | |
| static constexpr bool | isConst = std::is_const_v<T> |
| static constexpr SizeType | defaultStride = sizeof(T) |
Private Attributes | |
| Pointer | mPointer = nullptr |
| SizeType | mSize = 0 |
| SizeType | mStride = 0 |
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally changing its type) with a Vector-like interface, excluding the methods which change a vector's size.
The library includes two classes, for viewing const and non-const memory: StridedMemoryView, and StridedMemoryView<const T>. To automatically generate the appropriate pointer, use make_strided_memory_view(ptr, size). where size is the number of elements your view will have
make_strided_memory_view also has an overload for Vector like types which can be useful if you want a view at a slice of the vector you can use it like this: make_strided_memory_view<OptionalNewType>(vector, offset = 0) where the offset is from the beginning of the vector.
It is the responsibility of the user to make sure the pointer given to a view remains valid throughout the view's lifetime. All methods of the library assume this.
Copying a memory view will copy the underlying pointer (and not its data), resulting in another view to the same memory.
To copy the data from one memory view to another, you can use std::copy
Example:
int* buf = new int[10]; auto view = make_strided_memory_view(buf, 10); for (auto& i : view) i = 0; // fill buf with zeroes
| using CeresEngine::StridedMemoryView< T >::const_iterator = IteratorImpl<true> |
| using CeresEngine::StridedMemoryView< T >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using CeresEngine::StridedMemoryView< T >::ConstIterator = const_iterator |
| using CeresEngine::StridedMemoryView< T >::ConstPointer = const_pointer |
| using CeresEngine::StridedMemoryView< T >::ConstReference = const_reference |
| using CeresEngine::StridedMemoryView< T >::ConstReverseIterator = const_reverse_iterator |
| using CeresEngine::StridedMemoryView< T >::DifferenceType = difference_type |
| using CeresEngine::StridedMemoryView< T >::iterator = IteratorImpl<false> |
| using CeresEngine::StridedMemoryView< T >::reverse_iterator = std::reverse_iterator<iterator> |
| using CeresEngine::StridedMemoryView< T >::ReverseIterator = reverse_iterator |
| using CeresEngine::StridedMemoryView< T >::ValueType = value_type |
|
default |
Creates a new strided memory view with length 0.
|
inline |
Creates a new strided memory view with length 0.
|
inline |
Creates a new memory view from a raw pointer and length and a custom stride.
|
inlineexplicit |
Creates a new strided memory view by casting the value of another.
| U | The type of memory view to convert from. |
| view | The memory view to convert from. |
|
default |
|
default |
|
inlinenoexcept |
Casts the memory view from type T to type U.
| U | The type to view the data in the memory view as. |
Gets the element at the given index in the memory view.
operator[], this methods performs bounds checking.| index | The index of element to be returned. |
index.
|
inline |
Gets the element at the given index in the memory view.
operator[], this methods performs bounds checking.| index | The index of element to be returned. |
index.
|
inline |
Gets the last element on the memory view.
|
inline |
Gets the last element on the memory view.
|
inlinenoexcept |
Returns an iterator to the first element in the view.
|
inlinenoexcept |
Returns an iterator to the first element in the view.
|
inlinenoexcept |
Returns the size of view in bytes.
|
inlinenoexcept |
Returns an iterator to the first element in the view.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view.
|
inlinenoexcept |
Returns an iterator to the first element in the view while iterating in reverse.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view while iterating in reverse.
|
inlinenoexcept |
Gets a pointer to the first element in the view.
|
inlinenoexcept |
Gets a pointer to the first element in the view.
|
inlinenoexcept |
Checks if the view is empty and has zero elements.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view.
|
inline |
Gets the first element on the memory view.
|
inline |
Gets the first element on the memory view.
|
inlinenoexcept |
Gets a pointer to the first element in the view.
|
inlinenoexcept |
Gets a pointer to the first element in the view.
|
inlineexplicit |
Checks if the memory view is valid.
|
default |
|
default |
|
inline |
at, this methods does not perform any bounds checking.| index | The index of element to be returned. |
index.
|
inline |
at, this methods does not perform any bounds checking.| index | The index of element to be returned. |
index.
|
inlinenoexcept |
Returns an iterator to the first element in the view while iterating in reverse.
|
inlinenoexcept |
Returns an iterator to the first element in the view while iterating in reverse.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view while iterating in reverse.
|
inlinenoexcept |
Returns an iterator to the past-the-last element in the view while iterating in reverse.
|
inline |
Resets the memory view size and stride.
| size | The new size to set the memory view to. |
| stride | The new stride of the view. By default sizeof(T). |
|
inline |
Resets the memory view and sets it's value a new pointer.
| ptr | The pointer to set the memory view to. Default nullptr. |
| size | The length of the new view. Default 0. |
| stride | The new stride of the view. By default sizeof(T). |
|
inlinenoexcept |
Gets the size of the view as number of elements.
|
inline |
Slices the memory view by taking the element that starts at offset and returns a new view with the given length.
| offset | The offset of the view element of the new view. |
| length | The number of elements in the new view. |
|
inlinenoexcept |
Returns the stride of view, in bytes.
|
staticconstexpr |
|
private |
|
private |