libzypp 17.37.10

zyppng::Base Class Reference

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

Inheritance diagram for zyppng::Base:

## Public Types
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
| Base ()
virtual | ~Base ()
WeakPtr | parent () const
void | addChild (const Base::Ptr &child)
void | removeChild (const Ptr &child)
const std::unordered_set< Ptr > & | children () const
std::thread::id | threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > | findChildren () const
template<typename T>
std::shared_ptr< T > | shared_this () const
template<typename T>
std::shared_ptr< T > | shared_this ()
template<typename T>
std::weak_ptr< T > | weak_this () const
template<typename T>
std::weak_ptr< T > | weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Static Public Member Functions
template<typename Obj, typename Functor>
static decltype(auto) | make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Protected Member Functions
| Base (BasePrivate &dd)

## Protected Attributes
std::unique_ptr< BasePrivate > | d_ptr

## Private Member Functions
| NON_COPYABLE (Base)

## Detailed Description

The Base class is used as a common base class for objects that emit signals, it also supports a parent/child relationship where the parent object keeps a reference for all its children.

Generally, all objects that want to send or receive signals should derive from Base, since it will help enforcing a correct use of shared_ptr semantics. Generally, with signal/slot emission, it is easy to run into the issue of an object being deleted while it emits a signal. Think about a Socket that emits a closed signal. It might be removed from the list of connections and the last reference of the object gets deleted before the signal returns. In order to prevent this from happening, we established a rule of "Always own a reference to the object you use". The connection helper's Base::connect and Base::connectFunc help with enforcing this rule, even asserting when compiled without NDEBUG defined.

See also
  zypp/zyppng/base/signals.h

Definition at line 59 of file base.h.

## Member Typedef Documentation

## ◆ Ptr

using zyppng::Base::Ptr = std::shared_ptr<Base>

Definition at line 65 of file base.h.

## ◆ WeakPtr

using zyppng::Base::WeakPtr = std::weak_ptr<Base>

Definition at line 66 of file base.h.

## Constructor & Destructor Documentation

## ◆ Base() [1/2]

zyppng::Base::Base | ( |  | ) |

Definition at line 20 of file base.cc.

## ◆ ~Base()

zyppng::Base::~Base | ( |  | ) |
| virtual

Definition at line 23 of file base.cc.

## ◆ Base() [2/2]

zyppng::Base::Base | ( | BasePrivate & | dd | ) |
| protected

Definition at line 13 of file base.cc.

## Member Function Documentation

## ◆ NON_COPYABLE()

zyppng::Base::NON_COPYABLE | ( | Base |  | ) |
| private

## ◆ parent()

Base::WeakPtr zyppng::Base::parent | ( |  | ) | const

Returns the parent object if there is one, otherwise returns a zero WeakPtr

Definition at line 26 of file base.cc.

## ◆ addChild()

void zyppng::Base::addChild | ( | const Base::Ptr & | child | ) |

Adds a new object to the child list, the object will keep a reference for its entire lifetime or until the object is removed

Definition at line 31 of file base.cc.

## ◆ removeChild()

void zyppng::Base::removeChild | ( | const Ptr & | child | ) |

Removes a child object from the internal child list

Definition at line 52 of file base.cc.

## ◆ children()

const std::unordered_set< Base::Ptr > & zyppng::Base::children | ( |  | ) | const

Returns all child objects of this object

Definition at line 66 of file base.cc.

## ◆ threadId()

std::thread::id zyppng::Base::threadId | ( |  | ) | const

Returns the thread ID this object was created in

Definition at line 71 of file base.cc.

## ◆ findChildren()

template<typename T>

std::vector< std::weak_ptr< T > > zyppng::Base::findChildren | ( |  | ) | const
| inline

Returns all children that can be casted to type T

Definition at line 102 of file base.h.

## ◆ shared_this() [1/2]

template<typename T>

std::shared_ptr< T > zyppng::Base::shared_this | ( |  | ) | const
| inline

Definition at line 113 of file base.h.

## ◆ shared_this() [2/2]

template<typename T>

std::shared_ptr< T > zyppng::Base::shared_this | ( |  | ) |
| inline

Definition at line 118 of file base.h.

## ◆ weak_this() [1/2]

template<typename T>

std::weak_ptr< T > zyppng::Base::weak_this | ( |  | ) | const
| inline

Definition at line 123 of file base.h.

## ◆ weak_this() [2/2]

template<typename T>

std::weak_ptr< T > zyppng::Base::weak_this | ( |  | ) |
| inline

Definition at line 128 of file base.h.

## ◆ make_base_slot()

template<typename Obj, typename Functor>

decltype(auto) zyppng::Base::make_base_slot | ( | Obj * | o,
|  | Functor && | f )
| inline static

Definition at line 133 of file base.h.

## ◆ connect() [1/2]

template<typename SenderFunc, typename ReceiverFunc>

auto zyppng::Base::connect | ( | typename internal::MemberFunction< SenderFunc >::ClassType & | s,
|  | SenderFunc && | sFun,
|  | typename internal::MemberFunction< ReceiverFunc >::ClassType & | recv,
|  | ReceiverFunc && | rFunc )
| inline static

Preferred way to connect a signal to a slot, this will automatically take care of tracking the target object in the connection

Definition at line 142 of file base.h.

## ◆ connect() [2/2]

template<typename SenderFunc, typename ReceiverFunc>

auto zyppng::Base::connect | ( | SenderFunc && | sFun,
|  | typename internal::MemberFunction< ReceiverFunc >::ClassType & | recv,
|  | ReceiverFunc && | rFunc )
| inline

Convenience func that uses "this" as the sender object in the signal / slot connection, this allows syntax like:

object.connect( &Obj::signal, *targetObj, &TargetObj::onSignal );

Definition at line 154 of file base.h.

## ◆ connectFunc() [1/2]

template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>

auto zyppng::Base::connectFunc | ( | typename internal::MemberFunction< SenderFunc >::ClassType & | s,
|  | SenderFunc && | sFun,
|  | ReceiverFunc && | rFunc,
|  | const Tracker &... | trackers )
| inline static

This allows to connect a lambda to a signal in a Base derived type. Make sure to track the objects used inside the slot for shared_ptr correctness ( always own a reference to the object you are calling )

Definition at line 163 of file base.h.

## ◆ connectFunc() [2/2]

template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>

std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > zyppng::Base::connectFunc | ( | SenderFunc && | sFun,
|  | ReceiverFunc && | rFunc,
|  | const Tracker &... | trackers )
| inline

Definition at line 168 of file base.h.

## Member Data Documentation

## ◆ d_ptr

std::unique_ptr<BasePrivate> zyppng::Base::d_ptr
| protected

Definition at line 174 of file base.h.

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

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