Ardour  9.0-pre0-350-gf17a656217
gui_object.h
Go to the documentation of this file.
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 #pragma once
22 
23 #include <map>
24 #include <string>
25 
26 #include "pbd/xml++.h"
27 #include "pbd/id.h"
28 
30 {
31 public:
33 
34  static const std::string xml_node_name;
35  void load (const XMLNode&);
36 
37  int set_state (const XMLNode&);
38  XMLNode& get_state () const;
39 
46  std::string get_string (const std::string& id, const std::string& prop_name, bool* empty = 0);
47 
48  template<typename T> void set_property (const std::string& id, const std::string& prop_name, const T& val) {
49  XMLNode* child = get_or_add_node (id);
50  child->set_property (prop_name.c_str(), val);
51  }
52  void remove_property (const std::string & id, const std:: string & prop_name);
53 
57  void remove_node (const std::string& id);
58  std::list<std::string> all_ids () const;
59 
60  XMLNode* get_or_add_node (const std::string &);
61 
62  static XMLNode* get_node (const XMLNode *, const std::string &);
63  static XMLNode* get_or_add_node (XMLNode *, const std::string &);
64 
65  private:
66  // no copy construction. object_map saves pointers to _state XMLNodes
67  // use set_state(get_state())
69 
71  // ideally we'd use a O(1) hash table here,
72  // but O(log(N)) is fine already.
73  std::map <std::string, XMLNode*> object_map;
74 };
75 
void load(const XMLNode &)
std::list< std::string > all_ids() const
static XMLNode * get_or_add_node(XMLNode *, const std::string &)
void set_property(const std::string &id, const std::string &prop_name, const T &val)
Definition: gui_object.h:48
XMLNode & get_state() const
void remove_node(const std::string &id)
void remove_property(const std::string &id, const std::string &prop_name)
static const std::string xml_node_name
Definition: gui_object.h:34
static XMLNode * get_node(const XMLNode *, const std::string &)
GUIObjectState(const GUIObjectState &other)
std::string get_string(const std::string &id, const std::string &prop_name, bool *empty=0)
XMLNode _state
Definition: gui_object.h:70
std::map< std::string, XMLNode * > object_map
Definition: gui_object.h:73
int set_state(const XMLNode &)
XMLNode * get_or_add_node(const std::string &)
Definition: xml++.h:114
bool set_property(const char *name, const std::string &value)