13 #ifndef ZYPP_BASE_PTRTYPES_H 14 #define ZYPP_BASE_PTRTYPES_H 19 #include <boost/scoped_ptr.hpp> 20 #include <boost/shared_ptr.hpp> 21 #include <boost/weak_ptr.hpp> 22 #include <boost/intrusive_ptr.hpp> 31 std::string
form(
const char * format, ... )
__attribute__ ((format (printf, 1, 2)));
89 using boost::scoped_ptr;
92 using boost::shared_ptr;
95 using boost::weak_ptr;
98 using boost::intrusive_ptr;
100 template<
typename T,
typename... Args>
103 return intrusive_ptr<T>(
new T( std::forward<Args>(__args)...) );
107 using boost::static_pointer_cast;
109 using boost::const_pointer_cast;
111 using boost::dynamic_pointer_cast;
132 inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<D> & obj )
136 return str << std::string(
"NULL");
140 inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<void> & obj )
144 return str << std::string(
"NULL");
149 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<D> & obj )
153 return str << std::string(
"NULL");
157 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<void> & obj )
158 {
return str << obj; }
162 inline std::ostream & operator<<( std::ostream & str, const zypp::intrusive_ptr<D> & obj )
166 return str << std::string(
"NULL");
170 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::intrusive_ptr<D> & obj )
174 return str << std::string(
"NULL");
193 namespace rw_pointer {
202 {
return !ptr_r || ptr_r.unique(); }
204 {
return !ptr_r || ptr_r.unique(); }
207 {
return ptr_r.use_count(); }
209 {
return ptr_r.use_count(); }
219 {
return !ptr_r || (ptr_r->refCount() <= 1); }
221 {
return !ptr_r || (ptr_r->refCount() <= 1); }
224 {
return ptr_r ? ptr_r->refCount() : 0; }
226 {
return ptr_r ? ptr_r->refCount() : 0; }
241 {
return ptr_r ? 1 : 0; }
243 {
return ptr_r ? 1 : 0; }
290 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
316 {
reset();
return *
this; }
321 void reset(
typename PtrType::element_type * dptr )
325 {
_dptr.swap( rhs._dptr ); }
328 {
_dptr.swap( rhs ); }
331 {
return _dptr.get() !=
nullptr; }
337 {
return _dptr.operator->(); }
339 const D *
get()
const 340 {
return _dptr.get(); }
346 {
return _dptr.operator->(); }
349 {
return _dptr.get(); }
353 {
return DTraits().unique(
_dptr ); }
356 {
return DTraits().use_count(
_dptr ); }
377 template<
class D,
class DPtr>
378 inline std::ostream & operator<<( std::ostream & str, const RW_pointer<D, DPtr> & obj )
381 return str << *obj.get();
382 return str << std::string(
"NULL");
386 template<
class D,
class DPtr>
388 {
return( lhs.
get() == rhs.
get() ); }
390 template<
class D,
class DPtr>
392 {
return( lhs.
get() == rhs.get() ); }
394 template<
class D,
class DPtr>
396 {
return( lhs.get() == rhs.
get() ); }
398 template<
class D,
class DPtr>
400 {
return( lhs.
get() == rhs.get() ); }
402 template<
class D,
class DPtr>
404 {
return( lhs.get() == rhs.
get() ); }
406 template<
class D,
class DPtr>
410 template<
class D,
class DPtr>
412 {
return(
nullptr == rhs.
get() ); }
416 template<
class D,
class DPtr>
418 {
return ! ( lhs == rhs ); }
420 template<
class D,
class DPtr>
422 {
return ! ( lhs == rhs ); }
424 template<
class D,
class DPtr>
426 {
return ! ( lhs == rhs ); }
428 template<
class D,
class DPtr>
430 {
return ! ( lhs == rhs ); }
432 template<
class D,
class DPtr>
434 {
return ! ( lhs == rhs ); }
436 template<
class D,
class DPtr>
440 template<
class D,
class DPtr>
442 {
return(
nullptr != rhs.
get() ); }
453 {
return rhs->
clone(); }
466 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
491 {
reset();
return *
this; }
500 void reset(
typename PtrType::element_type * dptr )
504 {
_dptr.swap( rhs._dptr ); }
507 {
_dptr.swap( rhs ); }
510 {
return _dptr.get() !=
nullptr; }
516 {
return _dptr.operator->(); }
518 const D *
get()
const 519 {
return _dptr.get(); }
532 {
return DTraits().unique(
_dptr ); }
535 {
return DTraits().use_count(
_dptr ); }
564 template<
class D,
class DPtr>
565 inline std::ostream & operator<<( std::ostream & str, const RWCOW_pointer<D, DPtr> & obj )
568 return str << *obj.get();
569 return str << std::string(
"NULL");
573 template<
class D,
class DPtr>
575 {
return( lhs.
get() == rhs.
get() ); }
577 template<
class D,
class DPtr>
579 {
return( lhs.
get() == rhs.get() ); }
581 template<
class D,
class DPtr>
583 {
return( lhs.get() == rhs.
get() ); }
585 template<
class D,
class DPtr>
587 {
return( lhs.
get() == rhs.get() ); }
589 template<
class D,
class DPtr>
591 {
return( lhs.get() == rhs.
get() ); }
593 template<
class D,
class DPtr>
597 template<
class D,
class DPtr>
599 {
return(
nullptr == rhs.
get() ); }
602 template<
class D,
class DPtr>
604 {
return ! ( lhs == rhs ); }
606 template<
class D,
class DPtr>
608 {
return ! ( lhs == rhs ); }
610 template<
class D,
class DPtr>
612 {
return ! ( lhs == rhs ); }
614 template<
class D,
class DPtr>
616 {
return ! ( lhs == rhs ); }
618 template<
class D,
class DPtr>
620 {
return ! ( lhs == rhs ); }
622 template<
class D,
class DPtr>
626 template<
class D,
class DPtr>
628 {
return(
nullptr != rhs.
get() ); }
638 #define DEFINE_PTR_TYPE(NAME) \ 640 extern void intrusive_ptr_add_ref( const NAME * ); \ 641 extern void intrusive_ptr_release( const NAME * ); \ 642 typedef zypp::intrusive_ptr<NAME> NAME##_Ptr; \ 643 typedef zypp::intrusive_ptr<const NAME> NAME##_constPtr; 646 #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::PublicSubkeyData::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.
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::PublicSubkeyData::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
Impl * clone() const
clone for RWCOW_pointer
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::PublicSubkeyData::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::PublicSubkeyData::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)