template class EE::ObservableVector¶
Overview¶
A vector whose explicit mutations can incrementally update attached adapters. More…
#include <observablevector.hpp> template <typename T> class ObservableVector { public: // typedefs typedef std::vector<T> ValueType; typedef std::function<void(const Change&)> Callback; // enums enum ChangeType; enum Phase; // structs struct Change; struct State; // classes class Connection; class SharedHandle; // construction ObservableVector(); ObservableVector(std::vector<T> values); ObservableVector(const ObservableVector&); ObservableVector(ObservableVector&&); // methods ObservableVector& operator=(const ObservableVector&); ObservableVector& operator=(ObservableVector&&); const std::vector<T>& get() const; const T& operator[](std::size_t index) const; std::size_t size() const; bool empty() const; void insert(std::size_t index, T value); void pushBack(T value); void erase(std::size_t index, std::size_t count = 1); void move(std::size_t from, std::size_t to); void set(std::size_t index, T value); void reset(std::vector<T> values); Connection observe(Callback callback); SharedHandle sharedHandle() const; };
Detailed Documentation¶
A vector whose explicit mutations can incrementally update attached adapters.
Use this when a collection remains live while a view is attached. Immutable option lists and collections already managed by a specialized Model should continue using those simpler models. Notifications are synchronous and the collection and its connections must be used from one owning thread. See the ui_data_collections example for live insertion, updates, and removal.
Construction¶
ObservableVector()
Creates an empty observable collection.
ObservableVector(std::vector<T> values)
Creates an observable collection containing values without emitting a change.
Methods¶
const std::vector<T>& get() const
Returns:
Read-only access to the complete collection.
const T& operator[](std::size_t index) const
Returns:
The value at index. No bounds checking is performed.
std::size_t size() const
Returns:
The number of values in the collection.
bool empty() const
Returns:
Whether the collection contains no values.
void insert(std::size_t index, T value)
Inserts value before index and emits paired Before/After notifications.
void pushBack(T value)
Appends value and emits paired Before/After insertion notifications.
void erase(std::size_t index, std::size_t count = 1)
Removes count values starting at index. A zero count is a no-op.
void move(std::size_t from, std::size_t to)
Moves one value from from to to.
to is the final index in the resulting collection. Moving to the same index is a no-op.
void set(std::size_t index, T value)
Replaces the value at index unless it already compares equal to value.
void reset(std::vector<T> values)
Replaces the entire collection and emits paired Reset notifications.
Connection observe(Callback callback)
Observes subsequent collection mutations.
Each non-empty mutation emits a Before notification followed by After. The callback is not invoked for the collection’s current contents when it is registered.
Returns:
A scoped connection; destroying it disconnects the callback.
SharedHandle sharedHandle() const
Returns:
Shared read access that keeps collection storage alive independently of this object.