Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Scope_Guard< GT, Cleanup > Class Template Reference

Generic RAII scope guard for cleanup operations on graphs. More...

#include <cookie_guard.H>

Collaboration diagram for Aleph::Scope_Guard< GT, Cleanup >:
[legend]

Public Member Functions

 Scope_Guard (const GT &g, Cleanup cleanup)
 Construct a scope guard.
 
 Scope_Guard (const Scope_Guard &)=delete
 Copying disabled.
 
Scope_Guardoperator= (const Scope_Guard &)=delete
 
 Scope_Guard (Scope_Guard &&other) noexcept
 Move construction transfers ownership.
 
 ~Scope_Guard ()
 Destructor - calls cleanup function if still active.
 
void release () noexcept
 Release the guard without calling cleanup.
 
bool is_active () const noexcept
 Check if guard is still active.
 
void cleanup_now ()
 Execute cleanup immediately and deactivate.
 

Private Attributes

const GTgraph
 
Cleanup cleanup_fn
 
bool active
 

Detailed Description

template<class GT, class Cleanup>
class Aleph::Scope_Guard< GT, Cleanup >

Generic RAII scope guard for cleanup operations on graphs.

Executes a cleanup function when the guard goes out of scope, unless explicitly released. Useful for ensuring cleanup happens even if exceptions occur.

Template Parameters
GTGraph type.
CleanupCallable type for cleanup (e.g., lambda, functor).
Example
// Initialize graph cookies
// Guard ensures cleanup even if exception occurs
Scope_Guard guard(g, [](const GT & graph) {
});
// ... algorithm code that might throw ...
// Destructor calls uninit_algorithm(g) automatically
Generic RAII scope guard for cleanup operations on graphs.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Author
Leandro Rabindranath León

Definition at line 559 of file cookie_guard.H.

Constructor & Destructor Documentation

◆ Scope_Guard() [1/3]

template<class GT , class Cleanup >
Aleph::Scope_Guard< GT, Cleanup >::Scope_Guard ( const GT g,
Cleanup  cleanup 
)
inline

Construct a scope guard.

Parameters
gGraph to pass to cleanup function.
cleanupFunction to call on destruction.

Definition at line 571 of file cookie_guard.H.

◆ Scope_Guard() [2/3]

Copying disabled.

◆ Scope_Guard() [3/3]

template<class GT , class Cleanup >
Aleph::Scope_Guard< GT, Cleanup >::Scope_Guard ( Scope_Guard< GT, Cleanup > &&  other)
inlinenoexcept

Move construction transfers ownership.

Definition at line 580 of file cookie_guard.H.

References Aleph::maps().

◆ ~Scope_Guard()

template<class GT , class Cleanup >
Aleph::Scope_Guard< GT, Cleanup >::~Scope_Guard ( )
inline

Destructor - calls cleanup function if still active.

Definition at line 588 of file cookie_guard.H.

References Aleph::Scope_Guard< GT, Cleanup >::active, Aleph::Scope_Guard< GT, Cleanup >::cleanup_fn, and Aleph::Scope_Guard< GT, Cleanup >::graph.

Member Function Documentation

◆ cleanup_now()

template<class GT , class Cleanup >
void Aleph::Scope_Guard< GT, Cleanup >::cleanup_now ( )
inline

Execute cleanup immediately and deactivate.

Safe to call multiple times - only first call executes cleanup.

Definition at line 607 of file cookie_guard.H.

References Aleph::Scope_Guard< GT, Cleanup >::active, Aleph::Scope_Guard< GT, Cleanup >::cleanup_fn, and Aleph::Scope_Guard< GT, Cleanup >::graph.

◆ is_active()

template<class GT , class Cleanup >
bool Aleph::Scope_Guard< GT, Cleanup >::is_active ( ) const
inlinenoexcept

Check if guard is still active.

Definition at line 601 of file cookie_guard.H.

References Aleph::Scope_Guard< GT, Cleanup >::active.

◆ operator=()

◆ release()

template<class GT , class Cleanup >
void Aleph::Scope_Guard< GT, Cleanup >::release ( )
inlinenoexcept

Release the guard without calling cleanup.

Use this if cleanup was performed manually or is no longer needed.

Definition at line 598 of file cookie_guard.H.

References Aleph::Scope_Guard< GT, Cleanup >::active.

Member Data Documentation

◆ active

◆ cleanup_fn

◆ graph


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