13 #ifndef ZYPP_BASE_PTRTYPES_H
14 #define ZYPP_BASE_PTRTYPES_H
18 #include <boost/scoped_ptr.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/weak_ptr.hpp>
21 #include <boost/intrusive_ptr.hpp>
82 using boost::scoped_ptr;
85 using boost::shared_ptr;
88 using boost::weak_ptr;
91 using boost::intrusive_ptr;
94 using boost::static_pointer_cast;
96 using boost::const_pointer_cast;
98 using boost::dynamic_pointer_cast;
119 inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<_D> & obj )
123 return str << std::string(
"NULL");
127 inline std::ostream &
dumpOn( std::ostream & str,
const zypp::shared_ptr<_D> & obj )
130 return dumpOn( str, *obj );
131 return str << std::string(
"NULL");
136 inline std::ostream & operator<<( std::ostream & str, const zypp::intrusive_ptr<_D> & obj )
140 return str << std::string(
"NULL");
144 inline std::ostream &
dumpOn( std::ostream & str,
const zypp::intrusive_ptr<_D> & obj )
147 return dumpOn( str, *obj );
148 return str << std::string(
"NULL");
167 namespace rw_pointer {
176 {
return !ptr_r || ptr_r.unique(); }
178 {
return !ptr_r || ptr_r.unique(); }
181 {
return ptr_r.use_count(); }
183 {
return ptr_r.use_count(); }
189 typedef intrusive_ptr<_D>
_Ptr;
193 {
return !ptr_r || (ptr_r->refCount() <= 1); }
195 {
return !ptr_r || (ptr_r->refCount() <= 1); }
198 {
return ptr_r ? ptr_r->refCount() : 0; }
200 {
return ptr_r ? ptr_r->refCount() : 0; }
215 {
return ptr_r ? 1 : 0; }
217 {
return ptr_r ? 1 : 0; }
264 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
267 typedef typename _Traits::_Ptr
_Ptr;
287 {
reset();
return *
this; }
292 void reset(
typename _Ptr::element_type * dptr )
299 {
_dptr.swap( rhs ); }
301 explicit operator bool()
const
302 {
return _dptr.get() !=
nullptr; }
308 {
return _dptr.operator->(); }
310 const _D *
get()
const
311 {
return _dptr.get(); }
317 {
return _dptr.operator->(); }
320 {
return _dptr.get(); }
324 {
return _Traits().unique(
_dptr ); }
327 {
return _Traits().use_count(
_dptr ); }
348 template<
class _D,
class _Ptr>
349 inline std::ostream & operator<<( std::ostream & str, const RW_pointer<_D, _Ptr> & obj )
352 return str << *obj.get();
353 return str << std::string(
"NULL");
357 template<
class _D,
class _Ptr>
359 {
return( lhs.
get() == rhs.
get() ); }
361 template<
class _D,
class _Ptr>
363 {
return( lhs.
get() == rhs.get() ); }
365 template<
class _D,
class _Ptr>
367 {
return( lhs.get() == rhs.
get() ); }
369 template<
class _D,
class _Ptr>
371 {
return( lhs.
get() == rhs.get() ); }
373 template<
class _D,
class _Ptr>
375 {
return( lhs.get() == rhs.
get() ); }
377 template<
class _D,
class _Ptr>
381 template<
class _D,
class _Ptr>
383 {
return(
nullptr == rhs.
get() ); }
387 template<
class _D,
class _Ptr>
389 {
return ! ( lhs == rhs ); }
391 template<
class _D,
class _Ptr>
393 {
return ! ( lhs == rhs ); }
395 template<
class _D,
class _Ptr>
397 {
return ! ( lhs == rhs ); }
399 template<
class _D,
class _Ptr>
401 {
return ! ( lhs == rhs ); }
403 template<
class _D,
class _Ptr>
405 {
return ! ( lhs == rhs ); }
407 template<
class _D,
class _Ptr>
411 template<
class _D,
class _Ptr>
413 {
return(
nullptr != rhs.
get() ); }
424 {
return rhs->clone(); }
437 template<
class _D,
class _Traits = rw_po
inter::Shared<_D> >
440 typedef typename _Traits::_Ptr
_Ptr;
460 {
reset();
return *
this; }
465 void reset(
typename _Ptr::element_type * dptr )
472 {
_dptr.swap( rhs ); }
474 explicit operator bool()
const
475 {
return _dptr.get() !=
nullptr; }
481 {
return _dptr.operator->(); }
483 const _D *
get()
const
484 {
return _dptr.get(); }
497 {
return _Traits().unique(
_dptr ); }
500 {
return _Traits().use_count(
_dptr ); }
529 template<
class _D,
class _Ptr>
530 inline std::ostream & operator<<( std::ostream & str, const RWCOW_pointer<_D, _Ptr> & obj )
533 return str << *obj.get();
534 return str << std::string(
"NULL");
538 template<
class _D,
class _Ptr>
540 {
return( lhs.
get() == rhs.
get() ); }
542 template<
class _D,
class _Ptr>
544 {
return( lhs.
get() == rhs.get() ); }
546 template<
class _D,
class _Ptr>
548 {
return( lhs.get() == rhs.
get() ); }
550 template<
class _D,
class _Ptr>
552 {
return( lhs.
get() == rhs.get() ); }
554 template<
class _D,
class _Ptr>
556 {
return( lhs.get() == rhs.
get() ); }
558 template<
class _D,
class _Ptr>
562 template<
class _D,
class _Ptr>
564 {
return(
nullptr == rhs.
get() ); }
567 template<
class _D,
class _Ptr>
569 {
return ! ( lhs == rhs ); }
571 template<
class _D,
class _Ptr>
573 {
return ! ( lhs == rhs ); }
575 template<
class _D,
class _Ptr>
577 {
return ! ( lhs == rhs ); }
579 template<
class _D,
class _Ptr>
581 {
return ! ( lhs == rhs ); }
583 template<
class _D,
class _Ptr>
585 {
return ! ( lhs == rhs ); }
587 template<
class _D,
class _Ptr>
591 template<
class _D,
class _Ptr>
593 {
return(
nullptr != rhs.
get() ); }
603 #define DEFINE_PTR_TYPE(NAME) \
605 extern void intrusive_ptr_add_ref( const NAME * ); \
606 extern void intrusive_ptr_release( const NAME * ); \
607 typedef zypp::intrusive_ptr<NAME> NAME##_Ptr; \
608 typedef zypp::intrusive_ptr<const NAME> NAME##_constPtr;
611 #endif // ZYPP_BASE_PTRTYPES_H
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const RW_pointer< _D, _Ptr > &rhs)
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const RW_pointer< _D, _Ptr > &rhs)
bool unique(const _Ptr &ptr_r)
RWCOW_pointer & operator=(std::nullptr_t)
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
bool operator!=(const typename _Ptr::_constPtr &lhs, const RW_pointer< _D, _Ptr > &rhs)
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator==(const typename _Ptr::_constPtr &lhs, const RW_pointer< _D, _Ptr > &rhs)
long use_count(const _constPtr &ptr_r) const
Return number of references.
bool operator!=(const typename _Ptr::_Ptr &lhs, const RW_pointer< _D, _Ptr > &rhs)
const _D & operator*() const
RW_pointer(std::nullptr_t)
bool unique(const _constPtr &ptr_r)
Check whether pointer is not shared.
bool operator==(const typename _Ptr::_Ptr &lhs, const RW_pointer< _D, _Ptr > &rhs)
bool unique(const _constPtr &ptr_r)
Check whether pointer is not shared.
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, std::nullptr_t)
void reset(typename _Ptr::element_type *dptr)
void reset(typename _Ptr::element_type *dptr)
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
_Traits::_constPtr _constPtr
RW_pointer & operator=(std::nullptr_t)
RW_pointer(typename _Ptr::element_type *dptr)
bool operator==(std::nullptr_t, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
bool unique(const _Ptr &ptr_r)
bool unique(const _constPtr &ptr_r)
Check whether pointer is not shared.
long use_count(const _Ptr &ptr_r) const
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_constPtr &rhs)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool operator==(const typename _Ptr::_Ptr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator!=(std::nullptr_t, const RW_pointer< _D, _Ptr > &rhs)
long use_count(const _constPtr &ptr_r) const
Return number of references.
shared_ptr< const _D > _constPtr
const _D & operator*() const
RWCOW_pointer(std::nullptr_t)
bool operator==(const typename _Ptr::_constPtr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator!=(const typename _Ptr::_constPtr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
shared_ptr custom deleter doing nothing.
Wrapper for const correct access via Smart pointer types.
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, std::nullptr_t)
void swap(RW_pointer &rhs)
bool operator!=(const RWCOW_pointer< _D, _Ptr > &lhs, std::nullptr_t)
long use_count(const _Ptr &ptr_r) const
void swap(RWCOW_pointer &rhs)
scoped_ptr< const _D > _constPtr
_Traits::_constPtr _constPtr
const _D * operator->() const
bool operator!=(const typename _Ptr::_Ptr &lhs, const RWCOW_pointer< _D, _Ptr > &rhs)
long use_count(const _Ptr &ptr_r) const
const _D * operator->() const
intrusive_ptr< const _D > _constPtr
bool operator!=(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
bool operator==(const RW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
bool unique(const _Ptr &ptr_r)
long use_count(const _constPtr &ptr_r) const
Return number of references.
bool operator==(std::nullptr_t, const RW_pointer< _D, _Ptr > &rhs)
bool operator!=(std::nullptr_t, const RWCOW_pointer< _D, _Ptr > &rhs)
bool operator==(const RW_pointer< _D, _Ptr > &lhs, std::nullptr_t)
_D * rwcowClone(const _D *rhs)
bool operator==(const RWCOW_pointer< _D, _Ptr > &lhs, const typename _Ptr::_Ptr &rhs)
RW_pointer supporting 'copy on write' functionality.
RWCOW_pointer(typename _Ptr::element_type *dptr)
void operator()(const void *const ) const