13 #ifndef ZYPP_BASE_PTRTYPES_H 14 #define ZYPP_BASE_PTRTYPES_H 20 #include <boost/scoped_ptr.hpp> 21 #include <boost/shared_ptr.hpp> 22 #include <boost/weak_ptr.hpp> 23 #include <boost/intrusive_ptr.hpp> 32 std::string
form(
const char * format, ... )
__attribute__ ((format (printf, 1, 2)));
90 using boost::scoped_ptr;
93 using boost::shared_ptr;
96 using boost::weak_ptr;
99 using boost::intrusive_ptr;
101 template<
typename T,
typename... Args>
104 return intrusive_ptr<T>(
new T( std::forward<Args>(__args)...) );
108 using boost::static_pointer_cast;
110 using boost::const_pointer_cast;
112 using boost::dynamic_pointer_cast;
133 inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<D> & obj )
137 return str << std::string(
"NULL");
141 inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<void> & obj )
145 return str << std::string(
"NULL");
150 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<D> & obj )
154 return str << std::string(
"NULL");
158 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<void> & obj )
159 {
return str << obj; }
163 inline std::ostream & operator<<( std::ostream & str, const zypp::intrusive_ptr<D> & obj )
167 return str << std::string(
"NULL");
171 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::intrusive_ptr<D> & obj )
175 return str << std::string(
"NULL");
194 namespace rw_pointer {
203 {
return !ptr_r || ptr_r.unique(); }
205 {
return !ptr_r || ptr_r.unique(); }
208 {
return ptr_r.use_count(); }
210 {
return ptr_r.use_count(); }
220 {
return !ptr_r || (ptr_r->refCount() <= 1); }
222 {
return !ptr_r || (ptr_r->refCount() <= 1); }
225 {
return ptr_r ? ptr_r->refCount() : 0; }
227 {
return ptr_r ? ptr_r->refCount() : 0; }
242 {
return ptr_r ? 1 : 0; }
244 {
return ptr_r ? 1 : 0; }
291 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
317 {
reset();
return *
this; }
322 void reset(
typename PtrType::element_type * dptr )
326 {
_dptr.swap( rhs._dptr ); }
329 {
_dptr.swap( rhs ); }
332 {
return _dptr.get() !=
nullptr; }
338 {
return _dptr.operator->(); }
340 const D *
get()
const 341 {
return _dptr.get(); }
347 {
return _dptr.operator->(); }
350 {
return _dptr.get(); }
354 {
return DTraits().unique(
_dptr ); }
357 {
return DTraits().use_count(
_dptr ); }
378 template<
class D,
class DPtr>
379 inline std::ostream & operator<<( std::ostream & str, const RW_pointer<D, DPtr> & obj )
382 return str << *obj.get();
383 return str << std::string(
"NULL");
387 template<
class D,
class DPtr>
389 {
return( lhs.
get() == rhs.
get() ); }
391 template<
class D,
class DPtr>
393 {
return( lhs.
get() == rhs.get() ); }
395 template<
class D,
class DPtr>
397 {
return( lhs.get() == rhs.
get() ); }
399 template<
class D,
class DPtr>
401 {
return( lhs.
get() == rhs.get() ); }
403 template<
class D,
class DPtr>
405 {
return( lhs.get() == rhs.
get() ); }
407 template<
class D,
class DPtr>
409 {
return( lhs.
get() == nullptr ); }
411 template<
class D,
class DPtr>
413 {
return(
nullptr == rhs.
get() ); }
417 template<
class D,
class DPtr>
419 {
return ! ( lhs == rhs ); }
421 template<
class D,
class DPtr>
423 {
return ! ( lhs == rhs ); }
425 template<
class D,
class DPtr>
427 {
return ! ( lhs == rhs ); }
429 template<
class D,
class DPtr>
431 {
return ! ( lhs == rhs ); }
433 template<
class D,
class DPtr>
435 {
return ! ( lhs == rhs ); }
437 template<
class D,
class DPtr>
439 {
return( lhs.
get() != nullptr ); }
441 template<
class D,
class DPtr>
443 {
return(
nullptr != rhs.
get() ); }
454 {
return rhs->
clone(); }
467 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
492 {
reset();
return *
this; }
501 void reset(
typename PtrType::element_type * dptr )
505 {
_dptr.swap( rhs._dptr ); }
508 {
_dptr.swap( rhs ); }
511 {
return _dptr.get() !=
nullptr; }
517 {
return _dptr.operator->(); }
519 const D *
get()
const 520 {
return _dptr.get(); }
533 {
return DTraits().unique(
_dptr ); }
536 {
return DTraits().use_count(
_dptr ); }
565 template<
class D,
class DPtr>
566 inline std::ostream & operator<<( std::ostream & str, const RWCOW_pointer<D, DPtr> & obj )
569 return str << *obj.get();
570 return str << std::string(
"NULL");
574 template<
class D,
class DPtr>
576 {
return( lhs.
get() == rhs.
get() ); }
578 template<
class D,
class DPtr>
580 {
return( lhs.
get() == rhs.get() ); }
582 template<
class D,
class DPtr>
584 {
return( lhs.get() == rhs.
get() ); }
586 template<
class D,
class DPtr>
588 {
return( lhs.
get() == rhs.get() ); }
590 template<
class D,
class DPtr>
592 {
return( lhs.get() == rhs.
get() ); }
594 template<
class D,
class DPtr>
596 {
return( lhs.
get() == nullptr ); }
598 template<
class D,
class DPtr>
600 {
return(
nullptr == rhs.
get() ); }
603 template<
class D,
class DPtr>
605 {
return ! ( lhs == rhs ); }
607 template<
class D,
class DPtr>
609 {
return ! ( lhs == rhs ); }
611 template<
class D,
class DPtr>
613 {
return ! ( lhs == rhs ); }
615 template<
class D,
class DPtr>
617 {
return ! ( lhs == rhs ); }
619 template<
class D,
class DPtr>
621 {
return ! ( lhs == rhs ); }
623 template<
class D,
class DPtr>
625 {
return( lhs.
get() != nullptr ); }
627 template<
class D,
class DPtr>
629 {
return(
nullptr != rhs.
get() ); }
639 #define DEFINE_PTR_TYPE(NAME) \ 641 extern void intrusive_ptr_add_ref( const NAME * ) ZYPP_API; \ 642 extern void intrusive_ptr_release( const NAME * ) ZYPP_API; \ 643 typedef zypp::intrusive_ptr<NAME> NAME##_Ptr; \ 644 typedef zypp::intrusive_ptr<const NAME> NAME##_constPtr; 647 #endif // ZYPP_BASE_PTRTYPES_H void swap(RWCOW_pointer &rhs) noexcept
void swap(PtrType &rhs) noexcept
long use_count(const constPtrType &ptr_r) const
Return number of references.
RWCOW_pointer(PtrType dptr)
bool operator!=(const RWCOW_pointer< D, DPtr > &lhs, std::nullptr_t)
RWCOW_pointer & operator=(std::nullptr_t)
bool operator==(const typename DPtr::PtrType &lhs, const RW_pointer< D, DPtr > &rhs)
void swap(RW_pointer &rhs) noexcept
bool operator!=(const RW_pointer< D, DPtr > &lhs, const typename DPtr::constPtrType &rhs)
shared_ptr< zypp::PurgeKernels::Impl > PtrType
constPtrType getPtr() const
bool operator!=(const typename DPtr::PtrType &lhs, const RWCOW_pointer< D, DPtr > &rhs)
scoped_ptr< const zypp::ZConfig::Impl > constPtrType
String related utilities and Regular expression matching.
Impl * clone() const
clone for RWCOW_pointer
RW_pointer & operator=(const RW_pointer &)=default
bool operator==(const RWCOW_pointer< D, DPtr > &lhs, const typename DPtr::constPtrType &rhs)
bool operator==(std::nullptr_t, const RWCOW_pointer< D, DPtr > &rhs)
bool operator!=(const RW_pointer< D, DPtr > &lhs, const typename DPtr::PtrType &rhs)
void reset(typename PtrType::element_type *dptr)
long use_count(const constPtrType &ptr_r) const
Return number of references.
bool unique(const PtrType &ptr_r)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool operator==(const RW_pointer< D, DPtr > &lhs, std::nullptr_t)
bool operator!=(const typename DPtr::PtrType &lhs, const RW_pointer< D, DPtr > &rhs)
const D * operator->() const
bool operator!=(const RW_pointer< D, DPtr > &lhs, std::nullptr_t)
bool operator==(const typename DPtr::constPtrType &lhs, const RWCOW_pointer< D, DPtr > &rhs)
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
bool unique(const PtrType &ptr_r)
intrusive_ptr< const zypp::target::TargetImpl > constPtrType
RWCOW_pointer(typename PtrType::element_type *dptr)
typename rw_pointer::Shared< zypp::keyring::VerifyFileContext::Impl > ::PtrType PtrType
bool operator==(const RWCOW_pointer< D, DPtr > &lhs, const typename DPtr::PtrType &rhs)
bool operator!=(std::nullptr_t, const RW_pointer< D, DPtr > &rhs)
bool operator!=(const RW_pointer< D, DPtr > &lhs, const RW_pointer< D, DPtr > &rhs)
long use_count(const PtrType &ptr_r) const
RW_pointer(std::nullptr_t)
intrusive_ptr< zypp::target::TargetImpl > PtrType
bool operator==(const RW_pointer< D, DPtr > &lhs, const RW_pointer< D, DPtr > &rhs)
bool operator!=(const RWCOW_pointer< D, DPtr > &lhs, const RWCOW_pointer< D, DPtr > &rhs)
const D & operator*() const
D * rwcowClone(const D *rhs)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool operator==(const RW_pointer< D, DPtr > &lhs, const typename DPtr::constPtrType &rhs)
long use_count(const constPtrType &ptr_r) const
Return number of references.
bool operator!=(const RWCOW_pointer< D, DPtr > &lhs, const typename DPtr::constPtrType &rhs)
long use_count(const PtrType &ptr_r) const
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
RW_pointer(typename PtrType::element_type *dptr)
typename rw_pointer::Shared< zypp::PurgeKernels::Impl > ::constPtrType constPtrType
void reset(typename PtrType::element_type *dptr)
shared_ptr custom deleter doing nothing.
const D & operator*() const
const D * operator->() const
intrusive_ptr< T > make_intrusive(Args &&... __args)
bool operator==(const typename DPtr::constPtrType &lhs, const RW_pointer< D, DPtr > &rhs)
bool operator==(const RWCOW_pointer< D, DPtr > &lhs, const RWCOW_pointer< D, DPtr > &rhs)
typename rw_pointer::Shared< zypp::PurgeKernels::Impl > ::PtrType PtrType
Wrapper for const correct access via Smart pointer types.
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
RWCOW_pointer(std::nullptr_t)
bool operator==(const RWCOW_pointer< D, DPtr > &lhs, std::nullptr_t)
void swap(PtrType &rhs) noexcept
bool operator!=(const typename DPtr::constPtrType &lhs, const RWCOW_pointer< D, DPtr > &rhs)
shared_ptr< const zypp::PurgeKernels::Impl > constPtrType
bool unique(const PtrType &ptr_r)
long use_count(const PtrType &ptr_r) const
Easy-to use interface to the ZYPP dependency resolver.
scoped_ptr< zypp::ZConfig::Impl > PtrType
typename rw_pointer::Shared< zypp::keyring::VerifyFileContext::Impl > ::constPtrType constPtrType
bool operator==(const RW_pointer< D, DPtr > &lhs, const typename DPtr::PtrType &rhs)
void operator()(const void *const) const
constPtrType getPtr() const
bool operator!=(std::nullptr_t, const RWCOW_pointer< D, DPtr > &rhs)
bool operator!=(const typename DPtr::constPtrType &lhs, const RW_pointer< D, DPtr > &rhs)
bool operator!=(const RWCOW_pointer< D, DPtr > &lhs, const typename DPtr::PtrType &rhs)
RW_pointer supporting 'copy on write' functionality.
RW_pointer & operator=(std::nullptr_t)
bool operator==(const typename DPtr::PtrType &lhs, const RWCOW_pointer< D, DPtr > &rhs)
bool operator==(std::nullptr_t, const RW_pointer< D, DPtr > &rhs)