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;
103 typedef function<void ( param_type )>
Dispose;
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 ); }
194 inline std::ostream & operator<<( std::ostream & str, const AutoDispose<Tp> & obj )
195 {
return str << obj.value(); }
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