libzypp: zypp-core/ng/base/base.cc Source File

libzypp 17.38.14

base.cc
Go to the documentation of this file.
1#include <zypp-core/ng/base/private/base_p.h>
2
3namespace 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 void Base::setData( uint32_t quark, zypp::AutoDispose<void *> data )
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
base_p.h
zypp::AutoDispose
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
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:61
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::clearData
void clearData(uint32_t quark)
Definition base.cc:90
zyppng::Base::WeakPtr
std::weak_ptr< Base > WeakPtr
Definition base.h:67
zyppng::Base::setData
void setData(uint32_t quark, zypp::AutoDispose< void * > data)
Definition base.cc:76
zyppng::Base::children
const std::unordered_set< Ptr > & children() const
Definition base.cc:66
zyppng::Base::data
void * data(uint32_t quark)
Definition base.cc:82
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:66
zyppng::Base::~Base
virtual ~Base()
Definition base.cc:23
zyppng::Base::weak_this
std::weak_ptr< T > weak_this() const
Definition base.h:124
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::Base::d_ptr
std::unique_ptr< BasePrivate > d_ptr
Definition base.h:182
zyppng
Definition MediaNetworkRequestExecutor.h:16
ZYPP_IMPL_PRIVATE
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:85
Z_D
#define Z_D()
Definition zyppglobal.h:98