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;
100 template<
typename T,
typename... Args>
107 using boost::static_pointer_cast;
109 using boost::const_pointer_cast;
111 using boost::dynamic_pointer_cast;
136 return str << std::string(
"NULL");
144 return str << std::string(
"NULL");
153 return str << std::string(
"NULL");
158 {
return str << obj; }
166 return str << std::string(
"NULL");
174 return str << std::string(
"NULL");
193 namespace rw_pointer {
201 bool unique(
const constPtrType & ptr_r )
202 {
return !ptr_r || ptr_r.unique(); }
203 bool unique(
const PtrType & ptr_r )
204 {
return !ptr_r || ptr_r.unique(); }
206 long use_count(
const constPtrType & ptr_r )
const
207 {
return ptr_r.use_count(); }
208 long use_count(
const PtrType & ptr_r )
const
209 {
return ptr_r.use_count(); }
218 bool unique(
const constPtrType & ptr_r )
219 {
return !ptr_r || (ptr_r->refCount() <= 1); }
220 bool unique(
const PtrType & ptr_r )
221 {
return !ptr_r || (ptr_r->refCount() <= 1); }
223 long use_count(
const constPtrType & ptr_r )
const
224 {
return ptr_r ? ptr_r->refCount() : 0; }
225 long use_count(
const PtrType & ptr_r )
const
226 {
return ptr_r ? ptr_r->refCount() : 0; }
235 bool unique(
const constPtrType & ptr_r )
237 bool unique(
const PtrType & ptr_r )
240 long use_count(
const constPtrType & ptr_r )
const
241 {
return ptr_r ? 1 : 0; }
242 long use_count(
const PtrType & ptr_r )
const
243 {
return ptr_r ? 1 : 0; }
290 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
293 using PtrType =
typename DTraits::PtrType;
294 using constPtrType =
typename DTraits::constPtrType;
306 RW_pointer(
typename PtrType::element_type * dptr )
316 {
reset();
return *
this; }
321 void reset(
typename PtrType::element_type * dptr )
327 void swap( PtrType & rhs )
noexcept
330 explicit operator bool()
const
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 ); }
358 constPtrType
getPtr()
const
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>
387 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const RW_pointer<D, DPtr> & rhs )
388 {
return( lhs.get() == rhs.get() ); }
390 template<
class D,
class DPtr>
391 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
392 {
return( lhs.get() == rhs.get() ); }
394 template<
class D,
class DPtr>
395 inline bool operator==(
const typename DPtr::PtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
396 {
return( lhs.get() == rhs.get() ); }
398 template<
class D,
class DPtr>
399 inline bool operator==(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
400 {
return( lhs.get() == rhs.get() ); }
402 template<
class D,
class DPtr>
403 inline bool operator==(
const typename DPtr::constPtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
404 {
return( lhs.get() == rhs.get() ); }
406 template<
class D,
class DPtr>
407 inline bool operator==(
const RW_pointer<D, DPtr> & lhs, std::nullptr_t )
408 {
return( lhs.get() ==
nullptr ); }
410 template<
class D,
class DPtr>
411 inline bool operator==( std::nullptr_t,
const RW_pointer<D, DPtr> & rhs )
412 {
return(
nullptr == rhs.get() ); }
416 template<
class D,
class DPtr>
417 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const RW_pointer<D, DPtr> & rhs )
418 {
return ! ( lhs == rhs ); }
420 template<
class D,
class DPtr>
421 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
422 {
return ! ( lhs == rhs ); }
424 template<
class D,
class DPtr>
425 inline bool operator!=(
const typename DPtr::PtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
426 {
return ! ( lhs == rhs ); }
428 template<
class D,
class DPtr>
429 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
430 {
return ! ( lhs == rhs ); }
432 template<
class D,
class DPtr>
433 inline bool operator!=(
const typename DPtr::constPtrType & lhs,
const RW_pointer<D, DPtr> & rhs )
434 {
return ! ( lhs == rhs ); }
436 template<
class D,
class DPtr>
437 inline bool operator!=(
const RW_pointer<D, DPtr> & lhs, std::nullptr_t )
438 {
return( lhs.get() !=
nullptr ); }
440 template<
class D,
class DPtr>
441 inline bool operator!=( std::nullptr_t,
const RW_pointer<D, DPtr> & rhs )
442 {
return(
nullptr != rhs.get() ); }
453 {
return rhs->clone(); }
466 template<
class D,
class DTraits = rw_po
inter::Shared<D> >
469 using PtrType =
typename DTraits::PtrType;
470 using constPtrType =
typename DTraits::constPtrType;
491 {
reset();
return *
this; }
500 void reset(
typename PtrType::element_type * dptr )
506 void swap( PtrType & rhs )
noexcept
509 explicit operator bool()
const
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 ); }
537 constPtrType
getPtr()
const
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>
574 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
575 {
return( lhs.get() == rhs.get() ); }
577 template<
class D,
class DPtr>
578 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
579 {
return( lhs.get() == rhs.get() ); }
581 template<
class D,
class DPtr>
582 inline bool operator==(
const typename DPtr::PtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
583 {
return( lhs.get() == rhs.get() ); }
585 template<
class D,
class DPtr>
586 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
587 {
return( lhs.get() == rhs.get() ); }
589 template<
class D,
class DPtr>
590 inline bool operator==(
const typename DPtr::constPtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
591 {
return( lhs.get() == rhs.get() ); }
593 template<
class D,
class DPtr>
594 inline bool operator==(
const RWCOW_pointer<D, DPtr> & lhs, std::nullptr_t )
595 {
return( lhs.get() ==
nullptr ); }
597 template<
class D,
class DPtr>
598 inline bool operator==( std::nullptr_t,
const RWCOW_pointer<D, DPtr> & rhs )
599 {
return(
nullptr == rhs.get() ); }
602 template<
class D,
class DPtr>
603 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
604 {
return ! ( lhs == rhs ); }
606 template<
class D,
class DPtr>
607 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::PtrType & rhs )
608 {
return ! ( lhs == rhs ); }
610 template<
class D,
class DPtr>
611 inline bool operator!=(
const typename DPtr::PtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
612 {
return ! ( lhs == rhs ); }
614 template<
class D,
class DPtr>
615 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs,
const typename DPtr::constPtrType & rhs )
616 {
return ! ( lhs == rhs ); }
618 template<
class D,
class DPtr>
619 inline bool operator!=(
const typename DPtr::constPtrType & lhs,
const RWCOW_pointer<D, DPtr> & rhs )
620 {
return ! ( lhs == rhs ); }
622 template<
class D,
class DPtr>
623 inline bool operator!=(
const RWCOW_pointer<D, DPtr> & lhs, std::nullptr_t )
624 {
return( lhs.get() !=
nullptr ); }
626 template<
class D,
class DPtr>
627 inline bool operator!=( std::nullptr_t,
const RWCOW_pointer<D, DPtr> & rhs )
628 {
return(
nullptr != rhs.get() ); }
638#define DEFINE_PTR_TYPE(NAME) \
640extern void intrusive_ptr_add_ref( const NAME * ); \
641extern void intrusive_ptr_release( const NAME * ); \
642typedef zypp::intrusive_ptr<NAME> NAME##_Ptr; \
643typedef zypp::intrusive_ptr<const NAME> NAME##_constPtr;
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void swap(AutoDispose &rhs) noexcept
Exchange the contents of two AutoDispose objects.
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)
intrusive_ptr< T > make_intrusive(Args &&... __args)
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
void swap(RWCOW_pointer &rhs) noexcept
typename DTraits::PtrType PtrType
D * rwcowClone(const D *rhs)
Clone the underlying object.
const D * operator->() const
RW_pointer & operator=(const RW_pointer &)=default
constPtrType getPtr() const
const D & operator*() const
void swap(RW_pointer &rhs) noexcept
typename DTraits::PtrType 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.
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.
long use_count(const constPtrType &ptr_r) const
Return number of references.
long use_count(const constPtrType &ptr_r) const
Return number of references.
bool unique(const constPtrType &ptr_r)
Check whether pointer is not shared.