UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SplineTypeRegistry.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "SplineTypeId.h"
8#include "SplineInterfaces.h"
10
11namespace UE
12{
13namespace Geometry
14{
15namespace Spline
16{
17
23{
24public:
25 // Type ID definition
27
32
42 static inline bool RegisterType(
44 const FString& ImplName,
45 const FString& ValueTypeName,
46 FactoryFunction Factory)
47 {
48 // Check if this type is already registered
50 FScopeLock Lock(&GetRegistryLock());
51
52 // Check for existing registration with same ID but different names (hash collision)
53 if (const TPair<FString, FString>* ExistingNames = GetIdToNames().Find(TypeId))
54 {
56 ExistingNames->Key, ExistingNames->Value))
57 {
58 // Hash collision detected - registration failed
59 return false;
60 }
61
62 // Type already registered with same names - just check that factory exists
63 if (!GetFactories().Contains(TypeId))
64 {
65 // Factory missing but ID registered - add missing factory
66 GetFactories().Add(TypeId, MoveTemp(Factory));
67 }
68
69 // Already registered correctly
70 return true;
71 }
72
73 // New registration - add to all maps
74 GetIdToNames().Add(TypeId, NamePair);
75 GetNamesToId().Add(NamePair, TypeId);
76 GetFactories().Add(TypeId, MoveTemp(Factory));
77
78 UE_LOG(LogSpline, Log, TEXT("Registered spline type: TypeId=0x%08X, Impl=%s, Value=%s"),
80
81 return true;
82 }
83
91 {
92 FScopeLock Lock(&GetRegistryLock());
93
94 const FactoryFunction* Factory = GetFactories().Find(TypeId);
95 if (Factory)
96 {
97 return (*Factory)();
98 }
99
100 // Log helpful error message
101 const TPair<FString, FString>* Names = GetIdToNames().Find(TypeId);
102 if (Names)
103 {
104 UE_LOG(LogSpline, Warning, TEXT("No factory for type ID 0x%08X (Impl=%s, Value=%s)"),
105 TypeId, *Names->Key, *Names->Value);
106 }
107 else
108 {
109 UE_LOG(LogSpline, Warning, TEXT("Unknown type ID 0x%08X"), TypeId);
110 }
111
112 return nullptr;
113 }
114
123 const FString& ImplName,
124 const FString& ValueTypeName)
125 {
127
128 FScopeLock Lock(&GetRegistryLock());
129
130 const TypeId* TypeId = GetNamesToId().Find(NamePair);
131 if (TypeId && *TypeId != 0)
132 {
133 return CreateSpline(*TypeId);
134 }
135
136 UE_LOG(LogSpline, Warning, TEXT("No registered type for Impl=%s, Value=%s"),
138 return nullptr;
139 }
140
149 static inline bool GetTypeNames(
151 FString& OutImplName,
152 FString& OutValueTypeName)
153 {
154 FScopeLock Lock(&GetRegistryLock());
155
156 const TPair<FString, FString>* Names = GetIdToNames().Find(TypeId);
157 if (Names)
158 {
159 OutImplName = Names->Key;
160 OutValueTypeName = Names->Value;
161 return true;
162 }
163 return false;
164 }
165
173 static inline TypeId GetTypeId(
174 const FString& ImplName,
175 const FString& ValueTypeName)
176 {
178
179 FScopeLock Lock(&GetRegistryLock());
180
181 const TypeId* Id = GetNamesToId().Find(NamePair);
182 if (Id)
183 {
184 return *Id;
185 }
186 return 0;
187 }
188
189private:
193 static inline FCriticalSection& GetRegistryLock()
194 {
196 return RegistryLock;
197 }
198
202 static inline TMap<TypeId, TPair<FString, FString>>& GetIdToNames()
203 {
205 return IdToNames;
206 }
207
211 static inline TMap<TPair<FString, FString>, TypeId>& GetNamesToId()
212 {
214 return NamesToId;
215 }
216
220 static inline TMap<TypeId, FactoryFunction>& GetFactories()
221 {
222 static TMap<TypeId, FactoryFunction> Factories;
223 return Factories;
224 }
225};
226
234template<typename DerivedType, typename ValueType>
236{
237protected:
238 // Constructor ensures type is registered
240 {
241 static bool bRegistered = false;
242 if (!bRegistered)
243 {
244 bRegistered = true;
245 RegisterType();
246 }
247 }
248
249 // Virtual destructor for safe inheritance
250 virtual ~TSelfRegisteringSpline() = default;
251
252private:
253 // Register this type with the type registry
254 static inline void RegisterType()
255 {
256 // Get type information from the derived class
257 FSplineTypeRegistry::TypeId TypeId = DerivedType::GetStaticTypeId();
258 FString ImplName = DerivedType::GetSplineTypeName();
259 FString ValueName = TSplineValueTypeTraits<ValueType>::Name;
260
261 // Register factory function
263 TypeId,
264 ImplName,
265 ValueName,
266 []() { return MakeUnique<DerivedType>(); }
267 );
268 }
269};
270
271} // namespace Spline
272} // namespace Geometry
273} // namespace UE
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
Definition ScopeLock.h:141
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
static bool CheckTypeIdConflict(IdType TypeId, const FString &ImplName, const FString &ValueTypeName, const FString &ExistingImplName, const FString &ExistingValueTypeName)
Definition SplineTypeId.h:96
uint32 IdType
Definition SplineTypeId.h:33
Definition SplineTypeRegistry.h:23
FSplineTypeId::IdType TypeId
Definition SplineTypeRegistry.h:26
static bool GetTypeNames(TypeId TypeId, FString &OutImplName, FString &OutValueTypeName)
Definition SplineTypeRegistry.h:149
static TypeId GetTypeId(const FString &ImplName, const FString &ValueTypeName)
Definition SplineTypeRegistry.h:173
static TUniquePtr< ISplineInterface > CreateSpline(const FString &ImplName, const FString &ValueTypeName)
Definition SplineTypeRegistry.h:122
static bool RegisterType(TypeId TypeId, const FString &ImplName, const FString &ValueTypeName, FactoryFunction Factory)
Definition SplineTypeRegistry.h:42
static TUniquePtr< ISplineInterface > CreateSpline(TypeId TypeId)
Definition SplineTypeRegistry.h:90
Definition SplineTypeRegistry.h:236
TSelfRegisteringSpline()
Definition SplineTypeRegistry.h:239
Definition AdvancedWidgetsModule.cpp:13
Definition Tuple.h:652