DVar.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "DVarSystem.hpp"
4 
5 namespace iv
6 {
7 
16 template< class Type >
17 class DVar : private DVarListenerI
18 {
19 public:
21 
22  DVar( Instance * inst, DVarIdT< Type > id = DVarIdT< Type >() );
23  ~DVar();
24 
25  Instance * instance();
26 
27  Type get();
28 
29  void dvar( DVarIdT< Type > id );
30  DVarIdT< Type > dvar() const;
31 
32  void on_changed( std::function< void( Type const & newval ) > const &, bool call_immediately = false );
33 
34 private:
35  virtual void on_dvar_changed( DVarId id, std::type_index type, void * value ) override;
36 
37  Type get_uncached();
38 
39 private:
40  Instance * inst;
41  DVarSystem * dvs;
42  DVarIdT< Type > id;
43  std::function< void( Type const & newval ) > _on_changed;
44  Type cached;
45 };
46 
47 }
48 
49 #include "DVar.inl"