xbmc
Public Member Functions | List of all members
KODI::UTILS::CScopeGuard< Handle, invalid, Deleter > Class Template Reference

Generic scopeguard designed to handle any type of handle. More...

#include <ScopeGuard.h>

Public Member Functions

 CScopeGuard (std::function< Deleter > del, Handle handle=invalid)
 
 operator Handle () const
 
 operator bool () const
 
void attach (Handle handle)
 attach a new handle to this instance, if there's already a handle it will be closed. More...
 
Handle release ()
 release the managed handle so that it won't be auto closed More...
 
void reset ()
 reset the instance, closing any managed handle and setting it to invalid
 
 CScopeGuard (const CScopeGuard &rhs)=delete
 
CScopeGuardoperator= (const CScopeGuard &rhs)=delete
 
 CScopeGuard (CScopeGuard &&rhs) noexcept
 
CScopeGuardoperator= (CScopeGuard &&rhs) noexcept
 

Detailed Description

template<typename Handle, Handle invalid, typename Deleter>
class KODI::UTILS::CScopeGuard< Handle, invalid, Deleter >

Generic scopeguard designed to handle any type of handle.

This is not necessary but recommended to cut down on some typing using CSocketHandle = CScopeGuard<SOCKET, INVALID_SOCKET, closesocket>;

CSocketHandle sh(closesocket, open(thingy));

Member Function Documentation

◆ attach()

template<typename Handle, Handle invalid, typename Deleter>
void KODI::UTILS::CScopeGuard< Handle, invalid, Deleter >::attach ( Handle  handle)
inline

attach a new handle to this instance, if there's already a handle it will be closed.

Parameters
[in]handleThe handle to manage

◆ release()

template<typename Handle, Handle invalid, typename Deleter>
Handle KODI::UTILS::CScopeGuard< Handle, invalid, Deleter >::release ( )
inline

release the managed handle so that it won't be auto closed

Returns
The handle being managed by the guard

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