UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypeBitSetBuilder.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
12template <typename TBaseType>
14{
19 template <typename TTestedType>
21};
22
32template<typename TBaseStruct, typename TUStructType = UScriptStruct, bool bTestInheritanceAtRuntime=WITH_STRUCTUTILS_DEBUG, typename TContainer=FStructTypeBitSet::FBitSetContainer>
33struct TTypeBitSetBuilder : TTypeBitSetBase<TTypeBitSetBuilder<TBaseStruct, TUStructType, bTestInheritanceAtRuntime>, TBaseStruct, TUStructType, TContainer&, bTestInheritanceAtRuntime>
34{
43
44private:
49 struct FBitSet : TContainer
50 {
55 inline bool operator==(const FBitSet& Other) const
56 {
57 return TContainer::CompareSetBits(Other, /*bMissingBitValue=*/false);
58 }
59 };
60
61public:
63 using FConstBitSet = const FBitSet;
64
66 friend Super;
67
71 using Super::Add;
72 using Super::Remove;
73 using Super::Contains;
74 using Super::operator+=;
75 using Super::operator-=;
76 using Super::operator+;
77 using Super::operator-;
79
86 : Super(const_cast<FBitSet&>(Source))
87 , StructTracker(InStructTracker)
88 {
89 }
90
91private:
99 : Super(const_cast<FBitSet&>(Source))
100 , StructTracker(InStructTracker)
101 {
102 StructTypesBitArray.AddAtIndex(BitToSet);
103 }
104
105public:
113 {
114 ensureMsgf(&Source.StructTracker == &StructTracker, TEXT("Assignment is only allowed between two instances created with the same StructTracker."));
115 StructTypesBitArray = Source.StructTypesBitArray;
116 return *this;
117 }
118
126 {
127 if constexpr (bTestInheritanceAtRuntime)
128 {
129 // Ensure the struct type derives from the base struct
131 , TEXT("Creating index for '%s' while it doesn't derive from the expected struct type %s")
132 , *InStructType.GetPathName(), *GetBaseUStruct()->GetName())))
133 {
134 return INDEX_NONE;
135 }
136 }
137
138 // Find or add the struct type index in the tracker
140 }
141
149 {
150 if constexpr (bTestInheritanceAtRuntime)
151 {
152 // Ensure the struct type derives from the base struct
154 , TEXT("Creating index for '%s' while it doesn't derive from the expected struct type %s")
155 , *InStructType.GetPathName(), *GetBaseUStruct()->GetName())))
156 {
157 return INDEX_NONE;
158 }
159 }
160
161 // Find or add the struct type index in the tracker
162 return InStructTracker.FindOrAddStructTypeIndex(InStructType);
163 }
164
171 template<typename T>
173 {
174 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
175 static const int32 TypeIndex = GetTypeIndex(InStructTracker, *UE::StructUtils::GetAsUStruct<T>());
176 return TypeIndex;
177 }
178
185 template<typename T>
187 {
188 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
189 static const int32 TypeIndex = GetTypeIndex(*UE::StructUtils::GetAsUStruct<T>());
190 return TypeIndex;
191 }
192
199 template<typename T>
201 {
202 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
204 }
205
212 {
213 return Cast<const TUStructType>(StructTracker.GetStructType(Index));
214 }
215
221 template<typename T>
222 inline int32 Add()
223 {
224 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
227 return StructTypeIndex;
228 }
229
235 template<typename T>
236 inline int32 Remove()
237 {
238 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
240 StructTypesBitArray.RemoveAtIndex(StructTypeIndex);
241 return StructTypeIndex;
242 }
243
248 inline void Remove(const TTypeBitSetBuilder& Other)
249 {
250 StructTypesBitArray -= Other.StructTypesBitArray;
251 }
252
258 template<typename T>
259 inline bool Contains() const
260 {
261 static_assert(FTraits::template IsValidType<T>, "Given struct is not a valid type for this TypeBitSetBuilder.");
263 return StructTypesBitArray.Contains(StructTypeIndex);
264 }
265
272 {
273 TTypeBitSetBuilder Result = *this;
274 Result -= Other;
275 return MoveTemp(Result);
276 }
277
284 {
285 TTypeBitSetBuilder Result(StructTracker);
286 Result.StructTypesBitArray = TBitArray<>::BitwiseOR(StructTypesBitArray, Other.StructTypesBitArray, EBitwiseOperatorFlags::MaxSize);
287 return MoveTemp(Result);
288 }
289
299
309
316 {
317 return *this & Other;
318 }
319
325 inline bool IsEquivalent(const TTypeBitSetBuilder& Other) const
326 {
327 return StructTypesBitArray.CompareSetBits(Other.StructTypesBitArray, /*bMissingBitValue=*/false);
328 }
329
335 inline bool HasAll(const TTypeBitSetBuilder& Other) const
336 {
337 return StructTypesBitArray.HasAll(Other.StructTypesBitArray);
338 }
339
345 inline bool HasAny(const TTypeBitSetBuilder& Other) const
346 {
347 return StructTypesBitArray.HasAny(Other.StructTypesBitArray);
348 }
349
355 inline bool HasNone(const TTypeBitSetBuilder& Other) const
356 {
357 return !StructTypesBitArray.HasAny(Other.StructTypesBitArray);
358 }
359
364 bool IsEmpty() const
365 {
366 return StructTypesBitArray.IsEmpty();
367 }
368
374 inline bool IsBitSet(const int32 BitIndex) const
375 {
376 return StructTypesBitArray.Contains(BitIndex);
377 }
378
384 {
385 return StructTypesBitArray.CountSetBits();
386 }
387
393 {
394 return StructTracker.Num();
395 }
396
402 static int32 GetMaxNum(const FStructTracker& StructTracker)
403 {
404 return StructTracker.Num();
405 }
406
412 inline bool operator==(const TTypeBitSetBuilder& Other) const
413 {
414 return StructTypesBitArray.CompareSetBits(Other.StructTypesBitArray, /*bMissingBitValue=*/false);
415 }
416
422 inline bool operator!=(const TTypeBitSetBuilder& Other) const
423 {
424 return !(*this == Other);
425 }
426
431 operator FConstBitSet() const
432 {
433 return static_cast<FConstBitSet&>(StructTypesBitArray);
434 }
435
443 template<typename TOutStructType, typename Allocator>
445 {
447 while (It)
448 {
449 if (It.GetValue())
450 {
451 // Get the struct type from the tracker and add to the output array
452 OutTypes.Add(Cast<TOutStructType>(StructTracker.GetStructType(It.GetIndex())));
453 }
454 ++It;
455 }
456 }
457
464 void ExportTypes(TFunctionRef<bool(const TUStructType*)> Callback) const
465 {
467 bool bKeepGoing = true;
468 while (bKeepGoing && It)
469 {
470 if (It.GetValue())
471 {
472 bKeepGoing = Callback(GetTypeAtIndex(It.GetIndex()));
473 }
474 ++It;
475 }
476 }
477
483 {
484 return StructTypesBitArray.GetAllocatedSize();
485 }
486
491 FString DebugGetStringDesc() const
492 {
493 #if WITH_STRUCTUTILS_DEBUG
496 return static_cast<FString>(Ar);
497 #else
498 return TEXT("DEBUG INFO COMPILED OUT");
499 #endif //WITH_STRUCTUTILS_DEBUG
500 }
501
502#if WITH_STRUCTUTILS_DEBUG
507 void DebugGetStringDesc(FOutputDevice& Ar) const
508 {
509 for (int32 Index = 0; Index < StructTypesBitArray.Num(); ++Index)
510 {
512 {
513 // Get the name of the struct type and log it
514 Ar.Logf(TEXT("%s, "), *StructTracker.DebugGetStructTypeName(Index).ToString());
515 }
516 }
517 }
518
524 {
525 for (int32 Index = 0; Index < StructTypesBitArray.Num(); ++Index)
526 {
528 {
529 OutFNames.Add(StructTracker.DebugGetStructTypeName(Index));
530 }
531 }
532 }
533
540 {
541 return StructTracker.DebugGetStructTypeName(StructTypeIndex);
542 }
543
549 {
550 return StructTracker.DebugGetAllStructTypes<TUStructType>();
551 }
552
559 static FName DebugGetStructTypeName(const FStructTracker& StructTracker, const int32 StructTypeIndex)
560 {
561 return StructTracker.DebugGetStructTypeName(StructTypeIndex);
562 }
563
570 {
571 return StructTracker.DebugGetAllStructTypes<TUStructType>();
572 }
573
574protected:
577 {
578 return StructTypesBitArray;
579 }
580
582 {
583 return StructTypesBitArray;
584 }
585#endif // WITH_STRUCTUTILS_DEBUG
586
587protected:
593 {
594 return StructTracker;
595 }
596
597private:
602 FStructTracker& StructTracker;
603};
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UNLIKELY(x)
Definition Platform.h:857
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition NameTypes.h:617
Definition OutputDevice.h:133
void Logf(const FmtType &Fmt)
Definition OutputDevice.h:234
Definition StringOutputDevice.h:21
Definition Array.h:670
Definition BitArray.h:350
static TBitArray BitwiseOR(const TBitArray< AllocatorA > &A, const TBitArray< AllocatorB > &B, EBitwiseOperatorFlags InFlags)
Definition BitArray.h:1321
Definition AssetRegistryState.h:50
U16 Index
Definition radfft.cpp:71
Definition BitArray.h:26
Definition StructTypeBitSet.h:275
const UStruct * GetStructType(const int32 StructTypeIndex) const
Definition StructTypeBitSet.h:316
UE_API int32 FindOrAddStructTypeIndex(const UStruct &InStructType)
Definition StructTypeBitSet.cpp:88
int32 Num() const
Definition StructTypeBitSet.h:331
Definition UnrealTypeTraits.h:40
Definition StructTypeBitSet.h:403
static const UStruct * GetBaseUStruct()
Definition StructTypeBitSet.h:484
FContainer StructTypesBitArray
Definition StructTypeBitSet.h:790
bool Contains(const FUStructType &InStructType) const
Definition StructTypeBitSet.h:571
void Add(const FUStructType &InStructType)
Definition StructTypeBitSet.h:510
void Remove(const FUStructType &InStructType)
Definition StructTypeBitSet.h:536
void ExportTypes(TArray< const TOutStructType *, Allocator > &OutTypes) const
Definition StructTypeBitSet.h:715
Definition TypeBitSetBuilder.h:34
TUStructType FUStructType
Definition TypeBitSetBuilder.h:38
TBaseStruct FBaseStruct
Definition TypeBitSetBuilder.h:40
TTypeBitSetBuilder(FStructTracker &InStructTracker, FConstBitSet &Source)
Definition TypeBitSetBuilder.h:85
SIZE_T GetAllocatedSize() const
Definition TypeBitSetBuilder.h:482
friend Super
Definition TypeBitSetBuilder.h:66
TTypeBitSetBuilder operator+(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:283
static const UStruct * GetBaseUStruct()
Definition StructTypeBitSet.h:484
FString DebugGetStringDesc() const
Definition TypeBitSetBuilder.h:491
bool operator!=(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:422
int32 Remove()
Definition TypeBitSetBuilder.h:236
void Remove(const TTypeBitSetBuilder &Other)
Definition TypeBitSetBuilder.h:248
int32 CountStoredTypes() const
Definition TypeBitSetBuilder.h:383
int32 GetTypeIndex() const
Definition TypeBitSetBuilder.h:186
static int32 GetTypeIndex(const FStructTracker &InStructTracker, const TUStructType &InStructType)
Definition TypeBitSetBuilder.h:148
bool operator==(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:412
bool HasNone(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:355
static TTypeBitSetBuilder GetTypeBitSet(const TUStructType &InStructType)
Definition TypeBitSetBuilder.h:200
TTypeBitSetBase< TTypeBitSetBuilder, TBaseStruct, TUStructType, TContainer &, bTestInheritanceAtRuntime > Super
Definition TypeBitSetBuilder.h:36
bool IsBitSet(const int32 BitIndex) const
Definition TypeBitSetBuilder.h:374
static int32 GetMaxNum(const FStructTracker &StructTracker)
Definition TypeBitSetBuilder.h:402
TTypeBitSetBuilder operator&(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:295
FContainer StructTypesBitArray
Definition StructTypeBitSet.h:790
const TUStructType * GetTypeAtIndex(const int32 Index)
Definition TypeBitSetBuilder.h:211
bool HasAny(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:345
TTypeBitSetBuilder operator|(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:305
bool IsEquivalent(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:325
bool Contains() const
Definition TypeBitSetBuilder.h:259
void ExportTypes(TFunctionRef< bool(const TUStructType *)> Callback) const
Definition TypeBitSetBuilder.h:464
bool IsEmpty() const
Definition TypeBitSetBuilder.h:364
const FBitSet FConstBitSet
Definition TypeBitSetBuilder.h:63
int32 Add()
Definition TypeBitSetBuilder.h:222
int32 GetMaxNum() const
Definition TypeBitSetBuilder.h:392
int32 GetTypeIndex(const TUStructType &InStructType) const
Definition TypeBitSetBuilder.h:125
TTypeBitSetBuilder GetOverlap(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:315
TTypeBitSetBuilder & operator=(const TTypeBitSetBuilder &Source)
Definition TypeBitSetBuilder.h:112
bool HasAll(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:335
void ExportTypes(TArray< const TOutStructType *, Allocator > &OutTypes) const
Definition TypeBitSetBuilder.h:444
TTypeBitSetBuilder operator-(const TTypeBitSetBuilder &Other) const
Definition TypeBitSetBuilder.h:271
static int32 GetTypeIndex(FStructTracker &InStructTracker)
Definition TypeBitSetBuilder.h:172
FStructTracker & GetStructTracker() const
Definition TypeBitSetBuilder.h:592
Definition TypeBitSetBuilder.h:14
static constexpr bool IsValidType
Definition TypeBitSetBuilder.h:20