1 //////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (C) 2012-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_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-method.h" 33 #include "cdef-package.h" 34 #include "cdef-property.h" 35 #include "ov-builtin.h" 36 37 namespace octave 38 { 39 class interpreter; 40 41 class cdef_manager 42 { 43 public: 44 45 cdef_manager (interpreter& interp); 46 47 // No copying! 48 49 cdef_manager (const cdef_manager&) = delete; 50 51 cdef_manager& operator = (const cdef_manager&) = delete; 52 53 ~cdef_manager (void) = default; 54 55 cdef_class find_class (const std::string& name, 56 bool error_if_not_found = true, 57 bool load_if_not_found = true); 58 59 octave_value find_method_symbol (const std::string& method_name, 60 const std::string& class_name); 61 62 cdef_package find_package (const std::string& name, 63 bool error_if_not_found = true, 64 bool load_if_not_found = true); 65 66 octave_value find_package_symbol (const std::string& pack_name); 67 register_class(const cdef_class & cls)68 void register_class (const cdef_class& cls) 69 { 70 m_all_classes[cls.get_name ()] = cls; 71 } 72 unregister_class(const cdef_class & cls)73 void unregister_class (const cdef_class& cls) 74 { 75 m_all_classes.erase(cls.get_name ()); 76 } 77 register_package(const cdef_package & pkg)78 void register_package (const cdef_package& pkg) 79 { 80 m_all_packages[pkg.get_name ()] = pkg; 81 } 82 unregister_package(const cdef_package & pkg)83 void unregister_package (const cdef_package& pkg) 84 { 85 m_all_packages.erase (pkg.get_name ()); 86 } 87 meta_class(void)88 const cdef_class& meta_class (void) const { return m_meta_class; } meta_property(void)89 const cdef_class& meta_property (void) const { return m_meta_property; } meta_method(void)90 const cdef_class& meta_method (void) const { return m_meta_method; } meta_package(void)91 const cdef_class& meta_package (void) const { return m_meta_package; } 92 meta(void)93 const cdef_package& meta (void) const { return m_meta; } 94 95 cdef_class make_class (const std::string& name, 96 const std::list<cdef_class>& super_list = std::list<cdef_class> ()); 97 98 cdef_class make_class (const std::string& name, const cdef_class& super); 99 100 cdef_class make_meta_class (const std::string& name, 101 const cdef_class& super); 102 103 cdef_property make_property (const cdef_class& cls, 104 const std::string& name, 105 const octave_value& get_method = Matrix (), 106 const std::string& get_access = "public", 107 const octave_value& set_method = Matrix (), 108 const std::string& set_access = "public"); 109 110 cdef_property make_attribute (const cdef_class& cls, 111 const std::string& name); 112 113 cdef_method make_method (const cdef_class& cls, 114 const std::string& name, 115 const octave_value& fcn, 116 const std::string& m_access = "public", 117 bool is_static = false); 118 119 cdef_method make_method (const cdef_class& cls, 120 const std::string& name, 121 octave_builtin::fcn ff, 122 const std::string& m_access = "public", 123 bool is_static = false); 124 125 cdef_method make_method (const cdef_class& cls, 126 const std::string& name, 127 octave_builtin::meth mm, 128 const std::string& m_access = "public", 129 bool is_static = false); 130 131 cdef_package make_package (const std::string& nm, 132 const std::string& parent = ""); 133 134 octave_value find_method (const std::string& class_name, 135 const std::string& name) const; 136 137 private: 138 139 interpreter& m_interpreter; 140 141 // All registered/loaded classes 142 std::map<std::string, cdef_class> m_all_classes; 143 144 // All registered/loaded packages 145 std::map<std::string, cdef_package> m_all_packages; 146 147 cdef_class m_meta_class; 148 cdef_class m_meta_property; 149 cdef_class m_meta_method; 150 cdef_class m_meta_package; 151 152 cdef_package m_meta; 153 }; 154 } 155 156 #endif 157