libzypp 17.37.17
base.cc
Go to the documentation of this file.
2
3namespace zyppng {
4
7
9 { }
10
12
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
24 { }
25
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
virtual ~BasePrivate()
Definition base.cc:5
virtual void init()
Definition base.cc:8
void removeChild(const Ptr &child)
Definition base.cc:52
std::thread::id threadId() const
Definition base.cc:71
std::weak_ptr< Base > WeakPtr
Definition base.h:66
const std::unordered_set< Ptr > & children() const
Definition base.cc:66
void addChild(const Base::Ptr &child)
Definition base.cc:31
WeakPtr parent() const
Definition base.cc:26
std::shared_ptr< Base > Ptr
Definition base.h:65
virtual ~Base()
Definition base.cc:23
std::weak_ptr< T > weak_this() const
Definition base.h:123
std::unique_ptr< BasePrivate > d_ptr
Definition base.h:174
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:92
#define Z_D()
Definition zyppglobal.h:105