///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : AutoDispose<_Tp>
+ // CLASS NAME : AutoDispose<Tp>
//
- /** Reference counted access to a \c _Tp object calling a custom
+ /** Reference counted access to a \c Tp object calling a custom
* \c Dispose function when the last AutoDispose handle to it is
* destroyed or reset.
*
* \note As with pointers, constness of an \c AutoDispose object does
- * \b not apply to the stored \c _Tp object. If the stored \c _Tp object
- * should be immutable, you should use <tt>AutoDispose\<const _Tp\></tt>.
+ * \b not apply to the stored \c Tp object. If the stored \c Tp object
+ * should be immutable, you should use <tt>AutoDispose\<const Tp\></tt>.
*
* Pass a filename to the application and provide the appropriate
* code to be executed when the file is no longer needed:
* }
* \endcode
*/
- template<class _Tp>
+ template<class Tp>
class AutoDispose
{
public:
- typedef typename boost::call_traits<_Tp>::param_type param_type;
- typedef typename boost::call_traits<_Tp>::reference reference;
- typedef typename boost::call_traits<_Tp>::const_reference const_reference;
- typedef _Tp value_type;
- typedef typename boost::call_traits<_Tp>::value_type result_type;
+ typedef typename boost::call_traits<Tp>::param_type param_type;
+ typedef typename boost::call_traits<Tp>::reference reference;
+ typedef typename boost::call_traits<Tp>::const_reference const_reference;
+ typedef Tp value_type;
+ typedef typename boost::call_traits<Tp>::value_type result_type;
public:
/** Dispose function signatue. */
public:
- /** Provide implicit conversion to \c _Tp\&. */
+ /** Provide implicit conversion to \c Tp\&. */
operator reference() const
{ return _pimpl->_value; }
- /** Reference to the \c _Tp object. */
+ /** Reference to the \c Tp object. */
reference value() const
{ return _pimpl->_value; }
- /** Reference to the \c _Tp object. */
+ /** Reference to the \c Tp object. */
reference operator*() const
{ return _pimpl->_value; }
- /** Pointer to the \c _Tp object (asserted to be <tt>!= NULL</tt>). */
+ /** Pointer to the \c Tp object (asserted to be <tt>!= NULL</tt>). */
value_type * operator->() const
{ return & _pimpl->_value; }
};
///////////////////////////////////////////////////////////////////
- /** \relates AutoDispose<_Tp> Stream output of the \c _Tp object. */
- template<class _Tp>
- inline std::ostream & operator<<( std::ostream & str, const AutoDispose<_Tp> & obj )
+ /** \relates AutoDispose Stream output of the \c Tp object. */
+ template<class Tp>
+ inline std::ostream & operator<<( std::ostream & str, const AutoDispose<Tp> & obj )
{ return str << obj.value(); }
-
- ///////////////////////////////////////////////////////////////////
- /// \class AutoFD
- /// \brief \ref AutoDispose\<int> calling \c ::close
- /// \ingroup g_RAII
- ///////////////////////////////////////////////////////////////////
- struct AutoFD : public AutoDispose<int>
- {
- AutoFD( int fd_r = -1 ) : AutoDispose<int>( fd_r, [] ( int fd_r ) { if ( fd_r != -1 ) ::close( fd_r ); } ) {}
- };
-
- ///////////////////////////////////////////////////////////////////
- /// \class AutoFILE
- /// \brief \ref AutoDispose\<FILE*> calling \c ::fclose
- /// \see \ref AutoDispose
- /// \ingroup g_RAII
- ///////////////////////////////////////////////////////////////////
- struct AutoFILE : public AutoDispose<FILE*>
- {
- AutoFILE( FILE* file_r = nullptr ) : AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) { if ( file_r ) ::fclose( file_r ); } ) {}
- };
-
- ///////////////////////////////////////////////////////////////////
- /// \class AutoFREE<Tp>
- /// \brief \ref AutoDispose\<Tp*> calling \c ::free
- /// \ingroup g_RAII
- ///////////////////////////////////////////////////////////////////
- template <typename Tp>
- struct AutoFREE : public AutoDispose<Tp*>
- {
- AutoFREE( Tp* ptr_r = nullptr ) : AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) { if ( ptr_r ) ::free( ptr_r ); } ) {}
- AutoFREE( void* ptr_r ) : AutoFREE( static_cast<Tp*>(ptr_r) ) {}
- };
-
- template <>
- struct AutoFREE<void> : public AutoDispose<void*>
- {
- AutoFREE( void* ptr_r = nullptr ) : AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) { if ( ptr_r ) ::free( ptr_r ); } ) {}
- };
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////