libzypp: zypp::base::ReferenceCounted Class Reference

libzypp 17.36.6

Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | Related Symbols | List of all members
zypp::base::ReferenceCounted Class Reference

Base class for reference counted objects. More...

`#include <zypp-core/base/ReferenceCounted.h>`

Inheritance diagram for zypp::base::ReferenceCounted:

## Public Member Functions
| ReferenceCounted ()
| Default ctor.
| ReferenceCounted (const ReferenceCounted &rhs)
| Copy ctor.
virtual | ~ReferenceCounted ()
| Dtor.
ReferenceCounted & | operator= (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 Symbols
(Note that these are not member symbols.)
void | intrusive_ptr_add_ref (const ReferenceCounted *ptr_r)
| intrusive_ptr hook to add_ref.
void | intrusive_ptr_release (const ReferenceCounted *ptr_r)
| intrusive_ptr hook to release.
std::ostream & | operator<< (std::ostream &str, const ReferenceCounted &obj)
| Stream output.

## Detailed Description

Base class for reference counted objects.

Todo
  Make counter thread safe.

Definition at line 34 of file ReferenceCounted.h.

## Constructor & Destructor Documentation

## ◆ ReferenceCounted() [1/2]

zypp::base::ReferenceCounted::ReferenceCounted | ( |  | ) |

Default ctor.

Initial reference count is zero.

Definition at line 25 of file ReferenceCounted.cc.

## ◆ ReferenceCounted() [2/2]

zypp::base::ReferenceCounted::ReferenceCounted | ( | const ReferenceCounted & | rhs | ) |

Copy ctor.

Initial reference count is zero.

Definition at line 29 of file ReferenceCounted.cc.

## ◆ ~ReferenceCounted()

zypp::base::ReferenceCounted::~ReferenceCounted | ( |  | ) |
| virtual

Dtor.

Exceptions

  std::out_of_range | if reference count is not zero.

Definition at line 33 of file ReferenceCounted.cc.

## Member Function Documentation

## ◆ operator=()

ReferenceCounted & zypp::base::ReferenceCounted::operator= | ( | const ReferenceCounted & |  | ) |
| inline

Assignment.

Reference count remains untouched.

Definition at line 58 of file ReferenceCounted.h.

## ◆ refCount()

unsigned zypp::base::ReferenceCounted::refCount | ( |  | ) | const
| inline

Return reference counter value.

Definition at line 63 of file ReferenceCounted.h.

## ◆ ref()

void zypp::base::ReferenceCounted::ref | ( |  | ) | const
| inline

Add a reference.

Definition at line 67 of file ReferenceCounted.h.

## ◆ unref()

void zypp::base::ReferenceCounted::unref | ( |  | ) | const
| inline

Release a reference.

Deletes the object if reference count gets zero.

Exceptions

  std::out_of_range | if reference count is zero.

Definition at line 74 of file ReferenceCounted.h.

## ◆ add_ref()

static void zypp::base::ReferenceCounted::add_ref | ( | const ReferenceCounted * | ptr_r | ) |
| inlinestatic

Called by zypp::intrusive_ptr to add a reference.

See also
  Smart pointer types

Definition at line 87 of file ReferenceCounted.h.

## ◆ release()

static void zypp::base::ReferenceCounted::release | ( | const ReferenceCounted * | ptr_r | ) |
| inlinestatic

Called by zypp::intrusive_ptr to add a reference.

See also
  Smart pointer types

Definition at line 93 of file ReferenceCounted.h.

## ◆ dumpOn()

std::ostream & zypp::base::ReferenceCounted::dumpOn | ( | std::ostream & | str | ) | const
| protectedvirtual

Overload to realize std::ostream & operator<<.

Reimplemented in zypp::MediaSetAccess, zypp::parser::susetags::RepoIndex, zypp::ResObject, zypp::Resolvable, zypp::Target, zypp::target::rpm::BinHeader, zypp::target::rpm::librpmDb, zypp::target::rpm::RpmDb, zypp::target::rpm::RpmHeader, and zypp::target::TargetImpl.

Definition at line 47 of file ReferenceCounted.cc.

## ◆ ref_to()

virtual void zypp::base::ReferenceCounted::ref_to | ( | unsigned |  | ) | const
| inlineprotectedvirtual

Trigger derived classes after refCount was increased.

Reimplemented in zyppng::AttachedMediaInfo.

Definition at line 101 of file ReferenceCounted.h.

## ◆ unref_to()

virtual void zypp::base::ReferenceCounted::unref_to | ( | unsigned |  | ) | const
| inlineprotectedvirtual

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 107 of file ReferenceCounted.h.

## ◆ unrefException()

void zypp::base::ReferenceCounted::unrefException | ( |  | ) | const
| private

Throws Exception on unref.

Definition at line 41 of file ReferenceCounted.cc.

## Friends And Related Symbol Documentation

## ◆ operator<< [1/2]

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

Stream output via dumpOn.

## ◆ intrusive_ptr_add_ref()

void intrusive_ptr_add_ref | ( | const ReferenceCounted * | ptr_r | ) |
| related

intrusive_ptr hook to add_ref.

Definition at line 119 of file ReferenceCounted.h.

## ◆ intrusive_ptr_release()

void intrusive_ptr_release | ( | const ReferenceCounted * | ptr_r | ) |
| related

intrusive_ptr hook to release.

Definition at line 123 of file ReferenceCounted.h.

## ◆ operator<<() [2/2]

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

Stream output.

Definition at line 127 of file ReferenceCounted.h.

## Member Data Documentation

## ◆ _counter

unsigned zypp::base::ReferenceCounted::_counter
| mutableprivate

The reference counter.

Definition at line 111 of file ReferenceCounted.h.

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

- zypp-core/base/ReferenceCounted.h
- zypp-core/base/ReferenceCounted.cc