12 #ifndef ZYPP_AUTODISPOSE_H 13 #define ZYPP_AUTODISPOSE_H 16 #include <boost/call_traits.hpp> 18 #include <zypp-core/base/NonCopyable.h> 19 #include <zypp-core/base/PtrTypes.h> 20 #include <zypp-core/base/Function.h> 21 #include <zypp-core/Pathname.h> 96 typedef typename boost::call_traits<Tp>::param_type
param_type;
97 typedef typename boost::call_traits<Tp>::reference
reference;
105 using Dispose = function<void ( dispose_param_type )>;
132 {
return _pimpl->_value; }
136 {
return _pimpl->_value; }
140 {
return _pimpl->_value; }
144 {
return &
_pimpl->_value; }
157 {
return _pimpl->_dispose; }
161 {
_pimpl->_dispose = dispose_r; }
169 {
_pimpl->_dispose.swap( dispose_r ); }
224 {
return _pimpl->_dispose; }
228 {
_pimpl->_dispose = dispose_r; }
236 {
_pimpl->_dispose.swap( dispose_r ); }
273 inline std::ostream & operator<<( std::ostream & str, const AutoDispose<Tp> & obj )
274 {
return str << obj.value(); }
284 AutoFD(
int fd_r = -1 ) :
AutoDispose<int>( fd_r, [] ( int fd_r ) {
if ( fd_r != -1 ) ::close( fd_r ); } ) {}
295 AutoFILE( FILE* file_r =
nullptr ) :
AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) {
if ( file_r ) ::fclose( file_r ); } ) {}
303 template <
typename Tp>
306 AutoFREE( Tp* ptr_r =
nullptr ) :
AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
313 AutoFREE(
void* ptr_r =
nullptr ) :
AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
318 #endif // ZYPP_AUTODISPOSE_H AutoFREE(Tp *ptr_r=nullptr)
Impl(const Dispose &dispose_r)
void reset()
Reset to default Ctor values.
void swapDispose(Dispose &dispose_r)
Exchange the dispose function.
shared_ptr< Impl > _pimpl
void swap(AutoDispose &rhs)
Exchange the contents of two AutoDispose objects.
String related utilities and Regular expression matching.
std::conditional_t< std::is_pointer_v< FILE * >||std::is_integral_v< FILE * >, FILE * const, reference > dispose_param_type
void reset()
Reset to default Ctor values.
AutoDispose<int> calling ::close
void swap(AutoDispose &rhs)
Exchange the contents of two AutoDispose objects.
shared_ptr< Impl > _pimpl
void resetDispose()
Set no dispose function.
function< void(dispose_param_type)> Dispose
Dispose function signatue.
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
Impl(param_type value_r, const Dispose &dispose_r)
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
AutoDispose()
Default Ctor using default constructed value and no dispose function.
const Dispose & getDispose() const
Return the current dispose function.
reference operator*() const
Reference to the Tp object.
boost::call_traits< Tp >::const_reference const_reference
AutoDispose()
Default Ctor using default constructed value and no dispose function.
boost::call_traits< Tp >::param_type param_type
boost::call_traits< Tp >::value_type result_type
void resetDispose()
Set no dispose function.
AutoDispose(const Dispose &dispose_r)
Ctor taking dispose function and using default constructed value.
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
AutoFILE(FILE *file_r=nullptr)
AutoDispose(const Dispose &dispose_r)
Ctor taking dispose function and using default constructed value.
AutoFREE(void *ptr_r=nullptr)
reference value() const
Reference to the Tp object.
boost::call_traits< Tp >::reference reference
void swapDispose(Dispose &dispose_r)
Exchange the dispose function.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
AutoDispose<FILE*> calling ::fclose
value_type * operator->() const
Pointer to the Tp object (asserted to be != NULL).
AutoDispose(param_type value_r)
Ctor taking value and no dispose function.
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose(param_type value_r, const Dispose &dispose_r)
Ctor taking value and dispose function.
function< void()> Dispose
Dispose function signatue.
const Dispose & getDispose() const
Return the current dispose function.