hx3d  1
2D/3D Simple Game Framework
property.hpp
1 /*
2  Property.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_UTILS_PROPERTY
22 #define HX3D_UTILS_PROPERTY
23 
24 #include <vector>
25 #include <functional>
26 
27 namespace hx3d {
28 
32 template <class T>
34 public:
41  virtual void observe(const T& current, const T& newVal) = 0;
42 };
43 
47 template <class T>
49 private:
50  T _value;
51  std::function<void(const T&, const T&)> _func;
52 
53 public:
60  CallbackProperty(const T& value, std::function<void(const T&, const T&)> func);
61 
67  operator T const&() const;
68 
76  T& operator=(const T& value);
77 };
78 
82 template <class T>
83 class Property {
84 private:
85  T _value;
86  std::vector<PropertyObserver<T>*> _observers;
87 
88 public:
94  Property(const T& value);
95 
101  void addObserver(PropertyObserver<T>* observer);
102 
108  operator T const&() const;
109 
117  T& operator=(const T& value);
118 };
119 
120 } /* hx3d */
121 
122 #include "hx3d/utils/_inline/property.inl.hpp"
123 
124 #endif /* HX3D_UTILS_PROPERTY */
virtual void observe(const T &current, const T &newVal)=0
Observe property modification.
Callback-on-change property.
Definition: property.hpp:48
hx3d framework namespace
Definition: audio.hpp:26
Observable property.
Definition: property.hpp:83
Property observer (Observer pattern)
Definition: property.hpp:33