|
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>
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 = T * |
| using | const_iterator = const T * |
| 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 | |
| MemoryView ()=default | |
| Creates a new memory view with length 0. | |
| MemoryView (std::nullptr_t) | |
| Creates a new memory view with length 0. | |
| MemoryView (T *ptr, const SizeType size) | |
| Creates a new memory view from a raw pointer and length. | |
| template<typename U > | |
| MemoryView (const MemoryView< U > &view) | |
| Creates a new memory view by casting the value of another. | |
| template<typename Container > | |
| MemoryView (Container &container, SizeType offset=0) | |
| Creates a new memory view from an STL-compatible contiguous container. | |
| MemoryView (const MemoryView &)=default | |
| MemoryView (MemoryView &&)=default | |
| MemoryView & | operator= (const MemoryView &)=default |
| MemoryView & | operator= (MemoryView &&)=default |
| void | reset (Pointer ptr=nullptr, const SizeType size=0) |
| Resets the memory view and sets it's value a new pointer. | |
| void | reset (const SizeType size) |
| Resets the memory view size. | |
| 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 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 index) |
Gets the element at the given index in the memory view. | |
| ConstReference | at (SizeType index) const |
Gets the element at the given index in the memory view. | |
| ConstReference | operator[] (SizeType index) const |
| Reference | operator[] (SizeType index) |
| 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. | |
| ConstPointer | data () const noexcept |
| Gets a pointer to the first element in the view. | |
| Pointer | data () const 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. | |
| template<typename U > | |
| MemoryView< U > | as () const noexcept |
Casts the memory view from type T to type U. | |
| String | hexdump () const |
| void | hexdump (std::ostream &stream) const |
| String | toHex () const |
| void | toHex (std::ostream &stream) const |
Static Public Attributes | |
| static constexpr bool | isMutable = !std::is_const_v<T> |
Private Attributes | |
| T * | mPointer = nullptr |
| A raw pointer that points to the beginning of the memory view. | |
| SizeType | mSize = 0 |
| The length of the view, in multiples of sizeof(T). | |
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: MemoryView, and MemoryView<const T>. To automatically generate the appropriate pointer, use make_memory_view(ptr, size). where size is the number of elements your view will have
make_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_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:
| using CeresEngine::MemoryView< T >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using CeresEngine::MemoryView< T >::ConstIterator = const_iterator |
| using CeresEngine::MemoryView< T >::ConstPointer = const_pointer |
| using CeresEngine::MemoryView< T >::ConstReference = const_reference |
| using CeresEngine::MemoryView< T >::ConstReverseIterator = const_reverse_iterator |
| using CeresEngine::MemoryView< T >::DifferenceType = difference_type |
| using CeresEngine::MemoryView< T >::reverse_iterator = std::reverse_iterator<iterator> |
| using CeresEngine::MemoryView< T >::ReverseIterator = reverse_iterator |
| using CeresEngine::MemoryView< T >::ValueType = value_type |
|
default |
Creates a new memory view with length 0.
|
inline |
Creates a new memory view with length 0.
|
inline |
Creates a new memory view from a raw pointer and length.
|
inlineexplicit |
Creates a new memory view by casting the value of another.
| U | The type of memory view to convert from. |
| view | The memory view to convert from. |
|
inline |
Creates a new memory view from an STL-compatible contiguous container.
| container | The container to create a view from. |
| offset | The number of elements to skip from the start of the container. |
|
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 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.
| String CeresEngine::MemoryView< T >::hexdump | ( | ) | const |
| void CeresEngine::MemoryView< T >::hexdump | ( | std::ostream & | stream | ) | const |
|
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.
Resets the memory view size.
| size | The new size to set the memory view to. |
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. |
|
inlinenoexcept |
Gets the size of the view as number of elements.
|
inlinenoexcept |
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. |
| String CeresEngine::MemoryView< T >::toHex | ( | ) | const |
| void CeresEngine::MemoryView< T >::toHex | ( | std::ostream & | stream | ) | const |
|
staticconstexpr |
A raw pointer that points to the beginning of the memory view.
|
private |
The length of the view, in multiples of sizeof(T).