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