UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RangeBound.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
9#include "Misc/FrameNumber.h"
10#include "Misc/DateTime.h"
11
13{
17 enum Type
18 {
21
24
26 Open
27 };
28}
29
30
34template<typename ElementType>
36{
37public:
38
39 /*~ Typedef used to pass/return small element types by value rather than const& */
41
48 : Type(ERangeBoundTypes::Open)
49 , Value()
50 { }
51
62
63public:
64
71 [[nodiscard]] bool operator==(const TRangeBound& Other) const
72 {
73 return ((Type == Other.Type) && (IsOpen() || (Value == Other.Value)));
74 }
75
82 [[nodiscard]] bool operator!=(const TRangeBound& Other) const
83 {
84 return ((Type != Other.Type) || (!IsOpen() && (Value != Other.Value)));
85 }
86
87public:
88
98 {
100
101 return Value;
102 }
103
104
113 inline void SetValue(ElementValueOrConstRef NewValue)
114 {
116
117 Value = NewValue;
118 }
119
126 {
127 return (Type != ERangeBoundTypes::Open);
128 }
129
136 {
137 return (Type == ERangeBoundTypes::Exclusive);
138 }
139
146 {
147 return (Type == ERangeBoundTypes::Inclusive);
148 }
149
156 {
157 return (Type == ERangeBoundTypes::Open);
158 }
159
160public:
161
169 friend class FArchive& operator<<(class FArchive& Ar, TRangeBound& Bound)
170 {
171 return Ar << (uint8&)Bound.Type << Bound.Value;
172 }
173
180 friend uint32 GetTypeHash(const TRangeBound& Bound)
181 {
182 return (GetTypeHash((uint8)Bound.Type) + 23 * GetTypeHash(Bound.Value));
183 }
184
185public:
186
194 {
195 TRangeBound Result;
196
197 Result.Type = ERangeBoundTypes::Exclusive;
198 Result.Value = Value;
199
200 return Result;
201 }
202
210 {
211 TRangeBound Result;
212
213 Result.Type = ERangeBoundTypes::Inclusive;
214 Result.Value = Value;
215
216 return Result;
217 }
218
224 [[nodiscard]] static inline TRangeBound Open()
225 {
226 TRangeBound Result;
227
228 Result.Type = ERangeBoundTypes::Open;
229
230 return Result;
231 }
232
233public:
234
242 [[nodiscard]] static inline TRangeBound FlipInclusion(const TRangeBound& Bound)
243 {
244 if (Bound.IsExclusive())
245 {
246 return Inclusive(Bound.Value);
247 }
248
249 if (Bound.IsInclusive())
250 {
251 return Exclusive(Bound.Value);
252 }
253
254 return Bound;
255 }
256
264 [[nodiscard]] static inline const TRangeBound& MaxLower(const TRangeBound& A, const TRangeBound& B)
265 {
266 if (A.IsOpen()) { return B; }
267 if (B.IsOpen()) { return A; }
268 if (A.Value > B.Value) { return A; }
269 if (B.Value > A.Value) { return B; }
270 if (A.IsExclusive()) { return A; }
271
272 return B;
273 }
274
282 [[nodiscard]] static inline const TRangeBound& MaxUpper(const TRangeBound& A, const TRangeBound& B)
283 {
284 if (A.IsOpen()) { return A; }
285 if (B.IsOpen()) { return B; }
286 if (A.Value > B.Value) { return A; }
287 if (B.Value > A.Value) { return B; }
288 if (A.IsInclusive()) { return A; }
289
290 return B;
291 }
292
300 [[nodiscard]] static inline const TRangeBound& MinLower(const TRangeBound& A, const TRangeBound& B)
301 {
302 if (A.IsOpen()) { return A; }
303 if (B.IsOpen()) { return B; }
304 if (A.Value < B.Value) { return A; }
305 if (B.Value < A.Value) { return B; }
306 if (A.IsInclusive()) { return A; }
307
308 return B;
309 }
310
318 [[nodiscard]] static inline const TRangeBound& MinUpper(const TRangeBound& A, const TRangeBound& B)
319 {
320 if (A.IsOpen()) { return B; }
321 if (B.IsOpen()) { return A; }
322 if (A.Value < B.Value) { return A; }
323 if (B.Value < A.Value) { return B; }
324 if (A.IsExclusive()) { return A; }
325
326 return B;
327 }
328
329private:
330
333
335 ElementType Value;
336};
337
338
339/* Default range bounds for built-in types (for FProperty support)
340 *****************************************************************************/
341
342#define DEFINE_RANGEBOUND_WRAPPER_STRUCT(Name, ElementType) \
343 struct Name : TRangeBound<ElementType> \
344 { \
345 private: \
346 typedef TRangeBound<ElementType> Super; \
347 \
348 public: \
349 Name() \
350 : Super() \
351 { } \
352 \
353 Name(const Super& Other) \
354 : Super(Other) \
355 { } \
356 \
357 Name(const ElementType InValue) \
358 : Super(InValue) \
359 { } \
360 \
361 static UE_FORCEINLINE_HINT Name Exclusive(ElementValueOrConstRef Value) \
362 { \
363 return static_cast<const Name&>(Super::Exclusive(Value)); \
364 } \
365 \
366 static UE_FORCEINLINE_HINT Name Inclusive(ElementValueOrConstRef Value) \
367 { \
368 return static_cast<const Name&>(Super::Inclusive(Value)); \
369 } \
370 \
371 static UE_FORCEINLINE_HINT Name Open() \
372 { \
373 return static_cast<const Name&>(Super::Open()); \
374 } \
375 \
376 static UE_FORCEINLINE_HINT Name FlipInclusion(const Name& Bound) \
377 { \
378 return static_cast<const Name&>(Super::FlipInclusion(Bound)); \
379 } \
380 \
381 static UE_FORCEINLINE_HINT const Name& MaxLower(const Name& A, const Name& B) \
382 { \
383 return static_cast<const Name&>(Super::MaxLower(A, B)); \
384 } \
385 \
386 static UE_FORCEINLINE_HINT const Name& MaxUpper(const Name& A, const Name& B) \
387 { \
388 return static_cast<const Name&>(Super::MaxUpper(A, B)); \
389 } \
390 \
391 static UE_FORCEINLINE_HINT const Name& MinLower(const Name& A, const Name& B) \
392 { \
393 return static_cast<const Name&>(Super::MinLower(A, B)); \
394 } \
395 \
396 static UE_FORCEINLINE_HINT const Name& MinUpper(const Name& A, const Name& B) \
397 { \
398 return static_cast<const Name&>(Super::MinUpper(A, B)); \
399 } \
400 }; \
401 \
402 template <> \
403 struct TIsBitwiseConstructible<Name, TRangeBound<ElementType>> \
404 { \
405 enum { Value = true }; \
406 }; \
407 \
408 template <> \
409 struct TIsBitwiseConstructible<TRangeBound<ElementType>, Name> \
410 { \
411 enum { Value = true }; \
412 };
413
414
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DEFINE_RANGEBOUND_WRAPPER_STRUCT(Name, ElementType)
Definition RangeBound.h:342
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition EnumAsByte.h:22
Definition RangeBound.h:36
ElementValueOrConstRef GetValue() const
Definition RangeBound.h:97
friend uint32 GetTypeHash(const TRangeBound &Bound)
Definition RangeBound.h:180
UE_FORCEINLINE_HINT bool IsClosed() const
Definition RangeBound.h:125
static const TRangeBound & MinLower(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:300
UE_FORCEINLINE_HINT bool IsExclusive() const
Definition RangeBound.h:135
static const TRangeBound & MaxUpper(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:282
static TRangeBound Inclusive(ElementValueOrConstRef Value)
Definition RangeBound.h:209
TRangeBound(ElementValueOrConstRef InValue)
Definition RangeBound.h:58
UE_FORCEINLINE_HINT bool IsInclusive() const
Definition RangeBound.h:145
UE_FORCEINLINE_HINT bool IsOpen() const
Definition RangeBound.h:155
TRangeBound()
Definition RangeBound.h:47
static const TRangeBound & MaxLower(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:264
bool operator==(const TRangeBound &Other) const
Definition RangeBound.h:71
static const TRangeBound & MinUpper(const TRangeBound &A, const TRangeBound &B)
Definition RangeBound.h:318
static TRangeBound FlipInclusion(const TRangeBound &Bound)
Definition RangeBound.h:242
TCallTraits< ElementType >::ParamType ElementValueOrConstRef
Definition RangeBound.h:40
friend class FArchive & operator<<(class FArchive &Ar, TRangeBound &Bound)
Definition RangeBound.h:169
bool operator!=(const TRangeBound &Other) const
Definition RangeBound.h:82
static TRangeBound Open()
Definition RangeBound.h:224
static TRangeBound Exclusive(ElementValueOrConstRef Value)
Definition RangeBound.h:193
void SetValue(ElementValueOrConstRef NewValue)
Definition RangeBound.h:113
Definition RangeBound.h:13
Type
Definition RangeBound.h:18
@ Open
Definition RangeBound.h:26
@ Inclusive
Definition RangeBound.h:23
@ Exclusive
Definition RangeBound.h:20
Definition DateTime.h:76
Definition FrameNumber.h:18
TCallTraitsParamTypeHelper< T, PassByValue >::ParamType ParamType
Definition UnrealTypeTraits.h:275