![]() |
Shamrock 2025.10.0
Astrophysical Code
|
Tracks the lifetime of an object of type T and notifies observers through static callbacks. More...
#include <shamsolvergraph/include/shamsolvergraph/LifetimeTracker.hpp>
Public Member Functions | |
| LifetimeTracker () | |
| Constructor, notifies the creation of the tracked object. | |
| LifetimeTracker (const LifetimeTracker &)=delete | |
| would duplicate the UUID | |
| LifetimeTracker & | operator= (const LifetimeTracker &)=delete |
| would duplicate the UUID | |
| LifetimeTracker (LifetimeTracker &&) noexcept=default | |
| Move constructor: transfers the uuid to this and invalidates other. | |
| LifetimeTracker & | operator= (LifetimeTracker &&other) noexcept |
| void | trace_create () |
| Notifies creation of the tracked object. | |
| void | trace_destroy () |
| Fires the destroy notification, if not already fired or moved from. Idempotent. | |
| void | trace_state_update (T &object) |
| template<class F> | |
| void | trace_event (F &&event_info_builder) |
| ~LifetimeTracker () | |
| Destructor, notifies destruction (unless already notified, or moved from). | |
| Public Member Functions inherited from shambase::WithUUID< LifetimeTracker< T >, u64 > | |
| u64 | get_uuid () const |
| Get the uuid of the class. | |
| bool | is_alive () const |
| Whether this instance still holds a valid uuid (false once moved from). | |
| void | invalidate () |
| Marks this instance's uuid as invalid, e.g. to give up identity outside of a move. | |
| WithUUID () | |
| Constructor of the class. | |
| WithUUID & | operator= (const WithUUID &)=delete |
| would duplicate the uuid | |
Static Public Attributes | |
| static void(* | on_create )(u64 uuid) = nullptr |
| Called when a tracked object is created. | |
| static void(* | on_destroy )(u64 uuid) = nullptr |
| Called when a tracked object is destroyed. | |
| static void(* | on_state_update )(T &object) = nullptr |
| Called when the state of a tracked object changes (e.g. edges are rebound). | |
| static void(* | on_event )(u64 uuid, std::string_view s) = nullptr |
| Called when an operation is performed on a tracked object (e.g. evaluation). | |
| Static Public Attributes inherited from shambase::WithUUID< LifetimeTracker< T >, u64 > | |
| static constexpr u64 | invalid_uuid |
Additional Inherited Members | |
| Protected Attributes inherited from shambase::WithUUID< LifetimeTracker< T >, u64 > | |
| u64 | uuid |
| The unique identifier of the class. | |
Tracks the lifetime of an object of type T and notifies observers through static callbacks.
Held by the tracked object as a plain value member (not a base class), so trace_state_update() can take a T& to the enclosing object.
Move-safety comes from the base class: a moved-from instance's is_alive() reports false, so it won't emit a duplicate destroy notification.
All callbacks are nullptr by default, so tracking-disabled cost is one null check per notification site.
Definition at line 42 of file LifetimeTracker.hpp.
|
inline |
Constructor, notifies the creation of the tracked object.
Definition at line 55 of file LifetimeTracker.hpp.
|
inline |
Destructor, notifies destruction (unless already notified, or moved from).
Definition at line 111 of file LifetimeTracker.hpp.
|
inlinenoexcept |
Move assignment: fires this's own destroy notification (if still alive), then transfers other's uuid over and invalidates other.
Definition at line 69 of file LifetimeTracker.hpp.
|
inline |
Notifies creation of the tracked object.
Definition at line 78 of file LifetimeTracker.hpp.
|
inline |
Fires the destroy notification, if not already fired or moved from. Idempotent.
Definition at line 85 of file LifetimeTracker.hpp.
|
inline |
Use it like tracker.trace_event([]() {return "evaluate_begin";}); This patern allow for almost no overhead if tracing is disabled
Definition at line 104 of file LifetimeTracker.hpp.
|
inline |
Definition at line 95 of file LifetimeTracker.hpp.
|
inlinestatic |
Called when a tracked object is created.
Definition at line 45 of file LifetimeTracker.hpp.
|
inlinestatic |
Called when a tracked object is destroyed.
Definition at line 47 of file LifetimeTracker.hpp.
|
inlinestatic |
Called when an operation is performed on a tracked object (e.g. evaluation).
Definition at line 52 of file LifetimeTracker.hpp.
|
inlinestatic |
Called when the state of a tracked object changes (e.g. edges are rebound).
Definition at line 50 of file LifetimeTracker.hpp.