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