12#ifndef ZYPP_AUTODISPOSE_H 
   13#define ZYPP_AUTODISPOSE_H 
   16#include <boost/call_traits.hpp> 
   97      using param_type = 
typename boost::call_traits<Tp>::param_type;
 
   98      using reference = 
typename boost::call_traits<Tp>::reference;
 
  123      : 
_pimpl( new Impl( 
std::move(value_r) ) )
 
 
  128      : 
_pimpl( new Impl( 
std::move(value_r), 
std::move(dispose_r) ) )
 
 
  135      { 
return _pimpl->_value; }
 
 
  139      { 
return _pimpl->_value; }
 
 
  143      { 
return _pimpl->_value; }
 
 
  147      { 
return & 
_pimpl->_value; }
 
 
  155      { 
_pimpl.swap( rhs._pimpl ); }
 
 
  159      { 
return _pimpl.unique(); }
 
 
  164      { 
return _pimpl->_dispose; }
 
 
  168      { 
_pimpl->_dispose = dispose_r; }
 
 
  176      { 
_pimpl->_dispose.swap( dispose_r ); }
 
 
  181        template <
typename T>
 
  185        template <
typename T, 
typename D>
 
  186        Impl( T &&value_r, D &&dispose_r )
 
 
 
 
  207      using Dispose = function<void ()>;
 
  228      { 
_pimpl.swap( rhs._pimpl ); }
 
  233      { 
return _pimpl->_dispose; }
 
  237      { 
_pimpl->_dispose = dispose_r; }
 
  245      { 
_pimpl->_dispose.swap( dispose_r ); }
 
  280    template <
typename F>
 
 
  287#define __zypp_defer_concatenate(__lhs, __rhs) \ 
 
  290#define __zypp_defer_declarator(__id) \ 
  291    zypp::Deferred __zypp_defer_concatenate(__defer, __id) = [&]() 
 
  294    __zypp_defer_declarator(__LINE__) 
 
  311    AutoFD( 
int fd_r = -1 ) : 
AutoDispose<int>( fd_r, [] ( int fd_r ) { 
if ( fd_r != -1 ) ::close( fd_r ); } ) {}
 
 
  322    AutoFILE( FILE* file_r = 
nullptr ) : 
AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) { 
if ( file_r ) ::fclose( file_r ); } ) {}
 
 
  330  template <
typename Tp>
 
  333    AutoFREE( Tp* ptr_r = 
nullptr ) : 
AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) { 
if ( ptr_r ) ::free( ptr_r ); } ) {}
 
 
  340    AutoFREE( 
void* ptr_r = 
nullptr ) : 
AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) { 
if ( ptr_r ) ::free( ptr_r ); } ) {}
 
 
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
value_type * operator->() const
Pointer to the Tp object (asserted to be != NULL).
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
reference value() const
Reference to the Tp object.
std::ostream & operator<<(std::ostream &str, const AutoDispose< Tp > &obj)
Stream output of the Tp object.
const Dispose & getDispose() const
Return the current dispose function.
void resetDispose()
Set no dispose function.
function< void(dispose_param_type)> Dispose
Dispose function signatue.
AutoDispose(Dispose dispose_r)
Ctor taking dispose function and using default constructed value.
AutoDispose()
Default Ctor using default constructed value and no dispose function.
std::conditional_t< std::is_pointer_v< Tp >||std::is_integral_v< Tp >, Tp const, reference > dispose_param_type
reference operator*() const
Reference to the Tp object.
typename boost::call_traits< Tp >::const_reference const_reference
void reset()
Reset to default Ctor values.
shared_ptr< Impl > _pimpl
void swapDispose(Dispose &dispose_r)
Exchange the dispose function.
bool unique() const
Returns true if this is the only AutoDispose instance managing the current data object.
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
typename boost::call_traits< Tp >::param_type param_type
typename boost::call_traits< Tp >::reference reference
AutoDispose(value_type value_r, Dispose dispose_r)
Ctor taking value and dispose function.
AutoDispose(value_type value_r)
Ctor taking value and no dispose function.
typename boost::call_traits< Tp >::value_type result_type
constexpr bool is_integral_v
typename conditional< B, T, F >::type conditional_t
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose< void > OnScopeExit
Impl(T &&value_r, D &&dispose_r)
AutoFILE(FILE *file_r=nullptr)
AutoFREE(void *ptr_r=nullptr)
AutoFREE(Tp *ptr_r=nullptr)