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