libzypp 17.38.7
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
77 {
78 Z_D();
79 d->_data.insert_or_assign ( quark, data );
80 }
81
82 void *Base::data( uint32_t quark )
83 {
84 Z_D();
85 if ( !d->_data.count (quark) )
86 return nullptr;
87 return d->_data.at(quark).value ();
88 }
89
90 void Base::clearData( uint32_t quark )
91 {
92 Z_D();
93 d->_data.erase(quark);
94 }
95} // namespace zyppng
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
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
void clearData(uint32_t quark)
Definition base.cc:90
std::weak_ptr< Base > WeakPtr
Definition base.h:67
void setData(uint32_t quark, zypp::AutoDispose< void * > data)
Definition base.cc:76
const std::unordered_set< Ptr > & children() const
Definition base.cc:66
void * data(uint32_t quark)
Definition base.cc:82
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:66
virtual ~Base()
Definition base.cc:23
std::weak_ptr< T > weak_this() const
Definition base.h:124
std::unique_ptr< BasePrivate > d_ptr
Definition base.h:182
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:85
#define Z_D()
Definition zyppglobal.h:98