OneChildElem.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class ChildT >
6  Elem( inst ),
7  cm( inst, this, "OneChildElem" ),
8  child( &this->cm, nullptr ),
9  heap( inst, &this->cm )
10 {
11  this->cm.inherits( this->Elem::cm );
12 }
13 
14 template< class ChildT >
16 {
17  if( this->child.Get() )
18  {
19  // elem
20  this->child.Get()->elem()->elem_setParent( nullptr );
21 
22  // input
23  this->child.Get()->elem()->input_treeRefresh();
24  this->child.Get()->elem()->input_deactivate();
25  this->child.Get()->elem()->input_setParent( nullptr );
26  }
27 }
28 
29 template< class ChildT >
30 template< class T, class ... CArgs >
31 T * OneChildElem< ChildT >::createChild( CArgs const & ... cargs )
32 {
33  static_assert( std::is_base_of< ChildT, T >::value, "Child must inherit ChildT." );
34  auto t = this->heap.template createClient< T >( cargs ... );
35  this->setChild( t );
36  return t;
37 }
38 
39 template< class ChildT >
40 template< class T, class ... CArgs >
41 T * OneChildElem< ChildT >::createChild_Instance( char const * name, CArgs const & ... cargs )
42 {
43  static_assert( std::is_base_of< ChildT, T >::value, "Child must inherit ChildT." );
44  auto t = this->heap.template createInstance< T >( name, cargs ... );
45  this->setChild( t );
46  return t;
47 }
48 
49 template< class ChildT >
50 void OneChildElem< ChildT >::setChild( ChildT * child )
51 {
52  if( this->child.Get() )
53  this->removeChild();
54 
55  if( !child )
56  {
57  this->removeChild();
58  return;
59  }
60 
61  // pointer
62  this->child.Set( child );
63 
64  // input
65  child->elem()->input_setParent( this );
66  this->input_treeRefresh();
67 
68  // elem
69  child->elem()->elem_setParent( this );
70 }
71 
72 template< class ChildT >
74 {
75  if( !this->child.Get() )
76  return;
77 
78  // input
79  this->child.Get()->elem()->input_deactivate();
80  this->child.Get()->elem()->input_setParent( nullptr );
81  this->input_treeRefresh();
82 
83  // elem
84  this->child.Get()->elem()->elem_setParent( nullptr );
85 
86  // pointer
87  this->child.Set( nullptr );
88 }
89 
90 template< class ChildT >
91 void OneChildElem< ChildT >::elem_eachChild( std::function< void( Elem * ) > const & f )
92 {
93  if( this->child.Get() )
94  f( this->child.Get()->elem() );
95 }
96 
97 template< class ChildT >
99 {
100  if( this->child.Get()->elem() == node )
101  this->removeChild();
102 }
103 
104 template< class ChildT >
105 void OneChildElem< ChildT >::input_eachChild( std::function< void( InputNode * ) > const & f )
106 {
107  this->Elem::input_eachChild( f );
108 
109  if( this->child.Get() )
110  f( this->child.Get()->elem() );
111 }
112 
113 template< class ChildT >
115 {
116  this->Elem::input_childDisconnect( child );
117 
118  if( this->child.Get()->elem() == child )
119  this->removeChild();
120 }
121 
122 }