userver: utils::ResourceScopeStorage Class Reference
Loading...
Searching...
No Matches
utils::ResourceScopeStorage Class Referencefinal

#include <userver/utils/resource_scopes.hpp>

Detailed Description

Smart collection of ScopePtr. It is a helper class used in component system or in a component-less unit tests.

Definition at line 68 of file resource_scopes.hpp.

Public Member Functions

template<typename AfterConstructionCallback>
void Register (AfterConstructionCallback after_construction)
 Registers a functor to register some resource that will be called after the component is successfully created (including all class descendants) or after the component creation is emulated in unit tests. The functor must return a RAII-style handle object that unregisters the previously registered resource. The returned handle's destructor is called just before the component destructor is called.
 
void AfterConstruction ()
 Call all registered functors.
 
void BeforeDestruction ()
 Free all unregister previously rgistered resources.
 

Member Function Documentation

◆ Register()

template<typename AfterConstructionCallback>
void utils::ResourceScopeStorage::Register ( AfterConstructionCallback after_construction)
inline

Registers a functor to register some resource that will be called after the component is successfully created (including all class descendants) or after the component creation is emulated in unit tests. The functor must return a RAII-style handle object that unregisters the previously registered resource. The returned handle's destructor is called just before the component destructor is called.

Note
callback is not called if the component is not created OR any previously registered callback throws an exception.
if you don't have an existing RAII-ish class, but still want to do a cleanup, you might want to use utils::FastScopeGuard to wrap the cleanup function.

Definition at line 83 of file resource_scopes.hpp.


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