MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Observable.Fwd.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14/**
15 * @file
16 * This is a forward declaration for types in Observable.h. Unless the full TState type is used for class member
17 * declarations, use this header in other header files.
18 */
19
20#include "CoreMinimal.h"
21#include "Mcro/FunctionTraits.h"
22
24{
25 using namespace Mcro::FunctionTraits;
26
27 /** Flags expressing how TState should handle object comparison and lifespan */
29 {
30 /**
31 * When the object inside TState is != comparable TState wull only emit change events when the submitted
32 * value differs from the existing one.
33 */
35
36 /** Always emit change notification when a value is set on TState and don't attempt to compare them */
37 AlwaysNotify = 1 << 0,
38
39 /** Always emit change notification when a value is set on TState and don't attempt to compare them */
40 StorePrevious = 1 << 1,
41
42 /**
43 * Enable mutexes during modifications, notifications and expose a public critical section for users
44 * of the state.
45 */
46 ThreadSafeState = 1 << 2
47 };
48
49 struct IStateTag {};
50
51 template <typename T>
52 inline constexpr int32 StatePolicyFor =
53 CClass<T>
54 ? CCoreEqualityComparable<T>
58
59 template <typename T>
60 struct IState;
61
62 template <typename T>
63 struct TChangeData;
64
65 template <typename T, int32 DefaultPolicy = StatePolicyFor<T>>
66 struct TState;
67
68 /**
69 * Convenience alias for shared reference to a base type of TState. Use this in APIs which may modify or get the
70 * value of a state declared elsewhere.
71 */
72 template <typename T>
73 using TStateRef = TSharedRef<IState<T>>;
74
75 /**
76 * Convenience alias for shared pointer to a base type of TState. Use this in APIs which may modify or get the
77 * value of a state declared elsewhere.
78 */
79 template <typename T>
80 using TStatePtr = TSharedPtr<IState<T>>;
81
82 /**
83 * Convenience alias for weak pointer to a base type of TState. Use this in APIs which may modify or get the
84 * value of a state declared elsewhere.
85 */
86 template <typename T>
87 using TStateWeakPtr = TWeakPtr<IState<T>>;
88
89 /** Convenience alias for declaring a state as a shared reference. Use this only as object members */
90 template <typename T, int32 DefaultPolicy = StatePolicyFor<T>>
91 using TDeclareStateRef = TSharedRef<TState<T, DefaultPolicy>>;
92
93 /** Convenience alias for declaring a state as a shared pointer. Use this only as object members */
94 template <typename T, int32 DefaultPolicy = StatePolicyFor<T>>
95 using TDeclareStatePtr = TSharedPtr<TState<T, DefaultPolicy>>;
96
97 /** Concept constraining given type to a state */
98 template <typename T>
99 concept CState = CDerivedFrom<T, IStateTag>;
100
101 /** Concept describing a function which can be a change listener on a TState */
102 template <typename Function, typename T>
103 concept CChangeListener = CFunctionLike<Function>
105 && CConvertibleTo<T, TFunction_ArgDecay<Function, 0>>
106 ;
107
108 /** Concept describing a function which can listen to changes to the current value of a TState only */
109 template <typename Function, typename T>
111
112 /** Concept describing a function which can listen to changes to the current and the previous values of a TState */
113 template <typename Function, typename T>
116 && CConvertibleTo<TOptional<T>, TFunction_ArgDecay<Function, 1>>
117 ;
118
119 /** Convenience alias for thread safe states */
120 template <typename T, int32 DefaultPolicy = StatePolicyFor<T> | ThreadSafeState>
122
123 /** Convenience alias for boolean states */
125
126 /** Convenience alias for thread-safe boolean states */
128}
constexpr size_t TFunction_ArgCount
typename TFunctionTraits< std::decay_t< T > >::template ArgDecay< I > TFunction_ArgDecay
TWeakPtr< IState< T > > TStateWeakPtr
TSharedPtr< TState< T, DefaultPolicy > > TDeclareStatePtr
TSharedRef< TState< T, DefaultPolicy > > TDeclareStateRef
TSharedRef< IState< T > > TStateRef
constexpr int32 StatePolicyFor
TSharedPtr< IState< T > > TStatePtr