An observable value container that notifies observers when the value changes.
More...
|
| | ObservableValue (std::convertible_to< T > auto &&value) |
| | Constructs ObservableValue with initial value.
|
|
| ObservableValue () |
| | Constructs ObservableValue with default initial value.
|
|
| ObservableValue (ObservableValue const &)=delete |
|
| ObservableValue (ObservableValue &&)=default |
|
ObservableValue & | operator= (ObservableValue const &)=delete |
|
ObservableValue & | operator= (ObservableValue &&)=default |
| ObservableValue & | operator= (std::convertible_to< T > auto &&val) |
| | Assignment operator that updates value and notifies observers.
|
| ObservableGuard | operator-> () |
| | Provides deferred notification access to the value.
|
| | operator T const & () const |
| | Implicit conversion to const reference of the value.
|
| T const & | get () const |
| | Explicitly gets the current value.
|
| void | set (std::convertible_to< T > auto &&val) |
| | Sets a new value and notifies observers if changed.
|
| void | forceNotify () override |
| | Forces notification of all observers with the current value.
|
| boost::signals2::connection | observe (std::invocable< T const & > auto &&fn) |
| | Registers an observer callback for value changes.
|
| bool | hasObservers () const |
| | Checks if there are any active observers.
|
template<Observable T>
requires (not SomeAtomic<T>)
class util::ObservableValue< T >
An observable value container that notifies observers when the value changes.
ObservableValue wraps a value of type T and provides a mechanism to observe changes to that value. When the value is modified (and actually changes), all registered observers are notified.
- Template Parameters
-
| T | The type of value to observe. Must satisfy the Observable concept. |
- Thread Safety
- Observer subscription/unsubscription (observe() and connection.disconnect()) are thread-safe
- Value modification operations (set(), operator=) are NOT thread-safe and require external synchronization
- Observer callbacks are invoked synchronously on the same thread that triggered the value change
- If observers need to perform work on different threads, they must handle dispatch themselves (e.g., using an async execution context or message queue)
- Exception Handling
- If an observer callback throws an exception, the exception will propagate to the caller
- The value will still be updated even if observers throw exceptions
- No guarantee is made about whether other observers will be called if one throws
- It is the caller's responsibility to handle exceptions from observer callbacks