Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FrameValue.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreGlobals.h"
6#include "Misc/Optional.h"
7
8/**
9 * This struct allows you to cache a value for a frame, and automatically invalidates
10 * when the frame advances.
11 * If the value was set this frame, IsSet() returns true and GetValue() is valid.
12 */
13template<typename ValueType>
15{
16private:
17 uint64 FrameSet;
18 TOptional<ValueType> Value;
19
20public:
21 /** Construct an OptionaType with a valid value. */
22 TFrameValue(const ValueType& InValue)
24 {
25 Value = InValue;
26 }
27
28 TFrameValue(ValueType&& InValue)
30 {
31 Value = InValue;
32 }
33
34 /** Construct an OptionalType with no value; i.e. unset */
37 {
38 }
39
40 /** Copy/Move construction */
41 TFrameValue(const TFrameValue& InValue)
43 {
44 Value = InValue;
45 }
46
49 {
50 Value = InValue;
51 }
52
54 {
55 Value = InValue;
57 return *this;
58 }
59
61 {
62 Value = InValue;
64 return *this;
65 }
66
67 TFrameValue& operator=(const ValueType& InValue)
68 {
69 Value = InValue;
71 return *this;
72 }
73
74 TFrameValue& operator=(ValueType&& InValue)
75 {
76 Value = InValue;
78 return *this;
79 }
80
81public:
82
83 bool IsSet() const
84 {
85 return Value.IsSet() && FrameSet == GFrameCounter;
86 }
87
88 const ValueType& GetValue() const
89 {
90 checkf(FrameSet == GFrameCounter, TEXT("Cannot get value on a different frame"));
91 return Value.GetValue();
92 }
93
94 ValueType TryGetValue(ValueType UnsetValue) const
95 {
96 return IsSet() ? Value.GetValue() : UnsetValue;
97 }
98};
#define checkf(expr, format,...)
TFrameValue(const TFrameValue &InValue)
Definition FrameValue.h:41
TFrameValue & operator=(TFrameValue &&InValue)
Definition FrameValue.h:60
TFrameValue & operator=(const TFrameValue &InValue)
Definition FrameValue.h:53
const ValueType & GetValue() const
Definition FrameValue.h:88
uint64 FrameSet
Definition FrameValue.h:17
ValueType TryGetValue(ValueType UnsetValue) const
Definition FrameValue.h:94
TFrameValue(TFrameValue &&InValue)
Definition FrameValue.h:47
TFrameValue(const ValueType &InValue)
Definition FrameValue.h:22
TFrameValue & operator=(const ValueType &InValue)
Definition FrameValue.h:67
TFrameValue & operator=(ValueType &&InValue)
Definition FrameValue.h:74
TOptional< ValueType > Value
Definition FrameValue.h:18
TFrameValue(ValueType &&InValue)
Definition FrameValue.h:28
bool IsSet() const
Definition FrameValue.h:83