Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamrock::solvergraph::LifetimeTracker< T > Class Template Reference

Tracks the lifetime of an object of type T and notifies observers through static callbacks. More...

#include <shamsolvergraph/include/shamsolvergraph/LifetimeTracker.hpp>

Inheritance diagram for shamrock::solvergraph::LifetimeTracker< T >:
Collaboration diagram for shamrock::solvergraph::LifetimeTracker< T >:

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.

Detailed Description

template<typename T>
class shamrock::solvergraph::LifetimeTracker< T >

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.

Template Parameters
TThe tracked object type (e.g. INode, IEdge)

Definition at line 42 of file LifetimeTracker.hpp.

Constructor & Destructor Documentation

◆ LifetimeTracker()

template<typename T>
shamrock::solvergraph::LifetimeTracker< T >::LifetimeTracker ( )
inline

Constructor, notifies the creation of the tracked object.

Definition at line 55 of file LifetimeTracker.hpp.

Here is the call graph for this function:

◆ ~LifetimeTracker()

template<typename T>
shamrock::solvergraph::LifetimeTracker< T >::~LifetimeTracker ( )
inline

Destructor, notifies destruction (unless already notified, or moved from).

Definition at line 111 of file LifetimeTracker.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ operator=()

template<typename T>
LifetimeTracker & shamrock::solvergraph::LifetimeTracker< T >::operator= ( LifetimeTracker< T > && other)
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.

Here is the call graph for this function:

◆ trace_create()

template<typename T>
void shamrock::solvergraph::LifetimeTracker< T >::trace_create ( )
inline

Notifies creation of the tracked object.

Definition at line 78 of file LifetimeTracker.hpp.

◆ trace_destroy()

template<typename T>
void shamrock::solvergraph::LifetimeTracker< T >::trace_destroy ( )
inline

Fires the destroy notification, if not already fired or moved from. Idempotent.

Definition at line 85 of file LifetimeTracker.hpp.

Here is the call graph for this function:

◆ trace_event()

template<typename T>
template<class F>
void shamrock::solvergraph::LifetimeTracker< T >::trace_event ( F && event_info_builder)
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.

Here is the call graph for this function:

◆ trace_state_update()

template<typename T>
void shamrock::solvergraph::LifetimeTracker< T >::trace_state_update ( T & object)
inline

Definition at line 95 of file LifetimeTracker.hpp.

Member Data Documentation

◆ on_create

template<typename T>
void(* shamrock::solvergraph::LifetimeTracker< T >::on_create) (u64 uuid) = nullptr
inlinestatic

Called when a tracked object is created.

Definition at line 45 of file LifetimeTracker.hpp.

◆ on_destroy

template<typename T>
void(* shamrock::solvergraph::LifetimeTracker< T >::on_destroy) (u64 uuid) = nullptr
inlinestatic

Called when a tracked object is destroyed.

Definition at line 47 of file LifetimeTracker.hpp.

◆ on_event

template<typename T>
void(* shamrock::solvergraph::LifetimeTracker< T >::on_event) (u64 uuid, std::string_view s) = nullptr
inlinestatic

Called when an operation is performed on a tracked object (e.g. evaluation).

Definition at line 52 of file LifetimeTracker.hpp.

◆ on_state_update

template<typename T>
void(* shamrock::solvergraph::LifetimeTracker< T >::on_state_update) (T &object) = nullptr
inlinestatic

Called when the state of a tracked object changes (e.g. edges are rebound).

Definition at line 50 of file LifetimeTracker.hpp.


The documentation for this class was generated from the following file: