libzypp  9.1.2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | Related Functions
zypp::base::ReferenceCounted Class Reference

Base class for reference counted objects. More...

#include <ReferenceCounted.h>

Inheritance diagram for zypp::base::ReferenceCounted:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 ReferenceCounted ()
 Default ctor.
 ReferenceCounted (const ReferenceCounted &rhs)
 Copy ctor.
virtual ~ReferenceCounted ()
 Dtor.
ReferenceCountedoperator= (const ReferenceCounted &)
 Assignment.
unsigned refCount () const
 Return reference counter value.
void ref () const
 Add a reference.
void unref () const
 Release a reference.

Static Public Member Functions

static void add_ref (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference.
static void release (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference.

Protected Member Functions

virtual std::ostream & dumpOn (std::ostream &str) const
 Overload to realize std::ostream & operator<<.
virtual void ref_to (unsigned) const
 Trigger derived classes after refCount was increased.
virtual void unref_to (unsigned) const
 Trigger derived classes after refCount was decreased.

Private Member Functions

void unrefException () const
 Throws Exception on unref.

Private Attributes

unsigned _counter
 The reference counter.

Friends

std::ostream & operator<< (std::ostream &str, const ReferenceCounted &obj)
 Stream output via dumpOn.

Related Functions

(Note that these are not member functions.)

void intrusive_ptr_add_ref (const ReferenceCounted *ptr_r)
void intrusive_ptr_release (const ReferenceCounted *ptr_r)
std::ostream & operator<< (std::ostream &str, const ReferenceCounted &obj)

Detailed Description

Base class for reference counted objects.

Todo:
Make counter thread safe.

Definition at line 33 of file ReferenceCounted.h.


Constructor & Destructor Documentation

Default ctor.

Initial reference count is zero.

Definition at line 25 of file ReferenceCounted.cc.

Copy ctor.

Initial reference count is zero.

Definition at line 29 of file ReferenceCounted.cc.

Dtor.

Exceptions:
std::out_of_rangeif reference count is not zero.

Definition at line 33 of file ReferenceCounted.cc.

References _counter, and INT.


Member Function Documentation

ReferenceCounted& zypp::base::ReferenceCounted::operator= ( const ReferenceCounted ) [inline]

Assignment.

Reference count remains untouched.

Definition at line 57 of file ReferenceCounted.h.

unsigned zypp::base::ReferenceCounted::refCount ( ) const [inline]

Return reference counter value.

Definition at line 62 of file ReferenceCounted.h.

References _counter.

void zypp::base::ReferenceCounted::ref ( ) const [inline]

Add a reference.

Definition at line 66 of file ReferenceCounted.h.

References _counter, and ref_to().

Referenced by add_ref().

void zypp::base::ReferenceCounted::unref ( ) const [inline]

Release a reference.

Deletes the object if reference count gets zero.

Exceptions:
std::out_of_rangeif reference count is zero.

Definition at line 73 of file ReferenceCounted.h.

References _counter, unref_to(), and unrefException().

Referenced by release().

static void zypp::base::ReferenceCounted::add_ref ( const ReferenceCounted ptr_r) [inline, static]

Called by zypp::intrusive_ptr to add a reference.

See also:
Smart pointer types

Definition at line 86 of file ReferenceCounted.h.

References ref().

Referenced by intrusive_ptr_add_ref().

static void zypp::base::ReferenceCounted::release ( const ReferenceCounted ptr_r) [inline, static]

Called by zypp::intrusive_ptr to add a reference.

See also:
Smart pointer types

Definition at line 92 of file ReferenceCounted.h.

References unref().

Referenced by intrusive_ptr_release().

std::ostream & zypp::base::ReferenceCounted::dumpOn ( std::ostream &  str) const [protected, virtual]
virtual void zypp::base::ReferenceCounted::ref_to ( unsigned  ) const [inline, protected, virtual]

Trigger derived classes after refCount was increased.

Definition at line 100 of file ReferenceCounted.h.

Referenced by ref().

virtual void zypp::base::ReferenceCounted::unref_to ( unsigned  ) const [inline, protected, virtual]

Trigger derived classes after refCount was decreased.

No trigger is sent, if refCount got zero (i.e. the object is deleted).

Reimplemented in zypp::target::rpm::librpmDb.

Definition at line 106 of file ReferenceCounted.h.

Referenced by unref().

Throws Exception on unref.

Definition at line 42 of file ReferenceCounted.cc.

References INT.

Referenced by unref().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  str,
const ReferenceCounted obj 
) [friend]

Stream output via dumpOn.

void intrusive_ptr_add_ref ( const ReferenceCounted ptr_r) [related]

intrusive_ptr hook to add_ref.

Definition at line 118 of file ReferenceCounted.h.

References add_ref().

void intrusive_ptr_release ( const ReferenceCounted ptr_r) [related]

intrusive_ptr hook to release.

Definition at line 122 of file ReferenceCounted.h.

References release().

std::ostream & operator<< ( std::ostream &  str,
const ReferenceCounted obj 
) [related]

Stream output.

Definition at line 126 of file ReferenceCounted.h.

References dumpOn().


Member Data Documentation

unsigned zypp::base::ReferenceCounted::_counter [mutable, private]

The reference counter.

Definition at line 110 of file ReferenceCounted.h.

Referenced by dumpOn(), ref(), refCount(), unref(), and ~ReferenceCounted().


The documentation for this class was generated from the following files: