]> git.mxchange.org Git - flightgear.git/blob - src/Canvas/property_based_mgr.hxx
Canvas: Image/Window unifying and allow using canvas inside canvas.
[flightgear.git] / src / Canvas / property_based_mgr.hxx
1 // Base class for all property controlled subsystems
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 #ifndef PROPERTY_BASED_MGR_HXX_
20 #define PROPERTY_BASED_MGR_HXX_
21
22 #include "property_based_element.hxx"
23 #include <simgear/structure/subsystem_mgr.hxx>
24
25 #include <boost/shared_ptr.hpp>
26 #include <boost/function.hpp>
27 #include <vector>
28
29 class PropertyBasedMgr:
30   public SGSubsystem,
31   public SGPropertyChangeListener
32 {
33   public:
34     virtual void init();
35     virtual void shutdown();
36
37     virtual void update (double delta_time_sec);
38
39     virtual void childAdded( SGPropertyNode * parent,
40                              SGPropertyNode * child );
41     virtual void childRemoved( SGPropertyNode * parent,
42                                SGPropertyNode * child );
43
44     virtual void elementCreated(PropertyBasedElementPtr element) {}
45
46     virtual const SGPropertyNode* getPropertyRoot() const;
47
48   protected:
49
50     typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)>
51             ElementFactory;
52
53     /** Branch in the property tree for this property managed subsystem */
54     SGPropertyNode*      _props;
55
56     /** Property name of managed elements */
57     const std::string       _name_elements;
58
59     /** The actually managed elements */
60     std::vector<PropertyBasedElementPtr> _elements;
61
62     /** Function object which creates a new element */
63     ElementFactory          _element_factory;
64
65     /**
66      * @param path_root     Path to property branch used for controlling this
67      *                      subsystem
68      * @param name_elements The name of the nodes for the managed elements
69      */
70     PropertyBasedMgr( const std::string& path_root,
71                       const std::string& name_elements,
72                       ElementFactory element_factory );
73     virtual ~PropertyBasedMgr() = 0;
74
75 };
76
77 #endif /* PROPERTY_BASED_MGR_HXX_ */