![]() |
MCRO
C++23 utilities for Unreal Engine.
|
Public API and base class for TState which shouldn't concern with policy flags or thread safety.
More...
#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 |
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. | |
| virtual void | Set (T const &value)=0 |
| 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. | |
| virtual void | Modify (TUniqueFunction< void(T &)> &&modifier, bool alwaysNotify=true)=0 |
| Modify this state via an l-value ref in a functor. | |
| FDelegateHandle | OnChange (TDelegate< void(TChangeData< T > const &)> onChange, FEventPolicy const &eventPolicy={}) |
Add a delegate which gets a TChangeData<T> const& if this state has been set. | |
| template<CChangeListener< T > Function> | |
| FDelegateHandle | OnChange (Function const &onChange, FEventPolicy const &eventPolicy={}) |
Add a function without object binding which either has one or two arguments with the following signature: [](T const& next, [TOptional<T> const& previous]) | |
| template<typename Object , CChangeListener< T > Function> | |
| FDelegateHandle | OnChange (Object &&object, Function const &onChange, FEventPolicy const &eventPolicy={}) |
Add a function with an object binding which either has one or two arguments with the following signature: [](T const& next, [TOptional<T> const& previous]) | |
| template<CConvertibleToDecayed< T > Other, typename Guard > | |
| void | SyncPull (Guard &&object, IState< Other > &otherState) |
| Pull changes from another state, syncing the value between the two. Values will be copied. | |
| template<typename Other , typename Guard > requires CConvertibleToDecayed<Other, T> | |
| void | SyncPush (Guard &&object, IState< Other > &otherState) |
| Push changes from another state, syncing the value between the two. Values will be copied. | |
| virtual bool | HasChangedFrom (const T &nextValue)=0 |
| 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. | |
| virtual bool | HasEverChanged () const =0 |
| Returns true if this state has ever been changed from its initial value given at construction. | |
| virtual bool | Remove (FDelegateHandle const &handle)=0 |
Equivalent to TMulticastDelegate::Remove | |
| virtual int32 | RemoveAll (const void *object)=0 |
Equivalent to TMulticastDelegate::RemoveAll | |
| virtual TTuple< T const &, TUniquePtr< ReadLockVariant > > | GetOnAnyThread () const =0 |
| 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. | |
| virtual TUniquePtr< ReadLockVariant > | ReadLock () const =0 |
| Lock this state for reading for the current scope. | |
| virtual TUniquePtr< WriteLockVariant > | WriteLock ()=0 |
| Lock this state for writing for the current scope. | |
| virtual TOptional< T > const & | GetPrevious () const =0 |
| Get the previous value if StorePrevious is enabled and there was at least one change. | |
| virtual T const & | GetPrevious (T const &fallback) const =0 |
| Get the previous value if StorePrevious is enabled and there was at least one change. Get a fallback value otherwise. | |
| virtual T const & | GetPreviousOrCurrent () const =0 |
| Get the previous value if StorePrevious is enabled and there was at least one change or the current value otherwise. | |
| virtual void | NormalizePrevious ()=0 |
| Set the previous value to the current one. Useful in Ticks. | |
| template<CBooleanTestable = T> | |
| bool | BecameTrue (bool fallback=false) const |
| Returns true when this state is currently true, but previously it wasn't. | |
| template<CBooleanTestable = T> | |
| bool | OnDown (bool fallback=false) const |
| Returns true when this state is currently true, but previously it wasn't. | |
| template<CBooleanTestable = T> | |
| bool | BecameFalse (bool fallback=false) const |
| Returns true when this state is currently false, but previously it wasn't. | |
| template<CBooleanTestable = T> | |
| bool | OnUp (bool fallback=false) const |
| Returns true when this state is currently false, but previously it wasn't. | |
| template<CCoreEqualityComparable = T> | |
| bool | HasChanged () const |
| Returns true when current value is not equal to previous one. | |
| template<CCoreEqualityComparable = T> | |
| bool | HasChanged (T const &fallback) const |
| Returns true when current value is not equal to previous one. | |
| template<typename Self > | |
| operator T const & (this Self &&self) | |
| template<typename Self > | |
| const T * | operator-> (this Self &&self) |
Protected Member Functions | |
| virtual FDelegateHandle | OnChangeImpl (TDelegate< void(TChangeData< T > const &)> &&onChange, FEventPolicy const &eventPolicy={})=0 |
Static Protected Member Functions | |
| template<CChangeListener< T > Function> | |
| static auto | DelegateValueArgument (Function const &onChange) |
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 |
|
inline |
Returns true when this state is currently false, but previously it wasn't.
| fallback | Use this as the fallback previous state. |
Definition at line 302 of file Observable.h.
|
inline |
Returns true when this state is currently true, but previously it wasn't.
| fallback | Use this as the fallback previous state. |
Definition at line 279 of file Observable.h.
|
inlinestaticprotected |
Definition at line 97 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:
auto keyword, the structured binding auto keyword preserves reference qualifiers. See https://godbolt.org/z/jn918fKfdImplemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Get the previous value if StorePrevious is enabled and there was at least one change.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Get the previous value if StorePrevious is enabled and there was at least one change. Get a fallback value otherwise.
| fallback | Return this value if there's no previous one available |
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
pure virtual |
Get the previous value if StorePrevious is enabled and there was at least one change or the current value otherwise.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
inline |
Returns true when current value is not equal to previous one.
Definition at line 321 of file Observable.h.
|
inline |
Returns true when current value is not equal to previous one.
Definition at line 328 of file Observable.h.
|
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 >.
|
pure virtual |
Set the previous value to the current one. Useful in Ticks.
It will not trigger change notifications but it will use a write-lock when thread-safety is enabled. If StorePrevious is disabled it will do nothing.
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: [](T const& next, [TOptional<T> const& previous])
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 126 of file Observable.h.
|
inline |
Add a function with an object binding which either has one or two arguments with the following signature: [](T const& next, [TOptional<T> const& previous])
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 140 of file Observable.h.
|
inline |
Add a delegate which gets a TChangeData<T> const& if this state has been set.
Definition at line 112 of file Observable.h.
|
protectedpure virtual |
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.
|
inline |
Returns true when this state is currently true, but previously it wasn't.
| fallback | Use this as the fallback previous state. |
Definition at line 294 of file Observable.h.
|
inline |
Returns true when this state is currently false, but previously it wasn't.
| fallback | Use this as the fallback previous state. |
Definition at line 317 of file Observable.h.
|
inline |
Definition at line 334 of file Observable.h.
|
inline |
Definition at line 340 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 >.
|
inline |
Pull changes from another state, syncing the value between the two. Values will be copied.
| Other | Type convertible to the value of this state |
| Guard | The type of the lifespan guarding object |
| object | A lifespan guarding object in the context of this state, shared/weak pointer or UObject recommended. |
| otherState | A reference to the other state. |
Definition at line 157 of file Observable.h.
|
inline |
Push changes from another state, syncing the value between the two. Values will be copied.
| Other | The value of this state convertible to this type |
| Guard | The type of the lifespan guarding object |
| object | A lifespan guarding object in the context of the other state, shared/weak pointer or UObject recommended. |
| otherState | A reference to the other state. |
Definition at line 179 of file Observable.h.
|
pure virtual |
Lock this state for writing for the current scope.
Implemented in Mcro::Observable::TState< T, DefaultPolicy >.