Monitor new signal to rebuild sendlist
[ardour.git] / gtk2_ardour / gui_object.h
1 /*
2  * Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2011-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef __gtk_ardour_gui_object_h__
22 #define __gtk_ardour_gui_object_h__
23
24 #include <map>
25 #include <string>
26
27 #include <boost/variant.hpp>
28
29 #include "pbd/xml++.h"
30 #include "pbd/id.h"
31
32 class GUIObjectState
33 {
34 public:
35         GUIObjectState ();
36
37         static const std::string xml_node_name;
38         void load (const XMLNode&);
39
40         int set_state (const XMLNode&);
41         XMLNode& get_state () const;
42
43         /** Get a string from our state.
44          *  @param id property of Object node to look for.
45          *  @param prop_name name of the Object property to return.
46          *  @param empty if non-0, filled in with true if the property is currently non-existant, otherwise false.
47          *  @return value of property `prop_name', or empty.
48          */
49         std::string get_string (const std::string& id, const std::string& prop_name, bool* empty = 0);
50
51         template<typename T> void set_property (const std::string& id, const std::string& prop_name, const T& val) {
52                 XMLNode* child = get_or_add_node (id);
53                 child->set_property (prop_name.c_str(), val);
54         }
55
56         /** Remove node with provided id.
57          *  @param id property of Object node to look for.
58          */
59         void remove_node (const std::string& id);
60         std::list<std::string> all_ids () const;
61
62         XMLNode* get_or_add_node (const std::string &);
63
64         static XMLNode* get_node (const XMLNode *, const std::string &);
65         static XMLNode* get_or_add_node (XMLNode *, const std::string &);
66
67   private:
68         // no copy construction. object_map saves pointers to _state XMLNodes
69         // use set_state(get_state())
70         GUIObjectState (const GUIObjectState& other);
71
72         XMLNode _state;
73         // ideally we'd use a O(1) hash table here,
74         // but O(log(N)) is fine already.
75         std::map <std::string, XMLNode*> object_map;
76 };
77
78 #endif /* __gtk_ardour_gui_object_h__ */