Castor3D 0.16.0
Multiplatform 3D engine
Public Member Functions | List of all members
castor::BlockGuard< CleanFunc > Struct Template Reference

Allows to declare a scoped variable with an action on construction
and an action on destruction. More...

#include <BlockGuard.hpp>

Inheritance diagram for castor::BlockGuard< CleanFunc >:
Inheritance graph
[legend]
Collaboration diagram for castor::BlockGuard< CleanFunc >:
Collaboration graph
[legend]

Public Member Functions

 BlockGuard (BlockGuard const &)=delete
 
 BlockGuard (BlockGuard &&) noexcept=delete
 
BlockGuardoperator= (BlockGuard const &)=delete
 
BlockGuardoperator= (BlockGuard &&) noexcept=delete
 
template<typename InitFunc >
 BlockGuard (InitFunc init, CleanFunc clean)
 Constructor.
 
 ~BlockGuard () noexcept
 Destructor.
 

Additional Inherited Members

- Protected Member Functions inherited from castor::NonMovable
 NonMovable ()=default
 Constructor.
 
 ~NonMovable () noexcept=default
 Destructor.
 

Detailed Description

template<typename CleanFunc>
struct castor::BlockGuard< CleanFunc >

Allows to declare a scoped variable with an action on construction
and an action on destruction.

Remarks
Useful to force execution of code when an exception is thrown. Example
char * buffer = nullptr;
{
auto guard = makeBlockGuard( [&buffer, &size]()
{
buffer = new char[size + 1];
},
[&buffer]()
{
delete [] buffer;
} );
//
// ... Code that might throw an exception ...
//
}
BlockGuard< CleanFunc > makeBlockGuard(InitFunc init, CleanFunc clean)
Helper function to declare a BlockGuard.
Definition BlockGuard.hpp:70

Constructor & Destructor Documentation

◆ BlockGuard() [1/3]

template<typename CleanFunc >
castor::BlockGuard< CleanFunc >::BlockGuard ( BlockGuard< CleanFunc > const & )
delete

◆ BlockGuard() [2/3]

template<typename CleanFunc >
castor::BlockGuard< CleanFunc >::BlockGuard ( BlockGuard< CleanFunc > && )
deletenoexcept

◆ BlockGuard() [3/3]

template<typename CleanFunc >
template<typename InitFunc >
castor::BlockGuard< CleanFunc >::BlockGuard ( InitFunc init,
CleanFunc clean )
inline

Constructor.

Remarks
Executes the init action.
Parameters
[in]initThe action executed on construction.
[in]cleanThe action executed on destruction.

◆ ~BlockGuard()

template<typename CleanFunc >
castor::BlockGuard< CleanFunc >::~BlockGuard ( )
inlinenoexcept

Destructor.

Remarks
Executes the clean action.

Member Function Documentation

◆ operator=() [1/2]

template<typename CleanFunc >
BlockGuard & castor::BlockGuard< CleanFunc >::operator= ( BlockGuard< CleanFunc > && )
deletenoexcept

◆ operator=() [2/2]

template<typename CleanFunc >
BlockGuard & castor::BlockGuard< CleanFunc >::operator= ( BlockGuard< CleanFunc > const & )
delete

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