GNU Octave  8.1.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-2023 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 
39 
40 class OCTINTERP_API gtk_manager
41 {
42 public:
43 
44  gtk_manager (void) { }
45 
46  ~gtk_manager (void)
47  {
48  unload_all_toolkits ();
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  m_loaded_toolkits[tk.get_name ()] = tk;
60  }
61 
62  void unload_toolkit (const std::string& name)
63  {
64  m_loaded_toolkits.erase (name);
65  }
66 
67  graphics_toolkit find_toolkit (const std::string& name) const
68  {
69  auto p = m_loaded_toolkits.find (name);
70 
71  if (p != m_loaded_toolkits.end ())
72  return p->second;
73  else
74  return graphics_toolkit ();
75  }
76 
78  {
79  Cell m (1, m_available_toolkits.size ());
80 
81  octave_idx_type i = 0;
82  for (const auto& tkit : m_available_toolkits)
83  m(i++) = tkit;
84 
85  return m;
86  }
87 
89  {
90  Cell m (1, m_loaded_toolkits.size ());
91 
92  octave_idx_type i = 0;
93  for (const auto& nm_tkit_p : m_loaded_toolkits)
94  m(i++) = nm_tkit_p.first;
95 
96  return m;
97  }
98 
99  void unload_all_toolkits (void)
100  {
101  while (! m_loaded_toolkits.empty ())
102  {
103  auto p = m_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 (m_loaded_toolkits.find (name) != m_loaded_toolkits.end ())
111  unload_toolkit (name);
112  }
113  }
114 
115  std::string default_toolkit (void) const { return m_dtk; }
116 
117 private:
118 
119  // The name of the default toolkit.
120  std::string m_dtk;
121 
122  // The list of toolkits that we know about.
123  std::set<std::string> m_available_toolkits;
124 
125  // The list of toolkits we have actually loaded.
126  std::map<std::string, graphics_toolkit> m_loaded_toolkits;
127 };
128 
130 
131 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: Cell.h:43
std::string get_name(void) const
std::string default_toolkit(void) const
Definition: gtk-manager.h:115
void load_toolkit(const graphics_toolkit &tk)
Definition: gtk-manager.h:57
gtk_manager(void)
Definition: gtk-manager.h:44
void unload_all_toolkits(void)
Definition: gtk-manager.h:99
~gtk_manager(void)
Definition: gtk-manager.h:46
Cell available_toolkits_list(void) const
Definition: gtk-manager.h:77
std::map< std::string, graphics_toolkit > m_loaded_toolkits
Definition: gtk-manager.h:126
std::string m_dtk
Definition: gtk-manager.h:120
Cell loaded_toolkits_list(void) const
Definition: gtk-manager.h:88
void unload_toolkit(const std::string &name)
Definition: gtk-manager.h:62
graphics_toolkit find_toolkit(const std::string &name) const
Definition: gtk-manager.h:67
std::set< std::string > m_available_toolkits
Definition: gtk-manager.h:123
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
T octave_idx_type m
Definition: mx-inlines.cc:773