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)));
84 void operator()(
const void *
const )
const
89 using boost::scoped_ptr;
92 using boost::shared_ptr;
95 using boost::weak_ptr;
98 using boost::intrusive_ptr;
101 using boost::static_pointer_cast;
103 using boost::const_pointer_cast;
105 using boost::dynamic_pointer_cast;
126 inline std::ostream &
operator<<( std::ostream &
str,
const zypp::shared_ptr<D> & obj )
130 return str << std::string(
"NULL");
134 inline std::ostream &
operator<<( std::ostream &
str,
const zypp::shared_ptr<void> & obj )
138 return str << std::string(
"NULL");
143 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<D> & obj )
147 return str << std::string(
"NULL");
151 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::shared_ptr<void> & obj )
152 {
return str << obj; }
156 inline std::ostream &
operator<<( std::ostream &
str,
const zypp::intrusive_ptr<D> & obj )
160 return str << std::string(
"NULL");
164 inline std::ostream &
dumpOn( std::ostream &
str,
const zypp::intrusive_ptr<D> & obj )
168 return str << std::string(
"NULL");
187 namespace rw_pointer {
196 {
return !ptr_r || ptr_r.unique(); }
198 {
return !ptr_r || ptr_r.unique(); }
201 {
return ptr_r.use_count(); }
203 {
return ptr_r.use_count(); }
213 {
return !ptr_r || (ptr_r->refCount() <= 1); }
215 {
return !ptr_r || (ptr_r->refCount() <= 1); }
218 {
return ptr_r ? ptr_r->refCount() : 0; }
220 {
return ptr_r ? ptr_r->refCount() : 0; }
235 {
return ptr_r ? 1 : 0; }
237 {
return ptr_r ? 1 : 0; }
284 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
287 typedef typename DTraits::PtrType
PtrType;
297 RW_pointer(
typename PtrType::element_type * dptr )
307 {
reset();
return *
this; }
312 void reset(
typename PtrType::element_type * dptr )
316 {
_dptr.swap( rhs._dptr ); }
319 {
_dptr.swap( rhs ); }
321 explicit operator bool()
const
322 {
return _dptr.get() !=
nullptr; }
328 {
return _dptr.operator->(); }
330 const D *
get()
const
331 {
return _dptr.get(); }
337 {
return _dptr.operator->(); }
340 {
return _dptr.get(); }
344 {
return DTraits().unique(
_dptr ); }
347 {
return DTraits().use_count(
_dptr ); }
368 template<
class D,
class DPtr>
369 inline std::ostream &
operator<<( std::ostream &
str,
const RW_pointer<D, DPtr> & obj )
372 return str << *obj.get();
373 return str << std::string(
"NULL");
377 template<
class D,
class DPtr>
378 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const RW_pointer<D, DPtr> & rhs )
379 {
return( lhs.get() == rhs.get() ); }
381 template<
class D,
class DPtr>
382 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
383 {
return( lhs.get() == rhs.get() ); }
385 template<
class D,
class DPtr>
386 inline bool operator==(
const typename DPtr::PtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
387 {
return( lhs.get() == rhs.get() ); }
389 template<
class D,
class DPtr>
390 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
391 {
return( lhs.get() == rhs.get() ); }
393 template<
class D,
class DPtr>
394 inline bool operator==(
const typename DPtr::constPtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
395 {
return( lhs.get() == rhs.get() ); }
397 template<
class D,
class DPtr>
398 inline bool operator==(
const RW_pointer<D, DPtr> & lhs, std::nullptr_t )
399 {
return( lhs.get() ==
nullptr ); }
401 template<
class D,
class DPtr>
402 inline bool operator==( std::nullptr_t,
const RW_pointer<D, DPtr> & rhs )
403 {
return(
nullptr == rhs.get() ); }
407 template<
class D,
class DPtr>
408 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const RW_pointer<D, DPtr> & rhs )
409 {
return ! ( lhs == rhs ); }
411 template<
class D,
class DPtr>
412 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
413 {
return ! ( lhs == rhs ); }
415 template<
class D,
class DPtr>
416 inline bool operator!=(
const typename DPtr::PtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
417 {
return ! ( lhs == rhs ); }
419 template<
class D,
class DPtr>
420 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
421 {
return ! ( lhs == rhs ); }
423 template<
class D,
class DPtr>
424 inline bool operator!=(
const typename DPtr::constPtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
425 {
return ! ( lhs == rhs ); }
427 template<
class D,
class DPtr>
428 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs, std::nullptr_t )
429 {
return( lhs.get() !=
nullptr ); }
431 template<
class D,
class DPtr>
432 inline bool operator!=( std::nullptr_t,
const RW_pointer<D, DPtr> & rhs )
433 {
return(
nullptr != rhs.get() ); }
444 {
return rhs->clone(); }
457 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
460 typedef typename DTraits::PtrType
PtrType;
480 {
reset();
return *
this; }
485 void reset(
typename PtrType::element_type * dptr )
489 {
_dptr.swap( rhs._dptr ); }
492 {
_dptr.swap( rhs ); }
494 explicit operator bool()
const
495 {
return _dptr.get() !=
nullptr; }
501 {
return _dptr.operator->(); }
503 const D *
get()
const
504 {
return _dptr.get(); }
517 {
return DTraits().unique(
_dptr ); }
520 {
return DTraits().use_count(
_dptr ); }
549 template<
class D,
class DPtr>
550 inline std::ostream &
operator<<( std::ostream &
str,
const RWCOW_pointer<D, DPtr> & obj )
553 return str << *obj.get();
554 return str << std::string(
"NULL");
558 template<
class D,
class DPtr>
559 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
560 {
return( lhs.get() == rhs.get() ); }
562 template<
class D,
class DPtr>
563 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
564 {
return( lhs.get() == rhs.get() ); }
566 template<
class D,
class DPtr>
567 inline bool operator==(
const typename DPtr::PtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
568 {
return( lhs.get() == rhs.get() ); }
570 template<
class D,
class DPtr>
571 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
572 {
return( lhs.get() == rhs.get() ); }
574 template<
class D,
class DPtr>
575 inline bool operator==(
const typename DPtr::constPtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
576 {
return( lhs.get() == rhs.get() ); }
578 template<
class D,
class DPtr>
579 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs, std::nullptr_t )
580 {
return( lhs.get() ==
nullptr ); }
582 template<
class D,
class DPtr>
583 inline bool operator==( std::nullptr_t,
const RWCOW_pointer<D, DPtr> & rhs )
584 {
return(
nullptr == rhs.get() ); }
587 template<
class D,
class DPtr>
588 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
589 {
return ! ( lhs == rhs ); }
591 template<
class D,
class DPtr>
592 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
593 {
return ! ( lhs == rhs ); }
595 template<
class D,
class DPtr>
596 inline bool operator!=(
const typename DPtr::PtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
597 {
return ! ( lhs == rhs ); }
599 template<
class D,
class DPtr>
600 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
601 {
return ! ( lhs == rhs ); }
603 template<
class D,
class DPtr>
604 inline bool operator!=(
const typename DPtr::constPtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
605 {
return ! ( lhs == rhs ); }
607 template<
class D,
class DPtr>
608 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs, std::nullptr_t )
609 {
return( lhs.get() !=
nullptr ); }
611 template<
class D,
class DPtr>
612 inline bool operator!=( std::nullptr_t,
const RWCOW_pointer<D, DPtr> & rhs )
613 {
return(
nullptr != rhs.get() ); }
623#define DEFINE_PTR_TYPE(NAME) \
625extern void intrusive_ptr_add_ref( const NAME * ); \
626extern void intrusive_ptr_release( const NAME * ); \
627typedef zypp::intrusive_ptr<NAME> NAME##_Ptr; \
628typedef zypp::intrusive_ptr<const NAME> NAME##_constPtr;
unordered_set< D > * rwcowClone(const std::unordered_set< D > *rhs)
clone function for RW_pointer
String related utilities and Regular expression matching.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
RWCOW_pointer & operator=(std::nullptr_t)
const D & operator*() const
const D * operator->() const
constPtrType getPtr() const
D * rwcowClone(const D *rhs)
Clone the underlying object.
void swap(RWCOW_pointer &rhs)
DTraits::constPtrType constPtrType
DTraits::constPtrType constPtrType
const D * operator->() const
void swap(RW_pointer &rhs)
constPtrType getPtr() const
const D & operator*() const
RW_pointer & operator=(std::nullptr_t)
intrusive_ptr< D > PtrType
long use_count(const constPtrType &ptr_r) const
Return number of references.
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
intrusive_ptr< const D > constPtrType
scoped_ptr< const D > constPtrType
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
long use_count(const constPtrType &ptr_r) const
Return number of references.
shared_ptr< const D > constPtrType
long use_count(const constPtrType &ptr_r) const
Return number of references.
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.