GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
gtk-manager.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2007-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_gtk_manager_h)
27 #define octave_gtk_manager_h 1
28 
29 #include "octave-config.h"
30 
31 #include <map>
32 #include <set>
33 #include <string>
34 
35 #include "Cell.h"
36 #include "graphics-toolkit.h"
37 
38 namespace octave
39 {
41  {
42  public:
43 
44  gtk_manager (void) { }
45 
46  ~gtk_manager (void)
47  {
49  }
50 
51  graphics_toolkit get_toolkit (void) const;
52 
53  void register_toolkit (const std::string& name);
54 
55  void unregister_toolkit (const std::string& name);
56 
57  void load_toolkit (const graphics_toolkit& tk)
58  {
59  loaded_toolkits[tk.get_name ()] = tk;
60  }
61 
62  void unload_toolkit (const std::string& name)
63  {
64  loaded_toolkits.erase (name);
65  }
66 
67  graphics_toolkit find_toolkit (const std::string& name) const
68  {
69  auto p = loaded_toolkits.find (name);
70 
71  if (p != loaded_toolkits.end ())
72  return p->second;
73  else
74  return graphics_toolkit ();
75  }
76 
78  {
79  Cell m (1, available_toolkits.size ());
80 
81  octave_idx_type i = 0;
82  for (const auto& tkit : available_toolkits)
83  m(i++) = tkit;
84 
85  return m;
86  }
87 
89  {
90  Cell m (1, loaded_toolkits.size ());
91 
92  octave_idx_type i = 0;
93  for (const auto& nm_tkit_p : loaded_toolkits)
94  m(i++) = nm_tkit_p.first;
95 
96  return m;
97  }
98 
99  void unload_all_toolkits (void)
100  {
101  while (! loaded_toolkits.empty ())
102  {
103  auto p = loaded_toolkits.begin ();
104 
105  std::string name = p->first;
106 
107  p->second.close ();
108 
109  // The toolkit may have unloaded itself. If not, we'll do it here.
110  if (loaded_toolkits.find (name) != loaded_toolkits.end ())
112  }
113  }
114 
115  std::string default_toolkit (void) const { return dtk; }
116 
117  private:
118 
119  // The name of the default toolkit.
120  std::string dtk;
121 
122  // The list of toolkits that we know about.
123  std::set<std::string> available_toolkits;
124 
125  // The list of toolkits we have actually loaded.
126  std::map<std::string, graphics_toolkit> loaded_toolkits;
127  };
128 }
129 
130 #endif
Definition: Cell.h:43
std::string get_name(void) const
void unregister_toolkit(const std::string &name)
Definition: gtk-manager.cc:85
void load_toolkit(const graphics_toolkit &tk)
Definition: gtk-manager.h:57
void unload_all_toolkits(void)
Definition: gtk-manager.h:99
graphics_toolkit find_toolkit(const std::string &name) const
Definition: gtk-manager.h:67
void register_toolkit(const std::string &name)
Definition: gtk-manager.cc:74
Cell loaded_toolkits_list(void) const
Definition: gtk-manager.h:88
Cell available_toolkits_list(void) const
Definition: gtk-manager.h:77
graphics_toolkit get_toolkit(void) const
Definition: gtk-manager.cc:39
void unload_toolkit(const std::string &name)
Definition: gtk-manager.h:62
std::map< std::string, graphics_toolkit > loaded_toolkits
Definition: gtk-manager.h:126
std::string default_toolkit(void) const
Definition: gtk-manager.h:115
std::set< std::string > available_toolkits
Definition: gtk-manager.h:123
octave::graphics_toolkit graphics_toolkit
QString name
T octave_idx_type m
Definition: mx-inlines.cc:773