]> git.mxchange.org Git - simgear.git/blob - simgear/props/PropertyBasedMgr.hxx
cppbind.Ghost: clean up a bit
[simgear.git] / simgear / props / PropertyBasedMgr.hxx
1 // Base class for property controlled subsystems
2 //
3 // Copyright (C) 2012  Thomas Geymayer <tomgey@gmail.com>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 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 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
18
19 #ifndef SG_PROPERTY_BASED_MGR_HXX_
20 #define SG_PROPERTY_BASED_MGR_HXX_
21
22 #include "PropertyBasedElement.hxx"
23 #include <simgear/structure/subsystem_mgr.hxx>
24
25 #include <boost/function.hpp>
26 #include <vector>
27
28 namespace simgear
29 {
30
31   class PropertyBasedMgr:
32     public SGSubsystem,
33     public SGPropertyChangeListener
34   {
35     public:
36       virtual void init();
37       virtual void shutdown();
38
39       virtual void update (double delta_time_sec);
40
41       /**
42        * Create a new PropertyBasedElement
43        *
44        * @param name    Name of the new element
45        */
46       PropertyBasedElementPtr createElement(const std::string& name = "");
47
48       /**
49        * Get an existing PropertyBasedElement by its index
50        *
51        * @param index   Index of element node in property tree
52        */
53       PropertyBasedElementPtr getElement(size_t index) const;
54
55       /**
56        * Get an existing PropertyBasedElement by its name
57        *
58        * @param name    Name (value of child node "name" will be matched)
59        */
60       PropertyBasedElementPtr getElement(const std::string& name) const;
61
62       virtual const SGPropertyNode* getPropertyRoot() const;
63
64     protected:
65
66       typedef boost::function<PropertyBasedElementPtr(SGPropertyNode*)>
67               ElementFactory;
68
69       /** Branch in the property tree for this property managed subsystem */
70       SGPropertyNode_ptr      _props;
71
72       /** Property name of managed elements */
73       const std::string       _name_elements;
74
75       /** The actually managed elements */
76       std::vector<PropertyBasedElementPtr> _elements;
77
78       /** Function object which creates a new element */
79       ElementFactory          _element_factory;
80
81       /**
82        * @param props         Root node of property branch used for controlling
83        *                      this subsystem
84        * @param name_elements The name of the nodes for the managed elements
85        */
86       PropertyBasedMgr( SGPropertyNode_ptr props,
87                         const std::string& name_elements,
88                         ElementFactory element_factory );
89       virtual ~PropertyBasedMgr() = 0;
90
91       virtual void childAdded( SGPropertyNode * parent,
92                                SGPropertyNode * child );
93       virtual void childRemoved( SGPropertyNode * parent,
94                                  SGPropertyNode * child );
95
96       virtual void elementCreated(PropertyBasedElementPtr element) {}
97
98   };
99
100 } // namespace simgear
101
102 #endif /* SG_PROPERTY_BASED_MGR_HXX_ */