UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypedElementSorter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include <type_traits>
10#include "Misc/EnumClassFlags.h"
11
13{
20 class ICoreProvider;
21
27
30 {
31 public:
32 virtual ~FColumnSorterInterface() = default;
33
34 enum class ESortType : uint8
35 {
66
68 Max
69 };
70
72 virtual ESortType GetSortType() const = 0;
73
75 virtual FText GetShortName() const = 0;
76
81 virtual int32 Compare(const ICoreProvider& Storage, RowHandle Left, RowHandle Right) const = 0;
82
90 virtual FPrefixInfo CalculatePrefix(const ICoreProvider& Storage, RowHandle Row, uint32 ByteIndex) const = 0;
91 };
92
93 template<FColumnSorterInterface::ESortType SortType, typename ColumnType>
95 {
96 static_assert(static_cast<uint32>(SortType) < static_cast<uint32>(ESortType::Max), "Unexpected sort type for TColumnSorterInterface.");
97 };
98
99 template<typename ColumnType>
100 class TColumnSorterInterface<FColumnSorterInterface::ESortType::FixedSize64, ColumnType> : public FColumnSorterInterface
101 {
102 public:
103 virtual ~TColumnSorterInterface() override = default;
104
105 int32 Compare(const ICoreProvider& Storage, RowHandle Left, RowHandle Right) const override final;
106 FPrefixInfo CalculatePrefix(const ICoreProvider& Storage, RowHandle Row, uint32 ByteIndex) const override final;
107 ESortType GetSortType() const override final;
108
109 protected:
110 virtual FPrefixInfo CalculatePrefix(const ColumnType& Column, uint32 ByteIndex) const = 0;
111 };
112
113 template<typename ColumnType>
115 {
116 public:
117 virtual ~TColumnSorterInterface() override = default;
118
119 int32 Compare(const ICoreProvider& Storage, RowHandle Left, RowHandle Right) const override final;
120 FPrefixInfo CalculatePrefix(const ICoreProvider& Storage, RowHandle Row, uint32 ByteIndex) const override final;
121 ESortType GetSortType() const override final;
122
123 protected:
124 virtual FPrefixInfo CalculatePrefix(const ColumnType& Column, uint32 ByteIndex) const = 0;
125 };
126
127 template<typename ColumnType>
129 {
130 public:
131 virtual ~TColumnSorterInterface() override = default;
132
133 int32 Compare(const ICoreProvider& Storage, RowHandle Left, RowHandle Right) const override final;
134 FPrefixInfo CalculatePrefix(const ICoreProvider& Storage, RowHandle Row, uint32 ByteIndex) const override final;
135 ESortType GetSortType() const override final;
136
137 protected:
138 virtual int32 Compare(const ColumnType& Left, const ColumnType& Right) const = 0;
139 };
140
141 template<typename ColumnType>
143 {
144 public:
145 virtual ~TColumnSorterInterface() override = default;
146
147 int32 Compare(const ICoreProvider& Storage, RowHandle Left, RowHandle Right) const override final;
148 FPrefixInfo CalculatePrefix(const ICoreProvider& Storage, RowHandle Row, uint32 ByteIndex) const override final;
149 ESortType GetSortType() const override final;
150
151 protected:
152 virtual int32 Compare(const ColumnType& Left, const ColumnType& Right) const = 0;
153 virtual FPrefixInfo CalculatePrefix(const ColumnType& Column, uint32 ByteIndex) const = 0;
154 };
155
156 namespace Private
157 {
158 template<typename T>
159 concept SortNumericValue = std::is_integral_v<T> || std::is_floating_point_v<T>;
160
161 template <typename T>
162 struct TSortStringViewType : std::false_type {};
163
164 template <typename T>
165 struct TSortStringViewType<TStringView<T>> : std::true_type {};
166
167 template<typename T>
168 concept SortStringViewValue = TSortStringViewType<T>::value;
169
170 template<typename T>
173 std::is_same_v<T, FString> ||
174 std::is_same_v<T, FAnsiString> ||
175 std::is_same_v<T, FWideString> ||
176 std::is_same_v<T, FUtf8String>;
177
178 template<typename T>
179 concept SortStringVariantType = SortStringViewCopyableType<T> || std::is_same_v<T, FText>;
180
181 template<typename T>
182 concept NameValue = std::is_same_v<T, FName>;
183 }
184
195 template<typename T>
196 concept SortCase = std::is_same_v<T, FSortCaseSensitive> || std::is_same_v<T, FSortCaseInsensitive>;
197
198 template<SortCase Casing, Private::SortStringViewValue StringView>
200 {
201 using StringViewType = StringView;
202 static constexpr bool bIsCaseSensitive = std::is_same_v<Casing, FSortCaseSensitive>;
203 static constexpr ESearchCase::Type SearchCase = bIsCaseSensitive ? ESearchCase::CaseSensitive : ESearchCase::IgnoreCase;
204
205 TSortStringView() = default;
206
207 template<Private::SortStringViewCopyableType ViewType>
208 TSortStringView(const ViewType& InView) : View(InView) {}
209 template<Private::SortStringViewCopyableType ViewType>
210 TSortStringView& operator=(const ViewType& InView) { this->View = InView; return *this; }
211
212 TSortStringView(const FText& Text) : View(Text.ToString()) {}
213 TSortStringView& operator=(const FText& Text) { this->View = Text.ToString(); return *this; }
214
215 template<SortCase TargetCasing, Private::SortStringViewCopyableType ViewType>
216 TSortStringView(TargetCasing, const ViewType& String) : View(String) { static_assert(std::is_same_v<Casing, TargetCasing>); }
217 template<SortCase TargetCasing>
218 TSortStringView(TargetCasing, const FText& Text) : View(Text.ToString()) { static_assert(std::is_same_v<Casing, TargetCasing>); }
219
220 bool operator==(const TSortStringView& Rhs) const { return View.Equals(Rhs.View, SearchCase) == true; }
221 bool operator!=(const TSortStringView& Rhs) const { return View.Equals(Rhs.View, SearchCase) == false; }
222 bool operator< (const TSortStringView& Rhs) const { return View.Compare(Rhs.View, SearchCase) < 0; }
223 bool operator<=(const TSortStringView& Rhs) const { return View.Compare(Rhs.View, SearchCase) <= 0; }
224 bool operator> (const TSortStringView& Rhs) const { return View.Compare(Rhs.View, SearchCase) > 0; }
225 bool operator>=(const TSortStringView& Rhs) const { return View.Compare(Rhs.View, SearchCase) >= 0; }
226
227 StringView View;
228 };
229
230 template<SortCase Casing, Private::SortStringViewCopyableType View>
232 template<SortCase Casing>
234
235 enum class ENameSortBy : bool { Id, String };
236
238 {
239 Default = 0,
240 WithNone = 1 << 0,
241 RemoveLeadingSlash = 1 << 1,
242 };
244
245
246 template<ESortByNameFlags InFlags = ESortByNameFlags::Default>
247 struct TSortByName { static const ESortByNameFlags Flags = InFlags; };
249 struct FSortById {};
250
251 template<typename>
252 struct IsSortByName : std::false_type {};
253 template<ESortByNameFlags Flags>
254 struct IsSortByName<TSortByName<Flags>> : std::true_type {};
255
256 template<typename T>
257 concept SortBy = std::is_same_v<T, FSortById> || IsSortByName<T>::value;
258
259 template<SortBy By>
261 {
262 constexpr static bool bIsById = std::is_same_v<By, FSortById>;
263 using CompareType = std::conditional_t<bIsById, int32, FString>;
264 constexpr static bool bIsFixedSize = bIsById;
265
266 TSortNameView() = default;
267 explicit TSortNameView(const FName& Name) : View(&Name) {}
268 TSortNameView& operator=(const FName& Name);
269
270 template<SortBy TargetBy>
271 TSortNameView(TargetBy, const FName& Name) : View(&Name) { static_assert(std::is_same_v<By, TargetBy>); }
272
273 uint32 GetByteSize() const;
274 constexpr static uint32 GetElementSize();
275 FPrefixInfo CalculatePrefix(int32 CurrentIndex, int32 ByteIndex) const;
276
277 int32 Compare(const FName& Rhs) const;
278 int32 Compare(const TSortNameView& Rhs) const;
279 bool operator==(const TSortNameView& Rhs) const;
280 bool operator!=(const TSortNameView& Rhs) const;
281 bool operator< (const TSortNameView& Rhs) const;
282 bool operator<=(const TSortNameView& Rhs) const;
283 bool operator> (const TSortNameView& Rhs) const;
284 bool operator>=(const TSortNameView& Rhs) const;
285
286 const FName* View = nullptr;
287 mutable CompareType Cache = {};
288 mutable bool bIsCached = false;
289
290 private:
291 int32 Compare(const FName& Lhs, const FName& Rhs) const;
292 void CacheCompareType() const;
293 };
294
295 template<SortBy By>
297
298 template<typename... ValueTypes>
299 FPrefixInfo CreateSortPrefix(uint32 ByteIndex, ValueTypes&&... Values);
300
308 namespace Private
309 {
310 template<typename T>
311 constexpr uint64 MoveToLocation(int32 ByteIndex, T Value);
312
313 template<typename Numeric>
314 constexpr auto Rebase(Numeric Value);
315 }
316
317 template<typename ValueType>
319 {
320 // Used to short-circuit several calls to minimize noise in the error output of the compiler.
321 static constexpr bool bIsSupportedType = false;
322
323 // Check is just a random way to say "false" so the compiler doesn't evaluate the assert until an attempt is made to instance
324 // this version.
325 static_assert(sizeof(ValueType) == 0, "Unsupported sort type.");
326 };
327
328 template<Private::SortNumericValue NumericType>
329 struct TSortTypeInfo<NumericType>
330 {
331 static constexpr bool bIsSupportedType = true;
332 static constexpr bool bIsFixedSize = true;
333 constexpr static uint32 GetByteSize(NumericType Value) { return sizeof(NumericType); }
334 constexpr static uint32 GetElementSize() { return sizeof(NumericType); }
335 constexpr static FPrefixInfo CalculatePrefix(int32 CurrentIndex, int32 ByteIndex, NumericType Value)
336 {
337 // Due to an issue with MSVC resolving forward declared partially specialized templates that use concepts, this
338 // can't be moved to the .inl file.
339 return FPrefixInfo
340 {
341 .Prefix = Private::MoveToLocation(CurrentIndex - ByteIndex, Private::Rebase(Value)),
342 .bHasRemainingBytes = false
343 };
344 }
345 };
346
347 template<SortCase Casing, typename T>
349 {
350 static constexpr bool bIsSupportedType = true;
351 static constexpr bool bIsFixedSize = false;
352 constexpr static uint32 GetByteSize(TSortStringView<Casing, T> Value);
353 constexpr static uint32 GetElementSize();
354 constexpr static FPrefixInfo CalculatePrefix(
355 int32 CurrentIndex, int32 ByteIndex, TSortStringView<Casing, T> Value);
356 };
357
358 template<typename StringType> requires Private::SortStringVariantType<StringType>
359 struct TSortTypeInfo<StringType>
360 {
361 static constexpr bool bIsSupportedType = false;
362 static_assert(sizeof(StringType) == 0,
363 "Strings and string views are not directly supported. Use `TSortStringView` to indicate if sorting is case sensitive or not.");
364 };
365
366 template<SortBy By>
368 {
369 static constexpr bool bIsSupportedType = true;
370 static constexpr bool bIsFixedSize = TSortNameView<By>::bIsFixedSize;
371 static uint32 GetByteSize(const TSortNameView<By>& Value) { return Value.GetByteSize(); };
374 int32 CurrentIndex, int32 ByteIndex, TSortNameView<By> Value) { return Value.CalculatePrefix(CurrentIndex, ByteIndex); };
375 };
376
377 // Not a direct specialization, but done through requirements to prevent the compiler from evaluating the static_assert when it's not instanced.
378 template<Private::NameValue NameType>
380 {
381 static constexpr bool bIsSupportedType = false;
382 static_assert(sizeof(NameType) == 0,
383 "FNames are not directly supported. Use `TSortNameView` to indicate if sorting is based on a string or the unique FName number.");
384 };
385} // namespace UE::Editor::DataStorage
386
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
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
bool operator<(const FTextFormatString &LHS, const FTextFormatString &RHS)
Definition ITextFormatArgumentModifier.h:147
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
UE_REWRITE constexpr bool operator>(const LhsType &Lhs, const RhsType &Rhs)
Definition UEOps.h:90
UE_REWRITE constexpr bool operator<=(const LhsType &Lhs, const RhsType &Rhs)
Definition UEOps.h:118
UE_REWRITE constexpr bool operator>=(const LhsType &Lhs, const RhsType &Rhs)
Definition UEOps.h:104
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition Text.h:385
Definition StringView.h:107
Definition TypedElementSorter.h:30
virtual int32 Compare(const ICoreProvider &Storage, RowHandle Left, RowHandle Right) const =0
virtual ESortType GetSortType() const =0
virtual FPrefixInfo CalculatePrefix(const ICoreProvider &Storage, RowHandle Row, uint32 ByteIndex) const =0
ESortType
Definition TypedElementSorter.h:35
Definition TypedElementDataStorageInterface.h:65
Definition TypedElementSorter.h:95
Definition TypedElementSorter.h:182
Definition TypedElementSorter.h:159
Definition TypedElementSorter.h:257
Definition TypedElementSorter.h:196
Type
Definition CString.h:21
@ IgnoreCase
Definition CString.h:26
@ CaseSensitive
Definition CString.h:23
Definition OverriddenPropertySet.cpp:45
Definition CommonTypes.cpp:10
ESortByNameFlags
Definition TypedElementSorter.h:238
FPrefixInfo CreateSortPrefix(uint32 ByteIndex, ValueTypes &&... Values)
Definition TypedElementSorter.inl:502
ENameSortBy
Definition TypedElementSorter.h:235
uint64 RowHandle
Definition Handles.h:15
Definition NumericLimits.h:41
Definition TypedElementSorter.h:23
uint64 Prefix
Definition TypedElementSorter.h:24
bool bHasRemainingBytes
Definition TypedElementSorter.h:25
Definition TypedElementSorter.h:249
Definition TypedElementSorter.h:194
Definition TypedElementSorter.h:193
Definition TypedElementSorter.h:252
Definition TypedElementSorter.h:247
Definition TypedElementSorter.h:261
TSortNameView(const FName &Name)
Definition TypedElementSorter.h:267
TSortNameView(TargetBy, const FName &Name)
Definition TypedElementSorter.h:271
std::conditional_t< bIsById, int32, FString > CompareType
Definition TypedElementSorter.h:263
Definition TypedElementSorter.h:200
bool operator==(const TSortStringView &Rhs) const
Definition TypedElementSorter.h:220
TSortStringView(TargetCasing, const ViewType &String)
Definition TypedElementSorter.h:216
TSortStringView(const ViewType &InView)
Definition TypedElementSorter.h:208
TSortStringView & operator=(const ViewType &InView)
Definition TypedElementSorter.h:210
bool operator!=(const TSortStringView &Rhs) const
Definition TypedElementSorter.h:221
TSortStringView(TargetCasing, const FText &Text)
Definition TypedElementSorter.h:218
bool operator<=(const TSortStringView &Rhs) const
Definition TypedElementSorter.h:223
TSortStringView(const FText &Text)
Definition TypedElementSorter.h:212
StringView View
Definition TypedElementSorter.h:227
StringView StringViewType
Definition TypedElementSorter.h:201
TSortStringView & operator=(const FText &Text)
Definition TypedElementSorter.h:213
bool operator>=(const TSortStringView &Rhs) const
Definition TypedElementSorter.h:225
static constexpr FPrefixInfo CalculatePrefix(int32 CurrentIndex, int32 ByteIndex, NumericType Value)
Definition TypedElementSorter.h:335
static constexpr uint32 GetElementSize()
Definition TypedElementSorter.h:334
static constexpr uint32 GetByteSize(NumericType Value)
Definition TypedElementSorter.h:333
static constexpr uint32 GetElementSize()
Definition TypedElementSorter.h:372
static FPrefixInfo CalculatePrefix(int32 CurrentIndex, int32 ByteIndex, TSortNameView< By > Value)
Definition TypedElementSorter.h:373
static uint32 GetByteSize(const TSortNameView< By > &Value)
Definition TypedElementSorter.h:371
Definition TypedElementSorter.h:319