libzypp 17.37.10

base.cc
Go to the documentation of this file.
1#include <zypp-core/zyppng/base/private/base_p.h>
2
3 namespace zyppng {
4
5 BasePrivate::~BasePrivate()
6 { }
7
8 void BasePrivate::init()
9 { }
10
11 ZYPP_IMPL_PRIVATE(Base)
12
13 Base::Base ( BasePrivate &dd )
14 : d_ptr ( &dd )
15 {
16 d_ptr->z_ptr = this;
17 d_ptr->init();
18 }
19
20 Base::Base() : Base( *new BasePrivate(*this) )
21 { }
22
23 Base::~Base()
24 { }
25
26 Base::WeakPtr Base::parent() const
27 {
28 return d_func()->parent;
29 }
30
31 void Base::addChild( const Base::Ptr& child )
32 {
33 Z_D();
34 if ( !child )
35 return;
36
37 //we are already the parent
38 auto childParent = child->d_func()->parent.lock();
39 if ( childParent.get() == this )
40 return;
41
42 if ( childParent ) {
43 childParent->removeChild( child );
44 }
45
46 d->children.insert( child );
47
48 auto tracker = this->weak_this<Base>();
49 child->d_func()->parent = tracker;
50 }
51
52 void Base::removeChild( const Base::Ptr& child )
53 {
54 if ( !child )
55 return;
56
57 //we are not the child of this object
58 if ( child->d_func()->parent.lock().get() != this )
59 return;
60
61 Z_D();
62 d->children.erase( child );
63 child->d_func()->parent.reset();
64 }
65
66 const std::unordered_set<Base::Ptr> &Base::children() const
67 {
68 return d_func()->children;
69 }
70
71 std::thread::id Base::threadId() const
72 {
73 return d_func()->threadId;
74 }
75
76} // namespace zyppng
base_p.h
zyppng::BasePrivate
Definition base_p.h:14
zyppng::BasePrivate::~BasePrivate
virtual ~BasePrivate()
Definition base.cc:5
zyppng::BasePrivate::init
virtual void init()
Definition base.cc:8
zyppng::Base
Definition base.h:60
zyppng::Base::removeChild
void removeChild(const Ptr &child)
Definition base.cc:52
zyppng::Base::threadId
std::thread::id threadId() const
Definition base.cc:71
zyppng::Base::WeakPtr
std::weak_ptr< Base > WeakPtr
Definition base.h:66
zyppng::Base::children
const std::unordered_set< Ptr > & children() const
Definition base.cc:66
zyppng::Base::addChild
void addChild(const Base::Ptr &child)
Definition base.cc:31
zyppng::Base::parent
WeakPtr parent() const
Definition base.cc:26
zyppng::Base::Ptr
std::shared_ptr< Base > Ptr
Definition base.h:65
zyppng::Base::~Base
virtual ~Base()
Definition base.cc:23
zyppng::Base::weak_this
std::weak_ptr< T > weak_this() const
Definition base.h:123
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::Base::d_ptr
std::unique_ptr< BasePrivate > d_ptr
Definition base.h:174
zyppng
Definition MediaNetworkRequestExecutor.h:16
ZYPP_IMPL_PRIVATE
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:92
Z_D
#define Z_D()
Definition zyppglobal.h:105