MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
ArrayViews.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15
17{
18
19 /**
20 * Makes a non-owning byte array view of the source typed array.
21 * @tparam T Source type
22 * @tparam Allocator (optional) Array allocator
23 * @param array Source array (going out of scope while working with the view will result in undefined behavior)
24 * @return a non-owning byte array view of the source array
25 */
26 template<typename T, typename Allocator = FDefaultAllocator>
27 TArrayView<uint8> MakeByteArrayViewFromTyped(TArray<T, Allocator>& array)
28 {
29 return MakeArrayView(
30 reinterpret_cast<uint8*>(array.GetData()),
31 array.Num() * sizeof(T)
32 );
33 }
34
35 /**
36 * Makes a non-owning typed array view of the source byte array.
37 * @tparam T Destination type
38 * @tparam Allocator (optional) Array allocator
39 * @param array Source array (going out of scope while working with the view will result in undefined behavior)
40 * @return a non-owning typed array view of the source array
41 */
42 template<typename T, typename Allocator = FDefaultAllocator>
43 TArrayView<T> MakeTypedArrayViewFromBytes(TArray<uint8, Allocator>& array)
44 {
45 return MakeArrayView(
46 reinterpret_cast<T*>(array.GetData()),
47 array.Num() / sizeof(T)
48 );
49 }
50}
TArrayView< uint8 > MakeByteArrayViewFromTyped(TArray< T, Allocator > &array)
Definition ArrayViews.h:27
TArrayView< T > MakeTypedArrayViewFromBytes(TArray< uint8, Allocator > &array)
Definition ArrayViews.h:43