_Tp object calling a custom Dispose function when the last AutoDispose handle to it is destroyed or reset.
More...
#include <AutoDispose.h>
Public Types | |
| typedef boost::call_traits< _Tp >::param_type | param_type |
| typedef boost::call_traits< _Tp >::reference | reference |
| typedef boost::call_traits< _Tp >::const_reference | const_reference |
| typedef _Tp | value_type |
| typedef boost::call_traits< _Tp >::value_type | result_type |
| typedef function< void(param_type)> | Dispose |
| Dispose function signatue. | |
Public Member Functions | |
| AutoDispose () | |
| Default Ctor using default constructed value and nodispose function. | |
| AutoDispose (param_type value_r) | |
| Ctor taking value and using nodispose function. | |
| AutoDispose (param_type value_r, const Dispose &dispose_r) | |
| Ctor taking value and dispose function. | |
| operator reference () const | |
Provide implicit conversion to _Tp&. | |
| reference | value () const |
Reference to the _Tp object. | |
| reference | operator * () const |
Reference to the _Tp object. | |
| value_type * | operator-> () const |
Pointer to the _Tp object (asserted to be != NULL<>). | |
| void | reset () |
| Reset to default Ctor values. | |
| void | swap (AutoDispose &rhs) |
| Exchange the contents of two AutoDispose objects. | |
| const Dispose & | getDispose () const |
| Return the current dispose function. | |
| void | setDispose (const Dispose &dispose_r) |
| Set a new dispose function. | |
| void | resetDispose () |
| Set nodispose function. | |
| void | swapDispose (Dispose &dispose_r) |
| Exchange the dispose function. | |
Static Public Member Functions | |
| static void | nodispose (param_type) |
| Noop dispose function. | |
Private Attributes | |
| shared_ptr< Impl > | _pimpl |
Related Functions | |
| (Note that these are not member functions.) | |
| std::ostream & | operator<< (std::ostream &str, const AutoDispose< _Tp > &obj) |
Classes | |
| struct | Impl |
_Tp object calling a custom Dispose function when the last AutoDispose handle to it is destroyed or reset.
AutoDispose object does not apply to the stored _Tp object. If the stored _Tp object should be immutable, you should use AutoDispose<const _Tp><>.struct FileCache { Pathname getFile(); void releaseFile( const Pathname & ); }; static FileCache cache; void unlink( const Pathname & file_r ); AutoDispose<const Pathname> provideFile( ... ) { if ( file_is_in_cache ) { // will call 'cache.releaseFile( file )' return AutoDispose<const Pathname>( cache.getFile(), bind( &FileCache::releaseFile, ref(cache), _1 ) ); } else if ( file_is_temporary ) { // will call 'unlink( file )' return AutoDispose<const Pathname>( file, unlink ); } else if ( file_is_permanent ) { // will do nothing. return AutoDispose<const Pathname>( file ); } else { // will do nothing. return AutoDispose<const Pathname>(); } }
Exception safe handling of temporary files:
void provideFileAt( const Pathname & destination )
{
AutoDispose<const Pathname> guard( destination, unlink );
// Any exception here will lead to 'unlink( destination )'
// ...
// On success: reset the dispose function to NOOP.
guard.resetDispose();
}
Definition at line 92 of file AutoDispose.h.
|
|||||
|
Definition at line 95 of file AutoDispose.h. |
|
|||||
|
Definition at line 96 of file AutoDispose.h. |
|
|||||
|
Definition at line 97 of file AutoDispose.h. |
|
|||||
|
Definition at line 98 of file AutoDispose.h. |
|
|||||
|
Definition at line 99 of file AutoDispose.h. |
|
|||||
|
Dispose function signatue.
Definition at line 103 of file AutoDispose.h. |
|
|||||||||
|
Default Ctor using default constructed value and nodispose function.
Definition at line 110 of file AutoDispose.h. Referenced by zypp::AutoDispose< _Tp >::reset(). |
|
||||||||||
|
Ctor taking value and using nodispose function.
Definition at line 115 of file AutoDispose.h. |
|
||||||||||||||||
|
Ctor taking value and dispose function.
Definition at line 120 of file AutoDispose.h. |
|
||||||||||
|
Noop dispose function.
Definition at line 106 of file AutoDispose.h. Referenced by zypp::AutoDispose< _Tp >::resetDispose(), and zypp::AutoDispose< _Tp >::Impl::~Impl(). |
|
|||||||||
|
Provide implicit conversion to
Definition at line 127 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
|||||||||
|
Reference to the
Definition at line 131 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
|||||||||
|
Reference to the
Definition at line 135 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
|||||||||
|
Pointer to the
Definition at line 139 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
|||||||||
|
Reset to default Ctor values.
Definition at line 143 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::AutoDispose(). |
|
||||||||||
|
Exchange the contents of two AutoDispose objects.
Definition at line 147 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
|||||||||
|
Return the current dispose function.
Definition at line 152 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
||||||||||
|
Set a new dispose function.
Definition at line 156 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. Referenced by zypp::AutoDispose< _Tp >::resetDispose(). |
|
|||||||||
|
Set nodispose function.
Definition at line 160 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::nodispose(), and zypp::AutoDispose< _Tp >::setDispose(). Referenced by zypp::applydeltarpm::provide(). |
|
||||||||||
|
Exchange the dispose function. + Definition at line 164 of file AutoDispose.h. References zypp::AutoDispose< _Tp >::_pimpl. |
|
||||||||||||||||
|
<_Tp> Stream output of the Definition at line 189 of file AutoDispose.h. |
|
|||||
1.4.6