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;
98 typedef typename boost::call_traits<Tp>::const_reference
const_reference;
100 typedef typename boost::call_traits<Tp>::value_type
result_type;
103 using dispose_param_type =
typename std::conditional< std::is_pointer<Tp>::value || std::is_integral<Tp>::value, Tp
const,
reference >::type;
144 {
return _pimpl->_value; }
148 {
return _pimpl->_value; }
152 {
return _pimpl->_value; }
156 {
return &
_pimpl->_value; }
164 {
_pimpl.swap( rhs._pimpl ); }
168 {
return _pimpl.unique(); }
173 {
return _pimpl->_dispose; }
177 {
_pimpl->_dispose = dispose_r; }
185 {
_pimpl->_dispose.swap( dispose_r ); }
190 template <
typename T>
194 template <
typename T,
typename D>
195 Impl( T &&value_r, D &&dispose_r )
212 class AutoDispose<void>
216 typedef function<void ()>
Dispose;
237 {
_pimpl.swap( rhs._pimpl ); }
242 {
return _pimpl->_dispose; }
246 {
_pimpl->_dispose = dispose_r; }
254 {
_pimpl->_dispose.swap( dispose_r ); }
292 inline std::ostream &
operator<<( std::ostream &
str,
const AutoDispose<Tp> & obj )
293 {
return str << obj.value(); }
301 struct AutoFD :
public AutoDispose<int>
303 AutoFD(
int fd_r = -1 ) :
AutoDispose<int>( fd_r, [] ( int fd_r ) {
if ( fd_r != -1 ) ::close( fd_r ); } ) {}
312 struct AutoFILE :
public AutoDispose<FILE*>
314 AutoFILE( FILE* file_r =
nullptr ) :
AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) {
if ( file_r ) ::fclose( file_r ); } ) {}
322 template <
typename Tp>
323 struct AutoFREE :
public AutoDispose<Tp*>
325 AutoFREE( Tp* ptr_r =
nullptr ) :
AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
330 struct AutoFREE<void> :
public AutoDispose<void*>
332 AutoFREE(
void* ptr_r =
nullptr ) :
AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
RepoManager implementation.
value_type * operator->() const
Pointer to the Tp object (asserted to be != NULL).
reference value() const
Reference to 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()
Default Ctor using default constructed value and no dispose function.
reference operator*() const
Reference to the Tp object.
void reset()
Reset to default Ctor values.
shared_ptr< Impl > _pimpl
void swap(AutoDispose &rhs)
Exchange the contents of two AutoDispose objects.
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.
boost::call_traits< Tp >::param_type param_type
boost::call_traits< Tp >::reference reference
boost::call_traits< Tp >::const_reference const_reference
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
boost::call_traits< Tp >::value_type result_type
typename std::conditional< std::is_pointer< Tp >::value||std::is_integral< Tp >::value, Tp const, reference >::type dispose_param_type
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 > Deferred
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
AutoDispose< void > OnScopeExit
AutoFILE(FILE *file_r=nullptr)
AutoFREE(Tp *ptr_r=nullptr)