DVarCloner.inl
Go to the documentation of this file.
1 namespace iv
2 {
3 
4 template< class T >
5 DVarCloner< T >::DVarCloner( Instance * inst, DVarIdT< T > source, DVarIdT< T > target ) :
6  cm( inst, this, "DVarCloner" ),
7  inst( inst ),
8  dvs( inst->getSystem< DVarSystem >() ),
9  source( source ),
10  target( target )
11 {
12  if( this->dvs )
13  {
14  this->dvs->lock( this->instance(), this->target );
15  this->dvs->add_listener( this, this->source );
16 
17  this->dvs->template set< T >( this->instance(), this->target, this->dvs->template get< T >( source ) );
18  }
19 }
20 
21 template< class T >
22 DVarCloner< T >::~DVarCloner()
23 {
24  if( this->dvs )
25  {
26  this->dvs->unlock( this->instance(), this->target );
27  this->dvs->remove_listener( this, this->source );
28  }
29 }
30 
31 template< class T >
32 Instance * DVarCloner< T >::instance()
33 {
34  return this->inst;
35 }
36 
37 template< class T >
38 void DVarCloner< T >::on_dvar_changed( DVarId id, std::type_index type, void * value )
39 {
40  if( type != typeid( T ) )
41  {
42  this->cm.warning( SRC_INFO, "DVar ", id, " has unexpected type." );
43  return;
44  }
45 
46  this->dvs->template set< T >( this->instance(), this->target, *reinterpret_cast< T * >( value ) );
47 }
48 
49 }