GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
cdef-manager.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2012-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_cdef_manager_h)
27 #define octave_cdef_manager_h 1
28 
29 #include "octave-config.h"
30 
31 #include "cdef-class.h"
32 #include "cdef-fwd.h"
33 #include "cdef-method.h"
34 #include "cdef-package.h"
35 #include "cdef-property.h"
36 #include "ov-builtin.h"
37 
39 
40 class interpreter;
41 
42 class
43 OCTINTERP_API
45 {
46 public:
47 
48  OCTINTERP_API cdef_manager (interpreter& interp);
49 
50  // No copying!
51 
52  cdef_manager (const cdef_manager&) = delete;
53 
55 
56  ~cdef_manager (void) = default;
57 
58  OCTINTERP_API cdef_class
59  find_class (const std::string& name, bool error_if_not_found = true,
60  bool load_if_not_found = true);
61 
62  OCTINTERP_API octave_value
63  find_method_symbol (const std::string& method_name,
64  const std::string& class_name);
65 
66  OCTINTERP_API cdef_package
67  find_package (const std::string& name, bool error_if_not_found = true,
68  bool load_if_not_found = true);
69 
70  OCTINTERP_API octave_value
71  find_package_symbol (const std::string& pack_name);
72 
73  void register_class (const cdef_class& cls)
74  {
75  m_all_classes[cls.get_name ()] = cls;
76  }
77 
78  void unregister_class (const cdef_class& cls)
79  {
80  m_all_classes.erase(cls.get_name ());
81  }
82 
83  void register_package (const cdef_package& pkg)
84  {
85  m_all_packages[pkg.get_name ()] = pkg;
86  }
87 
88  void unregister_package (const cdef_package& pkg)
89  {
90  m_all_packages.erase (pkg.get_name ());
91  }
92 
93  const cdef_class& meta_class (void) const { return m_meta_class; }
94  const cdef_class& meta_property (void) const { return m_meta_property; }
95  const cdef_class& meta_method (void) const { return m_meta_method; }
96  const cdef_class& meta_package (void) const { return m_meta_package; }
97 
98  const cdef_package& meta (void) const { return m_meta; }
99 
100  OCTINTERP_API cdef_class
101  make_class (const std::string& name,
102  const std::list<cdef_class>& super_list = std::list<cdef_class> ());
103 
104  OCTINTERP_API cdef_class
105  make_class (const std::string& name, const cdef_class& super);
106 
107  OCTINTERP_API cdef_class
108  make_meta_class (const std::string& name, const cdef_class& super);
109 
110  OCTINTERP_API cdef_property
111  make_property (const cdef_class& cls, const std::string& name,
112  const octave_value& get_method = Matrix (),
113  const std::string& get_access = "public",
114  const octave_value& set_method = Matrix (),
115  const std::string& set_access = "public");
116 
117  OCTINTERP_API cdef_property
118  make_attribute (const cdef_class& cls, const std::string& name);
119 
120  OCTINTERP_API cdef_method
121  make_method (const cdef_class& cls, const std::string& name,
122  const octave_value& fcn,
123  const std::string& m_access = "public",
124  bool is_static = false);
125 
126  OCTINTERP_API cdef_method
127  make_method (const cdef_class& cls, const std::string& name,
129  const std::string& m_access = "public",
130  bool is_static = false);
131 
132  OCTINTERP_API cdef_method
133  make_method (const cdef_class& cls, const std::string& name,
135  const std::string& m_access = "public",
136  bool is_static = false);
137 
138  OCTINTERP_API cdef_package
139  make_package (const std::string& nm, const std::string& parent = "");
140 
141  OCTINTERP_API octave_value
142  find_method (const std::string& class_name,
143  const std::string& name) const;
144 
145 private:
146 
148 
149  // All registered/loaded classes
150  std::map<std::string, cdef_class> m_all_classes;
151 
152  // All registered/loaded packages
153  std::map<std::string, cdef_package> m_all_packages;
154 
159 
161 };
162 
164 
165 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: dMatrix.h:42
std::string get_name(void) const
Definition: cdef-class.h:322
~cdef_manager(void)=default
const cdef_package & meta(void) const
Definition: cdef-manager.h:98
cdef_manager(const cdef_manager &)=delete
cdef_class m_meta_method
Definition: cdef-manager.h:157
void unregister_package(const cdef_package &pkg)
Definition: cdef-manager.h:88
const cdef_class & meta_method(void) const
Definition: cdef-manager.h:95
const cdef_class & meta_property(void) const
Definition: cdef-manager.h:94
cdef_class m_meta_property
Definition: cdef-manager.h:156
void unregister_class(const cdef_class &cls)
Definition: cdef-manager.h:78
void register_package(const cdef_package &pkg)
Definition: cdef-manager.h:83
cdef_class m_meta_package
Definition: cdef-manager.h:158
const cdef_class & meta_package(void) const
Definition: cdef-manager.h:96
std::map< std::string, cdef_package > m_all_packages
Definition: cdef-manager.h:153
interpreter & m_interpreter
Definition: cdef-manager.h:147
const cdef_class & meta_class(void) const
Definition: cdef-manager.h:93
std::map< std::string, cdef_class > m_all_classes
Definition: cdef-manager.h:150
void register_class(const cdef_class &cls)
Definition: cdef-manager.h:73
cdef_class m_meta_class
Definition: cdef-manager.h:155
cdef_package m_meta
Definition: cdef-manager.h:160
std::string get_name(void) const
Definition: cdef-package.h:211
interpreter & operator=(const interpreter &)=delete
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:63
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:60
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn