MCRO
C++23 utilities for Unreal Engine.
|
#include <Observable.h>
Public Types | |
using | Type = T |
using | ReadLockVariant = TVariant<FReadScopeLock, FVoid> |
using | WriteLockVariant = TVariant<FWriteScopeLock, FVoid> |
Public Member Functions | |
virtual | ~IState ()=default |
virtual T const & | Get () const =0 |
virtual void | Set (T const &value)=0 |
virtual void | Modify (TUniqueFunction< void(T &)> &&modifier, bool alwaysNotify=true)=0 |
virtual FDelegateHandle | OnChange (TDelegate< void(TChangeData< T > const &)> onChange, EInvokeMode invokeMode=DefaultInvocation)=0 |
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) |
virtual bool | HasChangedFrom (const T &nextValue)=0 |
virtual bool | HasEverChanged () const =0 |
virtual bool | Remove (FDelegateHandle const &handle)=0 |
virtual int32 | RemoveAll (const void *object)=0 |
virtual TTuple< T const &, TUniquePtr< ReadLockVariant > > | GetOnAnyThread () const =0 |
virtual TUniquePtr< ReadLockVariant > | ReadLock () const =0 |
virtual TUniquePtr< WriteLockVariant > | WriteLock ()=0 |
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) |
Static Protected Member Functions | |
template<CChangeListener< T > Function> | |
static auto | DelegateValueArgument (Function const &onChange, EInvokeMode invokeMode=DefaultInvocation) |
Public API and base class for TState
which shouldn't concern with policy flags or thread safety
Definition at line 57 of file Observable.h.
using Mcro::Observable::IState< T >::ReadLockVariant = TVariant<FReadScopeLock, FVoid> |
Definition at line 60 of file Observable.h.
using Mcro::Observable::IState< T >::Type = T |
Definition at line 59 of file Observable.h.
using Mcro::Observable::IState< T >::WriteLockVariant = TVariant<FWriteScopeLock, FVoid> |
Definition at line 61 of file Observable.h.
|
virtualdefault |
|
inlinestaticprotected |
Definition at line 95 of file Observable.h.
|
pure virtual |
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.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
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
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
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.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Returns true if this state has ever been changed from its initial value given at construction.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
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. |
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
inline |
Add a function without object binding which either has one or two arguments with the following signature:
Where the argument previous
is optional (to have, not its type). The argument previous
when it is present is TOptional because it may only have a value when StorePrevious policy is active and T is copyable.
Definition at line 121 of file Observable.h.
|
inline |
Add a function with an object binding which either has one or two arguments with the following signature:
Where the argument previous
is optional (to have, not its type). The argument previous
when it is present is TOptional because it may only have a value when StorePrevious policy is active and T is copyable.
Definition at line 137 of file Observable.h.
|
pure virtual |
Add a delegate which gets a TChangeData<T> const&
if this state has been set.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
inline |
Definition at line 198 of file Observable.h.
|
inline |
Definition at line 204 of file Observable.h.
|
inline |
Definition at line 211 of file Observable.h.
|
pure virtual |
Lock this state for reading for the current scope
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Equivalent to TMulticastDelegate::Remove
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Equivalent to TMulticastDelegate::RemoveAll
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
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.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Lock this state for writing for the current scope
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.