Botan 3.9.0
Crypto and TLS for C&
Botan::scoped_cleanup< FunT > Class Template Referencefinal

Helper class to create a RAII-style cleanup callback. More...

#include <stl_util.h>

Public Member Functions

void disengage () noexcept
scoped_cleanupoperator= (const scoped_cleanup &)=delete
scoped_cleanupoperator= (scoped_cleanup &&other) noexcept
 scoped_cleanup (const scoped_cleanup &)=delete
 scoped_cleanup (FunT cleanup)
 scoped_cleanup (scoped_cleanup &&other) noexcept
 ~scoped_cleanup ()

Detailed Description

template<std::invocable FunT>
class Botan::scoped_cleanup< FunT >

Helper class to create a RAII-style cleanup callback.

Ensures that the cleanup callback given in the object's constructor is called when the object is destroyed. Use this to ensure some cleanup code runs when leaving the current scope.

Definition at line 346 of file stl_util.h.

Constructor & Destructor Documentation

◆ scoped_cleanup() [1/3]

template<std::invocable FunT>
Botan::scoped_cleanup< FunT >::scoped_cleanup ( FunT cleanup)
inlineexplicit

Definition at line 348 of file stl_util.h.

348: m_cleanup(std::move(cleanup)) {}
Helper class to create a RAII-style cleanup callback.
Definition stl_util.h:346

Referenced by operator=(), operator=(), scoped_cleanup(), and scoped_cleanup().

◆ scoped_cleanup() [2/3]

template<std::invocable FunT>
Botan::scoped_cleanup< FunT >::scoped_cleanup ( const scoped_cleanup< FunT > & )
delete

References scoped_cleanup().

◆ scoped_cleanup() [3/3]

template<std::invocable FunT>
Botan::scoped_cleanup< FunT >::scoped_cleanup ( scoped_cleanup< FunT > && other)
inlinenoexcept

Definition at line 353 of file stl_util.h.

353: m_cleanup(std::move(other.m_cleanup)) { other.disengage(); }
void disengage() noexcept
Definition stl_util.h:372

References scoped_cleanup().

◆ ~scoped_cleanup()

template<std::invocable FunT>
Botan::scoped_cleanup< FunT >::~scoped_cleanup ( )
inline

Definition at line 363 of file stl_util.h.

363 {
364 if(m_cleanup.has_value()) {
365 m_cleanup.value()();
366 }
367 }

Member Function Documentation

◆ disengage()

template<std::invocable FunT>
void Botan::scoped_cleanup< FunT >::disengage ( )
inlinenoexcept

Disengage the cleanup callback, i.e., prevent it from being called

Definition at line 372 of file stl_util.h.

372{ m_cleanup.reset(); }

◆ operator=() [1/2]

template<std::invocable FunT>
scoped_cleanup & Botan::scoped_cleanup< FunT >::operator= ( const scoped_cleanup< FunT > & )
delete

References scoped_cleanup().

◆ operator=() [2/2]

template<std::invocable FunT>
scoped_cleanup & Botan::scoped_cleanup< FunT >::operator= ( scoped_cleanup< FunT > && other)
inlinenoexcept

Definition at line 355 of file stl_util.h.

355 {
356 if(this != &other) {
357 m_cleanup = std::move(other.m_cleanup);
359 }
360 return *this;
361 }

References scoped_cleanup().


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