12#ifndef ZYPP_CORE_BASE_REFERENCECOUNTED_H
13#define ZYPP_CORE_BASE_REFERENCECOUNTED_H
17#include <zypp-core/base/PtrTypes.h>
33 class ReferenceCounted
87 {
if( ptr_r ) ptr_r->ref(); }
93 {
if( ptr_r ) ptr_r->unref(); }
97 virtual std::ostream &
dumpOn( std::ostream &
str )
const;
100 virtual void ref_to(
unsigned )
const {}
106 virtual void unref_to(
unsigned )
const {}
118 inline void intrusive_ptr_add_ref(
const ReferenceCounted * ptr_r )
122 inline void intrusive_ptr_release(
const ReferenceCounted * ptr_r )
126 inline std::ostream &
operator<<( std::ostream &
str,
const ReferenceCounted & obj )
127 {
return obj.dumpOn(
str ); }
136#define IMPL_PTR_TYPE(NAME) \
137void intrusive_ptr_add_ref( const NAME * ptr_r ) \
138{ zypp::base::ReferenceCounted::add_ref( ptr_r ); } \
139void intrusive_ptr_release( const NAME * ptr_r ) \
140{ zypp::base::ReferenceCounted::release( ptr_r ); }
virtual ~ReferenceCounted()
Dtor.
void ref() const
Add a reference.
virtual void unref_to(unsigned) const
Trigger derived classes after refCount was decreased.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload to realize std::ostream & operator<<.
void unrefException() const
Throws Exception on unref.
friend std::ostream & operator<<(std::ostream &str, const ReferenceCounted &obj)
Stream output via dumpOn.
void unref() const
Release a reference.
unsigned _counter
The reference counter.
static void add_ref(const ReferenceCounted *ptr_r)
Called by zypp::intrusive_ptr to add a reference.
unsigned refCount() const
Return reference counter value.
virtual void ref_to(unsigned) const
Trigger derived classes after refCount was increased.
ReferenceCounted & operator=(const ReferenceCounted &)
Assignment.
ReferenceCounted()
Default ctor.
static void release(const ReferenceCounted *ptr_r)
Called by zypp::intrusive_ptr to add a reference.
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const Flags< TEnum > &obj)
Easy-to use interface to the ZYPP dependency resolver.