GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-classdef.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2025 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_classdef_h)
27#define octave_classdef_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "cdef-object.h"
34#include "ov-base.h"
35#include "ov-fcn.h"
36
38
39class cdef_object;
40class interpreter;
41class tree_evaluator;
42class type_info;
43
44OCTAVE_END_NAMESPACE(octave)
45
47{
48public:
49
51 : octave_base_value (), m_object () { }
52
53 octave_classdef (const octave::cdef_object& obj)
54 : octave_base_value (), m_object (obj) { }
55
56 OCTAVE_DISABLE_COPY_MOVE (octave_classdef)
57
58 ~octave_classdef () = default;
59
61 {
62 return new octave_classdef (m_object.clone ());
63 }
64
66 {
67 return new octave_classdef (m_object.empty_clone ());
68 }
69
70 octave_classdef * classdef_object_value (bool = false) { return this; }
71
72 octave::cdef_object get_object () const { return m_object; }
73
74 octave::cdef_object& get_object_ref () { return m_object; }
75
76 bool is_defined () const { return true; }
77
78 bool isstruct () const { return false; }
79
80 bool isobject () const { return true; }
81
82 bool is_classdef_object () const { return true; }
83
84 OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false);
85
86 OCTINTERP_API void
87 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
88
89 OCTINTERP_API bool is_instance_of (const std::string& cls_name) const;
90
91 void break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame)
92 {
93 m_object.break_closure_cycles (frame);
94 }
95
96 OCTINTERP_API octave_value_list
97 subsref (const std::string& type, const std::list<octave_value_list>& idx,
98 int nargout);
99
100 octave_value subsref (const std::string& type,
101 const std::list<octave_value_list>& idx)
102 {
103 octave_value_list retval = subsref (type, idx, 1);
104 return (retval.length () > 0 ? retval(0) : octave_value ());
105 }
106
107 OCTINTERP_API octave_value
108 subsref (const std::string& type, const std::list<octave_value_list>& idx,
109 bool auto_add);
110
111 OCTINTERP_API octave_value
112 subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
113 const octave_value& rhs);
114
115 OCTINTERP_API octave_value
116 undef_subsasgn (const std::string& type,
117 const std::list<octave_value_list>& idx,
118 const octave_value& rhs);
119
120 OCTINTERP_API Matrix size ();
121
122 OCTINTERP_API octave_idx_type xnumel (const octave_value_list&);
123
124 string_vector map_keys () const { return m_object.map_keys (); }
125
126 octave_map map_value () const { return m_object.map_value (); }
127
128 dim_vector dims () const { return m_object.dims (); }
129
130 void set_property (octave_idx_type idx, const std::string& name,
131 const octave_value& pval)
132 {
133 m_object.set_property (idx, name, pval);
134 }
135
137 get_property (octave_idx_type idx, const std::string& name) const
138 {
139 return m_object.get_property (idx, name);
140 }
141
142 static OCTINTERP_API octave_value
143 superclass_ref (const std::string& meth, const std::string& cls);
144
145 static OCTINTERP_API octave_value metaclass_query (const std::string& cls);
146
147public:
148
149 int type_id () const { return s_t_id; }
150 std::string type_name () const { return s_t_name; }
151 std::string class_name () const { return m_object.class_name (); }
152
153 static int static_type_id () { return s_t_id; }
154 static std::string static_type_name () { return s_t_name; }
155 static std::string static_class_name () { return "<unknown>"; }
156 static OCTINTERP_API void register_type (octave::type_info&);
157
158private:
159
160 octave::cdef_object m_object;
161
162 static int s_t_id;
163
164 static const std::string s_t_name;
165};
166
167void install_classdef (octave::interpreter& interp);
168
170{
171public:
172
173 octave_classdef_meta (const octave::cdef_meta_object& obj)
174 : m_object (obj)
175 { }
176
177 OCTAVE_DISABLE_COPY_MOVE (octave_classdef_meta)
178
179 ~octave_classdef_meta () { m_object.meta_release (); }
180
181 bool is_classdef_meta () const { return true; }
182
183 bool is_package () const { return m_object.is_package(); }
184
185 octave_function * function_value (bool = false) { return this; }
186
187 // We don't need to override all three forms of subsref. The using
188 // declaration will avoid warnings about partially-overloaded virtual
189 // functions.
191
193 subsref (const std::string& type,
194 const std::list<octave_value_list>& idx,
195 int nargout)
196 {
197 return m_object.meta_subsref (type, idx, nargout);
198 }
199
200 // Override default call method because we don't push a new stack
201 // frame for this operation on classdef_meta objects.
202
203 octave_value_list call (octave::tree_evaluator& tw, int nargout,
204 const octave_value_list& args)
205 {
206 return execute (tw, nargout, args);
207 }
208
209 octave_value_list execute (octave::tree_evaluator&, int nargout,
210 const octave_value_list& args)
211 {
212 // Emulate ()-type meta subsref
213
214 std::list<octave_value_list> idx (1, args);
215 std::string type ("(");
216
217 return subsref (type, idx, nargout);
218 }
219
220 bool accepts_postfix_index (char type) const
221 { return m_object.meta_accepts_postfix_index (type); }
222
223 OCTINTERP_API bool is_classdef_method (const std::string& cname = "") const;
224
225 OCTINTERP_API bool
226 is_classdef_constructor (const std::string& cname = "") const;
227
228 OCTINTERP_API std::string doc_string (const std::string& meth_name) const;
229
230 OCTINTERP_API std::string file_name () const;
231
232private:
233
234 octave::cdef_meta_object m_object;
235};
236
238{
239public:
241
242 octave_classdef_superclass_ref (const std::string& meth,
243 const std::string& cls)
244 : octave_function (), m_method_name (meth), m_class_name (cls)
245 { }
246
247 OCTAVE_DISABLE_COPY_MOVE (octave_classdef_superclass_ref)
248
250
251 bool is_classdef_superclass_ref () const { return true; }
252
253 octave_function * function_value (bool = false) { return this; }
254
255 // Override default call method because we don't push a new stack
256 // frame for this operation on classdef_superclass_ref objects.
257
258 octave_value_list call (octave::tree_evaluator& tw, int nargout,
259 const octave_value_list& args)
260 {
261 return execute (tw, nargout, args);
262 }
263
264 OCTINTERP_API octave_value_list
265 execute (octave::tree_evaluator& tw, int nargout,
266 const octave_value_list& idx);
267
268private:
269
270 OCTINTERP_API bool
271 is_constructed_object (octave::tree_evaluator& tw, const std::string& nm);
272
273private:
274
275 std::string m_method_name;
276 std::string m_class_name;
277};
278
279#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition ov-base.cc:245
octave_value_list call(octave::tree_evaluator &tw, int nargout, const octave_value_list &args)
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
bool is_classdef_method(const std::string &cname="") const
bool accepts_postfix_index(char type) const
octave_classdef_meta(const octave::cdef_meta_object &obj)
std::string file_name() const
bool is_classdef_constructor(const std::string &cname="") const
std::string doc_string(const std::string &meth_name) const
octave_function * function_value(bool=false)
bool is_classdef_meta() const
bool is_package() const
octave_value_list execute(octave::tree_evaluator &, int nargout, const octave_value_list &args)
bool is_classdef_superclass_ref() const
octave_value_list call(octave::tree_evaluator &tw, int nargout, const octave_value_list &args)
octave_value_list execute(octave::tree_evaluator &tw, int nargout, const octave_value_list &idx)
octave_function * function_value(bool=false)
octave_classdef_superclass_ref(const std::string &meth, const std::string &cls)
octave_classdef * classdef_object_value(bool=false)
Definition ov-classdef.h:70
octave_base_value * empty_clone() const
Definition ov-classdef.h:65
static std::string static_class_name()
octave_map map_value() const
void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &frame)
Definition ov-classdef.h:91
octave_value get_property(octave_idx_type idx, const std::string &name) const
dim_vector dims() const
octave_classdef(const octave::cdef_object &obj)
Definition ov-classdef.h:53
octave::cdef_object & get_object_ref()
Definition ov-classdef.h:74
octave_base_value * clone() const
Definition ov-classdef.h:60
bool isstruct() const
Definition ov-classdef.h:78
bool is_classdef_object() const
Definition ov-classdef.h:82
octave::cdef_object get_object() const
Definition ov-classdef.h:72
static std::string static_type_name()
bool is_defined() const
Definition ov-classdef.h:76
static int static_type_id()
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
std::string type_name() const
std::string class_name() const
void set_property(octave_idx_type idx, const std::string &name, const octave_value &pval)
string_vector map_keys() const
bool isobject() const
Definition ov-classdef.h:80
~octave_classdef()=default
int type_id() const
octave_idx_type length() const
Definition ovl.h:111
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void install_classdef(octave::interpreter &interp)
int register_type(const std::string &t_name, const std::string &c_name, const octave_value &val)