Static, type-safe collection manager for Core-derived objects.
More...
#include <CoreManager.h>
Public Member Functions | |
| virtual | ~CoreManager () |
Static Public Member Functions | |
| static void | addComponent (T &component) |
Register a T object with this manager. | |
| static void | clear () |
| Remove all registered objects. | |
| static void | clearPending () |
| Discard all pending operations without executing them. | |
| static const std::vector< T * > & | getComponents () |
| Return a read-only view of all currently registered objects. | |
| static bool | isBusy () |
Return true if the manager is currently iterating. | |
| static void | processPending () |
| Flush all pending operations immediately. | |
| static bool | removeComponent (T &component) |
Unregister a T object by reference. | |
| static bool | removeComponent (T *component) |
Unregister a T object by pointer. | |
Static Protected Member Functions | |
| static void | beginBusy () |
| Signal that iteration has begun. | |
| static void | deferOrExecute (std::function< void()> operation) |
Execute operation now if safe, otherwise queue it. | |
| static void | endBusy () |
| Signal that iteration has ended; flush pending operations. | |
Static Protected Attributes | |
| static int | busyDepth |
| Iteration nesting depth. Operations are deferred while this is > 0. | |
| static std::vector< std::function< void()> > | pendingOperations |
| Queue of operations pending until the current iteration completes. | |
Static, type-safe collection manager for Core-derived objects.
CoreManager<T> owns a static list of T* pointers and provides add, remove, and query operations. It inherits DeferredOperationsManager so that removals requested while the collection is being iterated are queued and applied safely once iteration completes — preventing iterator invalidation crashes.
Because the underlying storage is inline static, all instances of CoreManager<T> share a single list per type T. This means the manager behaves as a singleton per type without requiring an explicit instance to be passed around.
addComponent and removeComponent are safe to call at any time, including from within an event or update callback that is currently iterating the collection.T object after it has been registered. The collection stores raw pointers; moving the object invalidates them.| T | A Core-derived type whose instances will be managed. |
Definition at line 52 of file CoreManager.h.
|
virtual |
|
static |
Register a T object with this manager.
After registration, the object will receive update() and draw() calls each frame (for managers that drive those methods).
| component | The object to register. Must outlive its registration. |
|
staticprotectedinherited |
Signal that iteration has begun.
Increments the busy-depth counter. Multiple nested calls are safe — operations remain deferred until the outermost endBusy() is reached.
|
static |
Remove all registered objects.
If the collection is currently being iterated, the clear is deferred. After this call (or after the deferred clear executes), getComponents() returns an empty vector.
|
staticinherited |
Discard all pending operations without executing them.
Use during application shutdown or full reset when executing the queued operations would be unsafe (e.g., the objects they reference have already been destroyed).
|
staticprotectedinherited |
Execute operation now if safe, otherwise queue it.
If busyDepth > 0 the operation is appended to pendingOperations and will run when the current iteration completes. If the manager is idle the operation executes immediately.
| operation | The callable to execute or defer. |
|
staticprotectedinherited |
Signal that iteration has ended; flush pending operations.
Decrements the busy-depth counter. When the counter reaches zero, all operations in pendingOperations are executed in FIFO order and the queue is cleared.
|
staticnodiscard |
Return a read-only view of all currently registered objects.
The returned reference is valid until the next structural modification (add or remove). Do not store the reference across frames.
|
staticinherited |
Return true if the manager is currently iterating.
Can be used by external code that needs to know whether a destructive operation will be deferred.
true when busyDepth > 0.
|
staticinherited |
Flush all pending operations immediately.
Normally called automatically by endBusy(). Provided as a public escape hatch for unusual teardown sequences.
isBusy() is true can cause iterator invalidation in the currently running loop. Only call manually when you are certain it is safe.
|
static |
Unregister a T object by reference.
Safe to call from inside an event or update callback. If the collection is currently being iterated, the removal is deferred until iteration completes.
| component | The object to remove. |
true if the object was found and removed (or queued for removal); false if it was not registered.
|
static |
Unregister a T object by pointer.
Equivalent to the reference overload. Passing nullptr is safe and returns false.
| component | Pointer to the object to remove. |
true if found and removed (or queued); false otherwise.
|
inlinestaticprotectedinherited |
Iteration nesting depth. Operations are deferred while this is > 0.
Definition at line 69 of file DeferredOperationsManager.h.
|
inlinestaticprotectedinherited |
Queue of operations pending until the current iteration completes.
Definition at line 72 of file DeferredOperationsManager.h.