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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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]

template<class GT , class Cleanup >
Aleph::Scope_Guard< GT, Cleanup >::Scope_Guard ( const Scope_Guard< GT, Cleanup > &  )
delete

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::divide_and_conquer_partition_dp().

◆ ~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.

Referenced by TEST_F().

◆ 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=()

template<class GT , class Cleanup >
Scope_Guard & Aleph::Scope_Guard< GT, Cleanup >::operator= ( const Scope_Guard< GT, Cleanup > &  )
delete

◆ 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.

Referenced by TEST_F().

Member Data Documentation

◆ active

◆ cleanup_fn

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

◆ graph

template<class GT , class Cleanup >
const GT& Aleph::Scope_Guard< GT, Cleanup >::graph
private

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