DVar_Field.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class Type >
6  Field< Type >( inst ),
7  cm( inst, this, "DVar_Field" ),
8  inst( inst ),
9  id( id )
10 {
11  this->cm.inherits( this->Field< Type >::cm );
12 
13  auto dvs = inst->getSystemContainer()->getSystem< DVarSystem >();
14  if( dvs )
15  {
16  auto value = dvs->get< Type >( this->id );
17  this->Modify( value );
18  dvs->add_listener( this, this->id );
19  }
20 }
21 
22 template< class Type >
24 {
25  auto dvs = inst->getSystemContainer()->getSystem< DVarSystem >();
26  if( dvs )
27  dvs->remove_listener( this, this->id );
28 }
29 
30 template< class Type >
32 {
33  return this->inst;
34 }
35 
36 template< class Type >
37 void DVar_Field< Type >::on_dvar_changed( DVarId id, std::type_index type, void * value )
38 {
39  Type & t_value = *reinterpret_cast< Type * >( value );
40  this->Modify( t_value );
41 }
42 
43 template< class Type >
44 void DVar_Field< Type >::OnChanged( bool real )
45 {
46  if( !real )
47  {
48  auto dvs = inst->getSystemContainer()->getSystem< DVarSystem >();
49  if( dvs )
50  {
51  auto value = dvs->get< Type >( this->id );
52  this->Modify( value );
53  }
54  }
55 }
56 
57 }