UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UniversalObjectLocatorResolveParameterBuffer.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
8{
9
10
11template<typename T, typename ...ArgTypes>
13{
14 const UScriptStruct* ParameterStruct = ParameterTypeHandle.Resolve();
15 if (!ensureMsgf(ParameterStruct, TEXT("Parameter struct is no longer registered!")))
16 {
17 return nullptr;
18 }
19
20 const uint8 ParameterIndex = ParameterTypeHandle.GetIndex();
21
22 const uint32 ParameterBit = 1 << ParameterIndex;
23 return static_cast<T*>(AddParameterImpl<T>(ParameterBit, Forward<ArgTypes>(InArgs)...));
24}
25
26
27template<typename ParameterType, typename ...ArgTypes>
29{
30 checkf((AllParameters & ParameterBit) == 0, TEXT("Parameter already exists!"));
31
32 // Add the enum entry
34
35 // Find the index of the new Parameter by counting how many bits are set before it
36 // For example, given ParameterBit=0b00010000 and AllParameters=0b00011011:
37 // (ParameterBit-1) = 0b00001111
38 // AllParameters & (ParameterBit-1) = 0b00001011
39 // CountBits(0b00001011) = 3
40 const int32 NewParameterIndex = static_cast<int32>(FMath::CountBits(AllParameters & (ParameterBit-1u)));
41
43
44 uint64 RequiredAlignment = FMath::Max(alignof(ParameterType), alignof(FResolveParameterHeader));
45
46 const int32 ExistingNum = static_cast<int32>(Num);
47
48 // Compute our required alignment for the allocation
49 {
50 for (int32 Index = 0; Index < ExistingNum; ++Index)
51 {
52 RequiredAlignment = FMath::Max(RequiredAlignment, (uint64)ExistingHeaders[Index].Alignment);
53 }
54 }
55
57
58 // Compute the required size of our allocation
59 {
60 // Allocate space for headers
62
63 int32 Index = 0;
64
65 // Count up the sizes and alignments of pre-existing parameters that exist before this new entry
66 for (; Index < NewParameterIndex; ++Index)
67 {
70 }
71
72 // Count up the size and alignment for the new parameter
73 RequiredSizeof = Align(RequiredSizeof, alignof(ParameterType));
74 RequiredSizeof += sizeof(ParameterType);
75 ++Index;
76
77 // Now count up the sizes and alignments of pre-existing parameters that exist after this new entry
78 for (; Index < ExistingNum+1; ++Index)
79 {
82 }
83 }
84
85 check( RequiredAlignment <= 0XFF );
86
88
90
92
93 // Make a new allocation if necessary
94 const bool bNeedsReallocation = !IsAligned(Memory, RequiredAlignment) || RequiredSizeof > Capacity;
96 {
98 check(RequiredCapacity <= std::numeric_limits<uint16>::max());
99
100 // Use the greater of the required size or double the current size to allow some additional capcity
101 Capacity = static_cast<uint16>(FMath::Max(RequiredSizeof, uint64(Capacity)*2));
102 Memory = reinterpret_cast<uint8*>(FMemory::Malloc(Capacity, RequiredAlignment));
103
104 bCanFreeMemory = true;
105 }
106
107 // We now have an extra entry
108 ++Num;
109
111
113 {
114 // Go back
115 ParameterPtr -= ExistingHeaders[OldIndex].Sizeof;
116 ParameterPtr = AlignDown(ParameterPtr, ExistingHeaders[OldIndex].Alignment);
117
118 void* OldParameter = ExistingHeaders[OldIndex].Resolve(OldAllocation);
120
121 // Overwrite the old header with its new position for error checking when we write the new header
122 ExistingHeaders[OldIndex].ParameterOffset = static_cast<uint16>(ParameterPtr-Memory);
123 };
124
125 // Relocate old structs that proceed the new index
126 for (int32 Index = static_cast<int32>(Num) - 1; Index > NewParameterIndex; --Index)
127 {
129 }
130
131 // Make the new entry
132 {
133 ParameterPtr -= sizeof(ParameterType);
134 ParameterPtr = AlignDown(ParameterPtr, alignof(ParameterType));
135
136 ParameterType* NewParameterPtr = reinterpret_cast<ParameterType*>(ParameterPtr);
137
138 // Allocate the new type
139 new (NewParameterPtr) ParameterType { Forward<ArgTypes>(InArgs)... };
140
141 static_assert(alignof(ParameterType) < 0x7F, "Required alignment of parameter must fit in 7 bytes");
142 }
143
145 static_cast<uint16>(ParameterPtr-Memory),
146 sizeof(ParameterType),
147 alignof(ParameterType)
148 };
149
150 // Relocate the entries that are before the new one
151 for (int32 Index = NewParameterIndex-1; Index >= 0; --Index)
152 {
154 }
155
156 // Check that we have enough space before for the headers (this should always be the case)
158
160
161 for (int32 Index = static_cast<int32>(Num)-1; Index > NewParameterIndex; --Index)
162 {
164 };
165
166 {
168 }
169
170 if (Memory != OldAllocation)
171 {
172 for (int32 Index = NewParameterIndex-1; Index >= 0; --Index)
173 {
175 };
176 }
177
178 // Tidy up the old allocation. We do not call destructors here because we relocated everything.
180 {
182 }
183
184 return static_cast<ParameterType*>(NewHeaders[NewParameterIndex].Resolve(Memory));
185}
186
187} // namespace UE::UniversalObjectLocator
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
constexpr T AlignDown(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:34
constexpr bool IsAligned(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:50
#define check(expr)
Definition AssertionMacros.h:314
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Class.h:1720
Definition AnimInstanceLocatorFragment.cpp:19
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memmove(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:109
static FORCENOINLINE CORE_API void Free(void *Original)
Definition UnrealMemory.cpp:685
uint32 AllParameters
Definition UniversalObjectLocatorResolveParameterBuffer.h:146
ParameterType * AddParameterImpl(uint32 ParameterBit, ArgTypes &&... InArgs)
Definition UniversalObjectLocatorResolveParameterBuffer.inl:28
uint8 * Memory
Definition UniversalObjectLocatorResolveParameterBuffer.h:143
uint16 Capacity
Definition UniversalObjectLocatorResolveParameterBuffer.h:149
T * AddParameter(TParameterTypeHandle< T > ParameterTypeHandle, ArgTypes &&... InArgs)
Definition UniversalObjectLocatorResolveParameterBuffer.inl:12
uint8 Num
Definition UniversalObjectLocatorResolveParameterBuffer.h:152
bool bCanFreeMemory
Definition UniversalObjectLocatorResolveParameterBuffer.h:155
Definition UniversalObjectLocatorResolveParameterBuffer.h:20
Definition UniversalObjectLocatorParameterTypeHandle.h:84