MCRO
C++23 utilities for Unreal Engine.
|
#include <Observable.h>
Public Types | |
template<typename ThreadSafeType , typename NaiveType > | |
using | ThreadSafeSwitch = std::conditional_t<static_cast<bool>(DefaultPolicy & ThreadSafeState), ThreadSafeType, NaiveType> |
using | StateBase = IState<T> |
using | ReadLockType = ThreadSafeSwitch<FReadScopeLock, FVoid> |
using | WriteLockType = ThreadSafeSwitch<FWriteScopeLock, FVoid> |
using | ReadLockVariant |
using | WriteLockVariant |
Public Types inherited from Mcro::Observable::IState< T > | |
using | Type = T |
using | ReadLockVariant = TVariant<FReadScopeLock, FVoid> |
using | WriteLockVariant = TVariant<FWriteScopeLock, FVoid> |
Public Member Functions | |
template<CDefaultInitializable = T> | |
TState () | |
template<CCopyConstructible = T> | |
TState (T const &value) | |
template<CMoveConstructible = T> | |
TState (T &&value) | |
template<CCopyConstructible = T> | |
TState (TState const &other) | |
template<CMoveConstructible = T> | |
TState (TState &&other) | |
template<typename Arg > requires (!CConvertibleTo<Arg, TState> && !CSameAs<Arg, T>) | |
TState (Arg &&arg) | |
template<typename... Args> requires (sizeof...(Args) > 1) | |
TState (Args &&... args) | |
virtual T const & | Get () const override |
virtual TTuple< T const &, TUniquePtr< ReadLockVariant > > | GetOnAnyThread () const override |
virtual void | Set (T const &value) override |
virtual void | Modify (TUniqueFunction< void(T &)> &&modifier, bool alwaysNotify=true) override |
virtual FDelegateHandle | OnChange (TDelegate< void(TChangeData< T > const &)> onChange, EInvokeMode invokeMode=DefaultInvocation) override |
virtual bool | Remove (FDelegateHandle const &handle) override |
virtual int32 | RemoveAll (const void *object) override |
virtual bool | HasChangedFrom (const T &nextValue) override |
virtual bool | HasEverChanged () const override |
virtual TUniquePtr< ReadLockVariant > | ReadLock () const override |
virtual TUniquePtr< WriteLockVariant > | WriteLock () override |
Public Member Functions inherited from Mcro::Observable::IState< T > | |
virtual | ~IState ()=default |
template<CChangeListener< T > Function> | |
FDelegateHandle | OnChange (Function const &onChange, EInvokeMode invokeMode=DefaultInvocation) |
template<typename Object , CChangeListener< T > Function> | |
FDelegateHandle | OnChange (Object &&object, Function const &onChange, EInvokeMode invokeMode=DefaultInvocation) |
template<typename Self > | |
operator const T & (this Self &&self) | |
template<typename Self > | |
const T * | operator-> (this Self &&self) |
template<typename Self , CConvertibleTo< T > Other> requires (!CState<Other>) | |
Self & | operator= (this Self &&self, Other &&value) |
Data Fields | |
int32 | PolicyFlags = DefaultPolicy |
Static Public Attributes | |
static constexpr int32 | DefaultPolicyFlags = DefaultPolicy |
Additional Inherited Members | |
Static Protected Member Functions inherited from Mcro::Observable::IState< T > | |
template<CChangeListener< T > Function> | |
static auto | DelegateValueArgument (Function const &onChange, EInvokeMode invokeMode=DefaultInvocation) |
Storage wrapper for any value which state needs to be tracked or their change needs to be observed. By default TState
is not thread-safe unless ThreadSafeState policy is active in DefaultPolicy
Definition at line 226 of file Observable.h.
using Mcro::Observable::TState< T, DefaultPolicy >::ReadLockType = ThreadSafeSwitch<FReadScopeLock, FVoid> |
Definition at line 236 of file Observable.h.
using Mcro::Observable::IState< T >::ReadLockVariant |
Definition at line 60 of file Observable.h.
using Mcro::Observable::TState< T, DefaultPolicy >::StateBase = IState<T> |
Definition at line 231 of file Observable.h.
using Mcro::Observable::TState< T, DefaultPolicy >::ThreadSafeSwitch = std::conditional_t<static_cast<bool>(DefaultPolicy & ThreadSafeState), ThreadSafeType, NaiveType> |
Definition at line 229 of file Observable.h.
using Mcro::Observable::TState< T, DefaultPolicy >::WriteLockType = ThreadSafeSwitch<FWriteScopeLock, FVoid> |
Definition at line 237 of file Observable.h.
using Mcro::Observable::IState< T >::WriteLockVariant |
Definition at line 61 of file Observable.h.
|
inline |
Enable default constructor only when T is default initializable
Definition at line 243 of file Observable.h.
|
inline |
Enable copy constructor for T only when T is copy constructable
Definition at line 247 of file Observable.h.
|
inline |
Enable move constructor for T only when T is move constructable
Definition at line 251 of file Observable.h.
|
inline |
Enable copy constructor for the state only when T is copy constructable
Definition at line 255 of file Observable.h.
|
inline |
Enable move constructor for the state only when T is move constructable
Definition at line 259 of file Observable.h.
|
inline |
Construct value in-place with non-semantic single argument constructor
Definition at line 264 of file Observable.h.
|
inline |
Construct value in-place with multiple argument constructor
Definition at line 269 of file Observable.h.
|
inlineoverridevirtual |
Get the wrapped value if for some reason the conversion operator is not enough or deleted. Thread safety is not considered in this function, use ReadLock
before Get
, or use GetOnAnyThread
which provides a read lock, if thread safety is a concern.
Implements Mcro::Observable::IState< T >.
Definition at line 271 of file Observable.h.
|
inlineoverridevirtual |
If thread safety is enabled in DefaultPolicy, get the value with a bundled read-scope-lock. Otherwise the tuple returns an empty dummy struct as its second argument. Use C++17 structured binding for convenience:
Unlike the placeholder auto
keyword, the structured binding auto
keyword preserves reference qualifiers. See https://godbolt.org/z/jn918fKfd
Implements Mcro::Observable::IState< T >.
Definition at line 273 of file Observable.h.
|
inlineoverridevirtual |
Given value will be stored in the state only if T is equality comparable and it differs from the current state value. If T is not equality comparable this function is equivalent to Set and always returns true.
Implements Mcro::Observable::IState< T >.
Definition at line 348 of file Observable.h.
|
inlineoverridevirtual |
Returns true if this state has ever been changed from its initial value given at construction.
Implements Mcro::Observable::IState< T >.
Definition at line 363 of file Observable.h.
|
inlineoverridevirtual |
Modify this state via an l-value ref in a functor
modifier | The functor which modifies this value |
alwaysNotify | Notify observers about the change even when the previous state is not different after the modification. This is only applicable when T is copyable, comparable, StorePrevious flag is set and AlwaysNotify flag is not set via policy. |
Implements Mcro::Observable::IState< T >.
Definition at line 300 of file Observable.h.
|
inlineoverridevirtual |
Add a delegate which gets a TChangeData<T> const&
if this state has been set.
Implements Mcro::Observable::IState< T >.
Definition at line 330 of file Observable.h.
|
inlineoverridevirtual |
Lock this state for reading for the current scope
Implements Mcro::Observable::IState< T >.
Definition at line 368 of file Observable.h.
|
inlineoverridevirtual |
Equivalent to TMulticastDelegate::Remove
Implements Mcro::Observable::IState< T >.
Definition at line 336 of file Observable.h.
|
inlineoverridevirtual |
Equivalent to TMulticastDelegate::RemoveAll
Implements Mcro::Observable::IState< T >.
Definition at line 342 of file Observable.h.
|
inlineoverridevirtual |
Set the wrapped value if for some reason the assignment operator is not enough or deleted. When thread safety is enabled Set will automatically lock this state for writing.
Implements Mcro::Observable::IState< T >.
Definition at line 278 of file Observable.h.
|
inlineoverridevirtual |
Lock this state for writing for the current scope
Implements Mcro::Observable::IState< T >.
Definition at line 373 of file Observable.h.
|
staticconstexpr |
Definition at line 239 of file Observable.h.
int32 Mcro::Observable::TState< T, DefaultPolicy >::PolicyFlags = DefaultPolicy |
Definition at line 378 of file Observable.h.