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