Oxygine  1
2g game engine
Property.h
1 #pragma once
2 namespace oxygine
3 {
4  template<typename Value, typename getValueRef, typename setValueRef, typename C, getValueRef(C::*GetF)() const, void (C::*SetF)(setValueRef)>
5  class Property0
6  {
7  public:
8  typedef C type;
9  typedef Value value;
10 
11  Property0(getValueRef dest) : _dest(dest), _initialized(false) {}
12 
13  void init(type& t)
14  {
15  _initialized = true;
16  _src = get(t);
17  }
18 
19  void init(getValueRef src)
20  {
21  _initialized = true;
22  _src = src;
23  }
24 
25  void setSrc(type& t)
26  {
27  set(t, _src);
28  }
29 
30  void setDest(type& t)
31  {
32  set(t, _dest);
33  }
34 
35  const value& getDest() const
36  {
37  return _dest;
38  }
39 
40  const value& getSrc() const
41  {
42  return _src;
43  }
44 
45  void update(type& t, float p, const UpdateState& us)
46  {
47  OX_ASSERT(_initialized);
48  value v = lerp(_src, _dest, p);
49  set(t, v);
50  }
51 
52  void done(type& t)
53  {
54  }
55 
56  static getValueRef get(C& c)
57  {
58  return (c.*GetF)();
59  }
60 
61  private:
62  value _dest;
63  value _src;
64  bool _initialized;
65 
66  static void set(C& c, setValueRef v)
67  {
68  return (c.*SetF)(v);
69  }
70  };
71 
72  template<typename Value, typename valueRef, typename C, valueRef(C::*GetF)() const, void (C::*SetF)(valueRef)>
73  class Property: public Property0<Value, valueRef, valueRef, C, GetF, SetF>
74  {
75  public:
77  };
78 
79  template<typename value0, typename value, typename valueRef, typename C, valueRef(C::*GetF)() const, void (C::*SetF)(valueRef)>
80  class Property2Args : public Property < value, valueRef, C, GetF, SetF >
81  {
83  public:
84  Property2Args(value0 v1, value0 v2) : GS(value(v1, v2)) {}
85  Property2Args(valueRef v) : GS(v) {}
86  };
87 
88 
89  template<typename value0, typename value, typename getValueRef, typename setValueRef, typename C, getValueRef(C::*GetF)() const, void (C::*SetF)(setValueRef)>
90  class Property2Args2 : public Property0 < value, getValueRef, setValueRef, C, GetF, SetF >
91  {
93  public:
94  Property2Args2(value0 v1, value0 v2) : GS(value(v1, v2)) {}
95  Property2Args2(getValueRef v) : GS(v) {}
96  };
97 
98  template<typename value0, typename value, typename valueRef, typename C, valueRef(C::*GetF)() const, void (C::*SetF)(valueRef)>
99  class Property2Args1Arg : public Property < value, valueRef, C, GetF, SetF >
100  {
102  public:
103  Property2Args1Arg(value0 v) : GS(value(v, v)) {}
104  Property2Args1Arg(value0 v1, value0 v2) : GS(value(v1, v2)) {}
105  Property2Args1Arg(valueRef v) : GS(v) {}
106  };
107 
108  //backward compatibility
109 #define GetSet Property
110 #define GetSet2Args Property2Args
111 #define GetSet2Args1Arg Property2Args1Arg
112 
113 }
Definition: Property.h:90
Definition: Property.h:73
Definition: Property.h:80
Definition: UpdateState.h:6
Definition: Property.h:5
–oxgl-end–!
Definition: Actor.h:14
Definition: Property.h:99