GNU Octave  9.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-2024 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  OCTAVE_DISABLE_COPY_MOVE (cdef_manager)
51 
52  ~cdef_manager () = default;
53 
54  OCTINTERP_API cdef_class
55  find_class (const std::string& name, bool error_if_not_found = true,
56  bool load_if_not_found = true);
57 
58  OCTINTERP_API octave_value
59  find_method_symbol (const std::string& method_name,
60  const std::string& class_name);
61 
62  OCTINTERP_API cdef_package
63  find_package (const std::string& name, bool error_if_not_found = true,
64  bool load_if_not_found = true);
65 
66  OCTINTERP_API octave_value
67  find_package_symbol (const std::string& pack_name);
68 
69  void register_class (const cdef_class& cls)
70  {
71  m_all_classes[cls.get_name ()] = cls;
72  }
73 
74  void unregister_class (const cdef_class& cls)
75  {
76  m_all_classes.erase(cls.get_name ());
77  }
78 
79  void register_package (const cdef_package& pkg)
80  {
81  m_all_packages[pkg.get_name ()] = pkg;
82  }
83 
84  void unregister_package (const cdef_package& pkg)
85  {
86  m_all_packages.erase (pkg.get_name ());
87  }
88 
89  const cdef_class& meta_class () const { return m_meta_class; }
90  const cdef_class& meta_property () const { return m_meta_property; }
91  const cdef_class& meta_method () const { return m_meta_method; }
92  const cdef_class& meta_package () const { return m_meta_package; }
93 
94  const cdef_package& meta () const { return m_meta; }
95 
96  OCTINTERP_API cdef_class
97  make_class (const std::string& name,
98  const std::list<cdef_class>& super_list = std::list<cdef_class> ());
99 
100  OCTINTERP_API cdef_class
101  make_class (const std::string& name, const cdef_class& super);
102 
103  OCTINTERP_API cdef_class
104  make_meta_class (const std::string& name, const cdef_class& super);
105 
106  OCTINTERP_API cdef_property
107  make_property (const cdef_class& cls, const std::string& name,
108  const octave_value& get_method = Matrix (),
109  const std::string& get_access = "public",
110  const octave_value& set_method = Matrix (),
111  const std::string& set_access = "public");
112 
113  OCTINTERP_API cdef_property
114  make_attribute (const cdef_class& cls, const std::string& name);
115 
116  OCTINTERP_API cdef_method
117  make_method (const cdef_class& cls, const std::string& name,
118  const octave_value& fcn,
119  const std::string& m_access = "public",
120  bool is_static = false);
121 
122  OCTINTERP_API cdef_method
123  make_method (const cdef_class& cls, const std::string& name,
125  const std::string& m_access = "public",
126  bool is_static = false);
127 
128  OCTINTERP_API cdef_method
129  make_method (const cdef_class& cls, const std::string& name,
131  const std::string& m_access = "public",
132  bool is_static = false);
133 
134  OCTINTERP_API cdef_package
135  make_package (const std::string& nm, const std::string& parent = "");
136 
137  OCTINTERP_API octave_value
138  find_method (const std::string& class_name,
139  const std::string& name) const;
140 
141 private:
142 
143  interpreter& m_interpreter;
144 
145  // All registered/loaded classes
146  std::map<std::string, cdef_class> m_all_classes;
147 
148  // All registered/loaded packages
149  std::map<std::string, cdef_package> m_all_packages;
150 
151  cdef_class m_meta_class;
152  cdef_class m_meta_property;
153  cdef_class m_meta_method;
154  cdef_class m_meta_package;
155 
156  cdef_package m_meta;
157 };
158 
159 OCTAVE_END_NAMESPACE(octave)
160 
161 #endif
Definition: dMatrix.h:42
std::string get_name() const
Definition: cdef-class.h:318
~cdef_manager()=default
const cdef_package & meta() const
Definition: cdef-manager.h:94
const cdef_class & meta_method() const
Definition: cdef-manager.h:91
const cdef_class & meta_property() const
Definition: cdef-manager.h:90
void unregister_package(const cdef_package &pkg)
Definition: cdef-manager.h:84
void unregister_class(const cdef_class &cls)
Definition: cdef-manager.h:74
void register_package(const cdef_package &pkg)
Definition: cdef-manager.h:79
const cdef_class & meta_class() const
Definition: cdef-manager.h:89
void register_class(const cdef_class &cls)
Definition: cdef-manager.h:69
const cdef_class & meta_package() const
Definition: cdef-manager.h:92
std::string get_name() const
Definition: cdef-package.h:211
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