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

RAII guard for graph algorithm initialization. More...

#include <ah_init_guard.H>

Public Member Functions

 Init_Guard (CleanupFunc f)
 Construct guard with cleanup function.
 
 ~Init_Guard ()
 Destructor calls cleanup if not released.
 
void release () noexcept
 Release the guard - cleanup will not be called.
 
bool is_released () const noexcept
 Check if the guard has been released.
 
 Init_Guard (const Init_Guard &)=delete
 Non-copyable.
 
Init_Guardoperator= (const Init_Guard &)=delete
 
 Init_Guard (Init_Guard &&other) noexcept
 Move constructor.
 
Init_Guardoperator= (Init_Guard &&other) noexcept
 Move assignment operator.
 

Private Attributes

CleanupFunc cleanup
 
bool released = false
 

Detailed Description

template<typename CleanupFunc>
class Aleph::Init_Guard< CleanupFunc >

RAII guard for graph algorithm initialization.

This template class provides exception-safe cleanup for graph algorithms that allocate resources during initialization (e.g., node/arc cookies).

The guard calls the provided cleanup function when destroyed, unless release() has been called to indicate successful completion.

Template Parameters
CleanupFuncA callable type (lambda, function object) that performs the cleanup when invoked with no arguments.

Usage example:

void my_algorithm(Graph& g) {
// ... algorithm that might throw ...
guard.release(); // Success - don't cleanup
}
RAII guard for graph algorithm initialization.
DynList< T > maps(const C &c, Op op)
Classic map operation.

Definition at line 79 of file ah_init_guard.H.

Constructor & Destructor Documentation

◆ Init_Guard() [1/3]

template<typename CleanupFunc >
Aleph::Init_Guard< CleanupFunc >::Init_Guard ( CleanupFunc  f)
inlineexplicit

Construct guard with cleanup function.

Parameters
fCleanup function to call on destruction (if not released).

Definition at line 90 of file ah_init_guard.H.

◆ ~Init_Guard()

Destructor calls cleanup if not released.

If release() was not called, the cleanup function is invoked.

Definition at line 96 of file ah_init_guard.H.

References Aleph::Init_Guard< CleanupFunc >::cleanup, Aleph::maps(), and Aleph::Init_Guard< CleanupFunc >::released.

◆ Init_Guard() [2/3]

template<typename CleanupFunc >
Aleph::Init_Guard< CleanupFunc >::Init_Guard ( const Init_Guard< CleanupFunc > &  )
delete

Non-copyable.

◆ Init_Guard() [3/3]

template<typename CleanupFunc >
Aleph::Init_Guard< CleanupFunc >::Init_Guard ( Init_Guard< CleanupFunc > &&  other)
inlinenoexcept

Move constructor.

Transfers ownership of the cleanup function to this guard. The moved-from guard is marked as released.

Parameters
otherGuard to move from.

Definition at line 126 of file ah_init_guard.H.

References Aleph::maps().

Member Function Documentation

◆ is_released()

template<typename CleanupFunc >
bool Aleph::Init_Guard< CleanupFunc >::is_released ( ) const
inlinenoexcept

Check if the guard has been released.

Returns
true if release() has been called, false otherwise.

Definition at line 113 of file ah_init_guard.H.

References Aleph::Init_Guard< CleanupFunc >::released.

◆ operator=() [1/2]

◆ operator=() [2/2]

Move assignment operator.

If this guard holds an active cleanup, it is executed first. Then ownership is transferred from other.

Parameters
otherGuard to move from.
Returns
Reference to this.

Definition at line 140 of file ah_init_guard.H.

References Aleph::Init_Guard< CleanupFunc >::cleanup, Aleph::maps(), and Aleph::Init_Guard< CleanupFunc >::released.

◆ release()

template<typename CleanupFunc >
void Aleph::Init_Guard< CleanupFunc >::release ( )
inlinenoexcept

Release the guard - cleanup will not be called.

Call this method to indicate successful completion. After calling this, the cleanup function will not be invoked on destruction.

Definition at line 107 of file ah_init_guard.H.

References Aleph::Init_Guard< CleanupFunc >::released.

Member Data Documentation

◆ cleanup

◆ released


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