12#ifndef ZYPP_AUTODISPOSE_H
13#define ZYPP_AUTODISPOSE_H
16#include <boost/call_traits.hpp>
19#include <zypp-core/base/NonCopyable.h>
20#include <zypp-core/base/PtrTypes.h>
21#include <zypp-core/base/Function.h>
22#include <zypp-core/Pathname.h>
97 using param_type =
typename boost::call_traits<Tp>::param_type;
98 using reference =
typename boost::call_traits<Tp>::reference;
99 using const_reference =
typename boost::call_traits<Tp>::const_reference;
101 using result_type =
typename boost::call_traits<Tp>::value_type;
135 {
return _pimpl->_value; }
139 {
return _pimpl->_value; }
143 {
return _pimpl->_value; }
147 {
return &
_pimpl->_value; }
164 {
return _pimpl->_dispose; }
181 template <
typename T>
185 template <
typename T,
typename D>
203 class AutoDispose<void>
233 {
return _pimpl->_dispose; }
278 struct Deferred :
public AutoDispose<void>
280 template <
typename F>
287#define __zypp_defer_concatenate(__lhs, __rhs) \
290#define __zypp_defer_declarator(__id) \
291 zypp::Deferred __zypp_defer_concatenate(__defer, __id) = [&]()
294 __zypp_defer_declarator(__LINE__)
300 inline std::ostream &
operator<<( std::ostream &
str,
const AutoDispose<Tp> & obj )
301 {
return str << obj.value(); }
309 struct AutoFD :
public AutoDispose<int>
311 AutoFD(
int fd_r = -1 ) : AutoDispose<int>( fd_r, [] ( int fd_r ) {
if ( fd_r != -1 ) ::close( fd_r ); } ) {}
320 struct AutoFILE :
public AutoDispose<FILE*>
322 AutoFILE( FILE* file_r =
nullptr ) : AutoDispose<
FILE*>( file_r, [] (
FILE* file_r ) {
if ( file_r ) ::fclose( file_r ); } ) {}
330 template <
typename Tp>
331 struct AutoFREE :
public AutoDispose<Tp*>
333 AutoFREE( Tp* ptr_r =
nullptr ) : AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
334 AutoFREE(
void* ptr_r ) : AutoFREE( static_cast<Tp*>(ptr_r) ) {}
338 struct AutoFREE<void> :
public AutoDispose<void*>
340 AutoFREE(
void* ptr_r =
nullptr ) : AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) {
if ( ptr_r ) ::free( ptr_r ); } ) {}
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
RepoManager implementation.
AutoDispose()
Default Ctor using default constructed value and no dispose function.
value_type * operator->() const
Pointer to the Tp object (asserted to be != NULL).
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
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.
std::conditional_t< std::is_pointer_v< Tp >||std::is_integral_v< Tp >, Tp const, reference > dispose_param_type
reference operator*() const
Reference to the Tp object.
typename boost::call_traits< Tp >::const_reference const_reference
void reset()
Reset to default Ctor values.
shared_ptr< Impl > _pimpl
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.
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
typename boost::call_traits< Tp >::param_type param_type
typename boost::call_traits< Tp >::reference reference
typename boost::call_traits< Tp >::value_type result_type
typename conditional< B, T, F >::type conditional_t
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 > OnScopeExit
constexpr std::string_view FILE("file")