Go to the documentation of this file.
12 #ifndef ZYPP_AUTODISPOSE_H
13 #define ZYPP_AUTODISPOSE_H
16 #include <boost/call_traits.hpp>
95 typedef typename boost::call_traits<Tp>::param_type
param_type;
96 typedef typename boost::call_traits<Tp>::reference
reference;
99 typedef typename boost::call_traits<Tp>::value_type
result_type;
130 {
return _pimpl->_value; }
134 {
return _pimpl->_value; }
138 {
return _pimpl->_value; }
142 {
return &
_pimpl->_value; }
155 {
return _pimpl->_dispose; }
159 {
_pimpl->_dispose = dispose_r; }
167 {
_pimpl->_dispose.swap( dispose_r ); }
205 AutoFD(
int fd_r = -1 ) :
AutoDispose<int>( fd_r, [] ( int fd_r ) {
if ( fd_r != -1 ) ::close( fd_r ); } ) {}
216 AutoFILE( FILE* file_r =
nullptr ) :
AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) {
if ( file_r ) ::fclose( file_r ); } ) {}
224 template <
typename Tp>
227 AutoFREE( Tp* ptr_r =
nullptr ) :
AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
234 AutoFREE(
void* ptr_r =
nullptr ) :
AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
239 #endif // ZYPP_AUTODISPOSE_H
void swap(AutoDispose &rhs)
Exchange the contents of two AutoDispose objects.
value_type * operator->() const
Pointer to the Tp object (asserted to be != NULL).
boost::call_traits< Tp >::param_type param_type
shared_ptr< Impl > _pimpl
AutoDispose<int> calling ::close
AutoDispose(param_type value_r, const Dispose &dispose_r)
Ctor taking value and dispose function.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
const Dispose & getDispose() const
Return the current dispose function.
Impl(param_type value_r, const Dispose &dispose_r)
AutoFILE(FILE *file_r=nullptr)
Easy-to use interface to the ZYPP dependency resolver.
boost::call_traits< Tp >::reference reference
void reset()
Reset to default Ctor values.
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
AutoDispose<FILE*> calling ::fclose
function< void(param_type)> Dispose
Dispose function signatue.
AutoFREE(void *ptr_r=nullptr)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
reference value() const
Reference to the Tp object.
AutoDispose()
Default Ctor using default constructed value and no dispose function.
String related utilities and Regular expression matching.
void resetDispose()
Set no dispose function.
std::ostream & operator<<(std::ostream &str, const AutoDispose< Tp > &obj)
reference operator*() const
Reference to the Tp object.
void swapDispose(Dispose &dispose_r)
Exchange the dispose function.
boost::call_traits< Tp >::value_type result_type
boost::call_traits< Tp >::const_reference const_reference
AutoDispose(param_type value_r)
Ctor taking value and no dispose function.
AutoDispose(const Dispose &dispose_r)
Ctor taking dispose function and using default constructed value.
AutoFREE(Tp *ptr_r=nullptr)