|
LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
|
Improved IModel with weak_ptr observers for automatic cleanup. More...
#include <IModelObservable.hpp>


Public Types | |
| using | ViewPtr = std::shared_ptr< IView > |
| Shared pointer type for views. | |
Public Member Functions | |
| virtual | ~IModelObservable ()=default |
| void | RegisterView (ViewPtr view) |
| Registers a view as observer with automatic cleanup. | |
| void | UnregisterView (const IView *view) |
| Unregisters a view from observations. | |
| size_t | GetViewCount () const |
| Gets count of currently active observers. | |
Protected Member Functions | |
| void | NotifyDataChanged () |
| Notifies all registered views that data has changed. | |
| void | NotifyCurrentIndexUpdated (int index) |
| Notifies all views of current item index change. | |
| void | CleanupDeadObservers () |
| Manually triggers cleanup of dead observers. | |
Private Member Functions | |
| void | CleanupDeadViews () |
| Internal method to clean up expired weak pointers. | |
Private Attributes | |
| std::shared_mutex | m_viewsMutex |
| Storage for observer weak pointers - automatically manages cleanup. | |
| std::vector< std::weak_ptr< IView > > | m_weakViews |
Improved IModel with weak_ptr observers for automatic cleanup.
This interface replaces the raw pointer-based observer pattern with weak_ptr-based observers that automatically detect and remove destroyed views. It provides thread-safe observer notifications with reader-writer locking.
New API (recommended):
| using mvc::IModelObservable::ViewPtr = std::shared_ptr<IView> |
Shared pointer type for views.
|
virtualdefault |
|
inlineprotected |
Manually triggers cleanup of dead observers.
Can be called explicitly to prune expired weak_ptr entries. Internally, cleanup is also performed on every RegisterView and NotifyDataChanged call.

|
inlineprivate |
Internal method to clean up expired weak pointers.
Called during registration and notifications to remove dead observers. Must be called with unique_lock held.


|
inline |
Gets count of currently active observers.
|
inlineprotected |
Notifies all views of current item index change.
| index | The new current item index |


|
inlineprotected |
Notifies all registered views that data has changed.
Iterates through all observers and calls their OnDataUpdated method. Dead observers (destroyed views) are automatically detected via weak_ptr and skipped without error.


|
inline |
Registers a view as observer with automatic cleanup.
The view is stored internally as weak_ptr so it's automatically removed when destroyed. No dangling pointers.
| view | Shared pointer to view to register |

|
inline |
Unregisters a view from observations.
| view | Pointer to the view to unregister |
Safe if view already unregistered or destroyed.

|
mutableprivate |
Storage for observer weak pointers - automatically manages cleanup.
|
private |