Mercurial > octave
annotate libinterp/octave-value/ov-classdef.cc @ 33639:65b1cf6aa60a bytecode-interpreter tip
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Mon, 03 Jun 2024 14:38:47 -0400 |
parents | 976638dd9021 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
3 // Copyright (C) 2012-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 #endif |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
29 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
30 #include <algorithm> |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
31 #include <iomanip> |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
32 |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
26769
diff
changeset
|
33 #include "cdef-class.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
26769
diff
changeset
|
34 #include "cdef-method.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
26769
diff
changeset
|
35 #include "cdef-package.h" |
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
26769
diff
changeset
|
36 #include "cdef-property.h" |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
37 #include "cdef-utils.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
38 #include "defun.h" |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
39 #include "errwarn.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
40 #include "interpreter-private.h" |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
41 #include "load-path.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 #include "ov-classdef.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
43 #include "ov-fcn-handle.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
44 #include "ov-typeinfo.h" |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
45 #include "ov-usr-fcn.h" |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
46 #include "parse.h" |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
47 #include "pr-output.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
48 #include "pt-eval.h" |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
49 #include "pt-misc.h" |
29314
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
50 #include "oct-lvalue.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
51 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
52 static bool |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
53 in_class_method (const octave::cdef_class& cls) |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
54 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
55 octave::cdef_class ctx = octave::get_class_context (); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
56 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
57 return (ctx.ok () && octave::is_superclass (ctx, cls)); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
58 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
59 |
31845
2da025d5e98d
maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents:
31814
diff
changeset
|
60 int octave_classdef::s_t_id (-1); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
61 |
31845
2da025d5e98d
maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents:
31814
diff
changeset
|
62 const std::string octave_classdef::s_t_name ("object"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
63 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
64 void |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
65 octave_classdef::register_type (octave::type_info& ti) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
66 { |
31845
2da025d5e98d
maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents:
31814
diff
changeset
|
67 s_t_id = ti.register_type (octave_classdef::s_t_name, "<unknown>", |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
68 octave_value (new octave_classdef ())); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
69 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
70 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
71 octave_value_list |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
72 octave_classdef::subsref (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
73 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
74 int nargout) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
75 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
76 std::size_t skip = 0; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
77 octave_value_list retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
78 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
79 octave::cdef_class cls = m_object.get_class (); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
80 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
81 if (! in_class_method (cls) && ! called_from_builtin ()) |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
82 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
83 octave::cdef_method meth = cls.find_method ("subsref"); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
84 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
85 if (meth.ok ()) |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
86 { |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
87 octave_value_list args; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
88 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
89 args(1) = make_idx_args (type, idx, "subsref"); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
90 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
91 m_count++; |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
92 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
93 |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
94 // If the number of output arguments is unknown, attempt to set up |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
95 // a proper value for nargout at least in the simple case where the |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
96 // cs-list-type expression - i.e., {} or ().x, is the leading one. |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
97 if (nargout <= 0) |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
98 { |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
99 bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{' |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
100 || (type.length () > 1 && type[0] == '(' |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
101 && type[1] == '.')); |
31652
a18897e4c7b5
classdef: call subsref method with correct nargout value (bug #48693)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
31607
diff
changeset
|
102 |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
103 if (maybe_cs_list_query) |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
104 { |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
105 // Set up a proper nargout for the subsref call by calling numel. |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
106 octave_value_list tmp; |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
107 int nout; |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
108 if (type[0] != '.') tmp = idx.front (); |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
109 nout = xnumel (tmp); |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
110 if (nargout != 0 || nout > 1) |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
111 nargout = nout; |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
112 } |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
113 else if (nargout < 0) |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
114 nargout = 1; |
31652
a18897e4c7b5
classdef: call subsref method with correct nargout value (bug #48693)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
31607
diff
changeset
|
115 } |
a18897e4c7b5
classdef: call subsref method with correct nargout value (bug #48693)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
31607
diff
changeset
|
116 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
117 retval = meth.execute (args, nargout, true, "subsref"); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
118 |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
119 // Since we're handling subsref, if the list has more than one element |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
120 // and the caller to subsref accepts more that one output, return |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
121 // the elements as a comma-separated list so that we can pass it to the |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
122 // evaluator |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
123 if (retval.length () > 1 && (nargout < 0 || nargout > 1)) |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
124 { |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
125 if (nargout <= 0 || nargout >= retval.length ()) |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
126 // Take the whole list |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
127 retval = octave_value (retval); |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
128 else |
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
129 // Take nargout elements of the list |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
130 retval = octave_value (retval.slice (0, nargout)); |
32410
554a932fc6d0
Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
32057
diff
changeset
|
131 } |
31652
a18897e4c7b5
classdef: call subsref method with correct nargout value (bug #48693)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
31607
diff
changeset
|
132 |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
133 return retval; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
134 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
135 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
136 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
137 // At this point, the default subsref mechanism must be used. |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
138 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
139 retval = m_object.subsref (type, idx, nargout, skip, octave::cdef_class ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
140 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
141 if (type.length () > skip && idx.size () > skip) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
142 retval = retval(0).next_subsref (nargout, type, idx, skip); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
143 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
144 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
145 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
146 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
147 octave_value |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
148 octave_classdef::subsref (const std::string& type, |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
149 const std::list<octave_value_list>& idx, |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
150 bool auto_add) |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
151 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
152 std::size_t skip = 0; |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
153 octave_value_list retval; |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
154 |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
155 // This variant of subsref is used to create temporary values when doing |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
156 // assignment with multi-level indexing. AFAIK this is only used for internal |
26757
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
157 // purpose (not sure we should even implement this). |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
158 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
159 octave::cdef_class cls = m_object.get_class (); |
26757
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
160 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
161 if (! in_class_method (cls)) |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
162 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
163 octave::cdef_method meth = cls.find_method ("subsref"); |
26757
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
164 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
165 if (meth.ok ()) |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
166 { |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
167 octave_value_list args; |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
168 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
169 args(1) = make_idx_args (type, idx, "subsref"); |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
170 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
171 m_count++; |
26757
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
172 args(0) = octave_value (this); |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
173 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
174 retval = meth.execute (args, 1, true, "subsref"); |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
175 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
176 return retval.length () > 0 ? retval(0) : octave_value (); |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
177 } |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
178 } |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
179 |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30259
diff
changeset
|
180 retval = m_object.subsref (type, idx, 1, skip, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30259
diff
changeset
|
181 octave::cdef_class (), auto_add); |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
182 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
183 if (type.length () > skip && idx.size () > skip) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
184 retval = retval(0).next_subsref (1, type, idx, skip); |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
185 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
186 return retval.length () > 0 ? retval(0) : octave_value (); |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
187 } |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
188 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
189 octave_value |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
190 octave_classdef::subsasgn (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
191 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
192 const octave_value& rhs) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
193 { |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
194 octave_value retval; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
195 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
196 octave::cdef_class cls = m_object.get_class (); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
197 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
198 if (! in_class_method (cls) && ! called_from_builtin ()) |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
199 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
200 octave::cdef_method meth = cls.find_method ("subsasgn"); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
201 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
202 if (meth.ok ()) |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
203 { |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
204 octave_value_list args; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
205 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
206 args(1) = make_idx_args (type, idx, "subsasgn"); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
207 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
208 m_count++; |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
209 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
210 args(2) = rhs; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
211 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
212 octave_value_list retlist; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
213 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
214 retlist = meth.execute (args, 1, true, "subsasgn"); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
215 |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
216 if (retlist.empty ()) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
217 error ("overloaded method 'subsasgn' did not return any value"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
218 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
219 retval = retlist(0); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
220 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
221 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
222 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
223 if (! retval.is_defined ()) |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
224 retval = m_object.subsasgn (type, idx, rhs); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
225 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
226 return retval; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
227 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
228 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
229 octave_value |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
230 octave_classdef::undef_subsasgn (const std::string& type, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
231 const std::list<octave_value_list>& idx, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
232 const octave_value& rhs) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
233 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
234 if (type.length () == 1 && type[0] == '(') |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
235 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
236 m_object = m_object.make_array (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
237 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
238 return subsasgn (type, idx, rhs); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
239 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
240 else |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
241 return octave_base_value::undef_subsasgn (type, idx, rhs); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
242 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
243 return octave_value (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
244 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
245 |
28072
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
246 Matrix |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31707
diff
changeset
|
247 octave_classdef::size () |
28072
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
248 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
249 octave::cdef_class cls = m_object.get_class (); |
28072
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
250 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
251 if (! in_class_method (cls) && ! called_from_builtin ()) |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
252 { |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
253 octave::cdef_method meth = cls.find_method ("size"); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
254 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
255 if (meth.ok ()) |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
256 { |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
257 m_count++; |
28072
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
258 octave_value_list args (1, octave_value (this)); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
259 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
260 octave_value_list lv = meth.execute (args, 1, true, "size"); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
261 if (lv.length () <= 0 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
262 || ! lv(0).is_matrix_type () || ! lv(0).dims ().isvector ()) |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
263 error ("%s.size: invalid return value", class_name ().c_str ()); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
264 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
265 return lv(0).matrix_value (); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
266 } |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
267 } |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
268 |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
269 return octave_base_value::size (); |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
270 } |
47238792de58
provide default size method for classdef objects
John W. Eaton <jwe@octave.org>
parents:
27932
diff
changeset
|
271 |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
272 octave_idx_type |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26778
diff
changeset
|
273 octave_classdef::xnumel (const octave_value_list& idx) |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
274 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
275 octave_idx_type retval = -1; |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
276 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
277 octave::cdef_class cls = m_object.get_class (); |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
278 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
279 if (! in_class_method (cls) && ! called_from_builtin ()) |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
280 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
281 octave::cdef_method meth = cls.find_method ("numel"); |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
282 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
283 if (meth.ok ()) |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
284 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
285 octave_value_list args (idx.length () + 1, octave_value ()); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
286 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
287 m_count++; |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
288 args(0) = octave_value (this); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
289 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
290 for (octave_idx_type i = 0; i < idx.length (); i++) |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
291 args(i+1) = idx(i); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
292 |
29314
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
293 // Temporarily set lvalue list of current statement to NULL, to avoid |
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
294 // using that list for the execution of the method "numel" |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30888
diff
changeset
|
295 octave::interpreter& interp = octave::__get_interpreter__ (); |
29314
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
296 octave::tree_evaluator& tw = interp.get_evaluator(); |
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
297 |
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
298 octave::unwind_action act ([&tw] (const std::list<octave::octave_lvalue> *lvl) |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
299 { |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
300 tw.set_lvalue_list (lvl); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
301 }, tw.lvalue_list ()); |
29314
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
302 tw.set_lvalue_list (nullptr); |
67857e94604a
Temporarily set lvalue list to null (bug #59704).
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents:
28515
diff
changeset
|
303 |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
304 octave_value_list lv = meth.execute (args, 1, true, "numel"); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
305 if (lv.length () != 1 || ! lv(0).is_scalar_type ()) |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
306 error ("@%s/numel: invalid return value", cls.get_name ().c_str ()); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
307 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
308 retval = lv(0).idx_type_value (true); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
309 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
310 return retval; |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
311 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
312 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
313 |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26778
diff
changeset
|
314 retval = octave_base_value::xnumel (idx); |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
315 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
316 return retval; |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
317 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
318 |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
319 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
320 octave_classdef::print (std::ostream& os, bool) |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
321 { |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
322 print_raw (os); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
323 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
324 |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
325 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
326 octave_classdef::print_raw (std::ostream& os, bool) const |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
327 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
328 octave::cdef_class cls = m_object.get_class (); |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
329 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
330 if (cls.ok ()) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
331 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
332 bool is_array = m_object.is_array (); |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
333 |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
334 increment_indent_level (); |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
335 |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
336 indent (os); |
29893
421e4913d8a4
print "object" not "m_object" for default classdef object display (bug #60938)
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
337 os << class_name () << " object"; |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
338 if (is_array) |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
339 os << " array"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
340 os << " with properties:"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
341 newline (os); |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
342 if (! Vcompact_format) |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
343 newline (os); |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
344 |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
345 increment_indent_level (); |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
346 |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
347 std::map<std::string, octave::cdef_property> property_map |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
348 = cls.get_property_map (); |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
349 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
350 std::size_t max_len = 0; |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
351 for (const auto& pname_prop : property_map) |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
352 { |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
353 // FIXME: this loop duplicates a significant portion of the |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
354 // loop below and the loop in Fproperties. |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
355 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
356 const octave::cdef_property& prop = pname_prop.second; |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
357 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
358 const std::string nm = prop.get_name (); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
359 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
360 octave_value acc = prop.get ("GetAccess"); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
361 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
362 if (! acc.is_string () || acc.string_value () != "public") |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
363 continue; |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
364 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
365 octave_value hid = prop.get ("Hidden"); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
366 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
367 if (hid.bool_value ()) |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
368 continue; |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
369 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
370 std::size_t sz = nm.size (); |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
371 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
372 if (sz > max_len) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
373 max_len = sz; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
374 } |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
375 |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
376 for (auto& pname_prop : property_map) |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
377 { |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
378 const octave::cdef_property& prop = pname_prop.second; |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
379 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
380 const std::string nm = prop.get_name (); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
381 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
382 octave_value acc = prop.get ("GetAccess"); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
383 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
384 if (! acc.is_string () || acc.string_value () != "public") |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
385 continue; |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
386 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
387 octave_value hid = prop.get ("Hidden"); |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
388 |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
389 if (hid.bool_value ()) |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
390 continue; |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
391 |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
392 indent (os); |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
393 |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
394 if (is_array) |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
395 os << " " << nm; |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
396 else |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
397 { |
33450
f86b8eb0c654
improve default display of classdef properties (bug #62432)
John W. Eaton <jwe@octave.org>
parents:
32862
diff
changeset
|
398 os << std::setw (max_len+2) << nm << ": "; |
f86b8eb0c654
improve default display of classdef properties (bug #62432)
John W. Eaton <jwe@octave.org>
parents:
32862
diff
changeset
|
399 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
400 octave_value val = prop.get_value (m_object, false); |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
401 |
33590
976638dd9021
Show ellipsis at end of long arrays for short_disp (bug #65637).
John W. Eaton <jwe@octave.org>
parents:
33451
diff
changeset
|
402 val.short_disp (os); |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
403 } |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
404 |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
405 newline (os); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
406 } |
27072
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
407 |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
408 decrement_indent_level (); |
1ccb40372115
fix printing of object arrays broken by changeset 2c4ad1958cab
John W. Eaton <jwe@octave.org>
parents:
27000
diff
changeset
|
409 decrement_indent_level (); |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
410 } |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
411 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
412 |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
413 bool |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
414 octave_classdef::is_instance_of (const std::string& cls_name) const |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
415 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
416 octave::cdef_class cls = octave::lookup_class (cls_name, false, false); |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
417 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
418 if (cls.ok ()) |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
419 return is_superclass (cls, m_object.get_class ()); |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
420 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
421 return false; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
422 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
423 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
424 octave_value |
26718
9b0335f4bc74
revise naming of the parts of a superclass reference
John W. Eaton <jwe@octave.org>
parents:
26686
diff
changeset
|
425 octave_classdef::superclass_ref (const std::string& meth, |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
426 const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
427 { |
26718
9b0335f4bc74
revise naming of the parts of a superclass reference
John W. Eaton <jwe@octave.org>
parents:
26686
diff
changeset
|
428 return octave_value (new octave_classdef_superclass_ref (meth, cls)); |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
429 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
430 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
431 octave_value |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
432 octave_classdef::metaclass_query (const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
433 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
434 return octave::to_ov (octave::lookup_class (cls)); |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
435 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
436 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
437 bool |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
438 octave_classdef_meta::is_classdef_method (const std::string& cname) const |
28438
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
439 { |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
440 bool retval = false; |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
441 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
442 if (m_object.is_method ()) |
28438
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
443 { |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
444 if (cname.empty ()) |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
445 retval = true; |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
446 else |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
447 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
448 octave::cdef_method meth (m_object); |
28438
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
449 |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
450 return meth.is_defined_in_class (cname); |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
451 } |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
452 } |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
453 |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
454 return retval; |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
455 } |
55f82d23fe5e
new octave_classdef_meta::is_classdef_method function
John W. Eaton <jwe@octave.org>
parents:
28429
diff
changeset
|
456 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
457 bool |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
458 octave_classdef_meta::is_classdef_constructor (const std::string& cname) const |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
459 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
460 bool retval = false; |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
461 |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
462 if (m_object.is_class ()) |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
463 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
464 if (cname.empty ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
465 retval = true; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
466 else |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
467 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
468 octave::cdef_class cls (m_object); |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
469 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
470 if (cls.get_name () == cname) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
471 retval = true; |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
472 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
473 } |
32862
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
474 else if (m_object.is_method ()) |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
475 { |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
476 octave::cdef_method meth (m_object); |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
477 |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
478 if (meth.is_constructor ()) |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
479 { |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
480 std::string meth_name = meth.get_name (); |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
481 |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
482 // Only consider METH to be a constructor if the dispatch |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
483 // class CNAME is the same as or derived from the class of |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
484 // METH. |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
485 |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
486 if (cname == meth_name) |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
487 retval = true; |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
488 else |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
489 { |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
490 octave::cdef_class meth_cls = octave::lookup_class (meth_name, false, false); |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
491 octave::cdef_class dispatch_cls = octave::lookup_class (cname, false, false); |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
492 |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
493 retval = octave::is_superclass (meth_cls, dispatch_cls); |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
494 } |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
495 } |
833f3d9bdf1a
Don't treat parent class constructor as inherited class method (bug #65037)
John W. Eaton <jwe@octave.org>
parents:
32632
diff
changeset
|
496 } |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
497 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
498 return retval; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
499 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
500 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
501 std::string |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
502 octave_classdef_meta::doc_string (const std::string& meth_name) const |
28514
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
503 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
504 if (m_object.is_class ()) |
28514
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
505 { |
29466
7c8a70e4daad
use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
506 octave::cdef_class cls (m_object); |
28514
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
507 |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
508 if (meth_name.empty ()) |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
509 return cls.doc_string (); |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
510 |
28515
49f4d7814760
find help for not-yet-loaded classdef methods defined in @DIR files.
John W. Eaton <jwe@octave.org>
parents:
28514
diff
changeset
|
511 octave::cdef_method cdef_meth = cls.find_method (meth_name); |
28514
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
512 |
28515
49f4d7814760
find help for not-yet-loaded classdef methods defined in @DIR files.
John W. Eaton <jwe@octave.org>
parents:
28514
diff
changeset
|
513 if (cdef_meth.ok ()) |
49f4d7814760
find help for not-yet-loaded classdef methods defined in @DIR files.
John W. Eaton <jwe@octave.org>
parents:
28514
diff
changeset
|
514 return cdef_meth.get_doc_string (); |
28514
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
515 } |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
516 |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
517 return ""; |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
518 } |
fab862fedf85
allow help to find docstrings for classdef classes and methods (bug #43047)
John W. Eaton <jwe@octave.org>
parents:
28438
diff
changeset
|
519 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
520 std::string |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
521 octave_classdef_meta::file_name () const |
30259
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
522 { |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
523 if (m_object.is_class ()) |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
524 { |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
525 octave::cdef_class cls (m_object); |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
526 |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
527 return cls.file_name (); |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
528 } |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
529 |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
530 return ""; |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
531 } |
03ff3f1020cf
store file name in classdef class object
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
532 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
533 octave_value_list |
28429
8eb8ba8aff9a
refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents:
28072
diff
changeset
|
534 octave_classdef_superclass_ref::execute (octave::tree_evaluator& tw, |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
535 int nargout, |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
536 const octave_value_list& idx) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
537 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
538 octave_value_list retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
539 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
540 std::string meth_name; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
541 bool in_constructor; |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
542 octave::cdef_class ctx; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
543 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
544 ctx = octave::get_class_context (meth_name, in_constructor); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
545 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
546 if (! ctx.ok ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
547 error ("superclass calls can only occur in methods or constructors"); |
20125
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
548 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
549 std::string mname = m_method_name; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
550 std::string cname = m_class_name; |
20189
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
551 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
552 // CLS is the superclass. The lookup_class function handles |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
553 // pkg.class names. |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
554 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
555 octave::cdef_class cls = octave::lookup_class (cname); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
556 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
557 if (in_constructor) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
558 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
559 if (! is_direct_superclass (cls, ctx)) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
560 error ("'%s' is not a direct superclass of '%s'", |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
561 cname.c_str (), ctx.get_name ().c_str ()); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
562 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
563 if (! is_constructed_object (tw, mname)) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
564 error ("cannot call superclass constructor with variable '%s'", |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
565 mname.c_str ()); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
566 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
567 octave_value sym = tw.varval (mname); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
568 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
569 cls.run_constructor (octave::to_cdef_ref (sym), idx); |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
570 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
571 retval(0) = sym; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
572 } |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
573 else |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
574 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
575 std::size_t pos = mname.find ('.'); |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
576 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
577 octave::cdef_object obj; |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
578 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
579 if (pos != std::string::npos) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
580 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
581 // We are looking at obj.meth. |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
582 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
583 std::string oname = m_method_name.substr (0, pos); |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
584 mname = mname.substr (pos + 1); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
585 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
586 octave_value tval = tw.varval (oname); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
587 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
588 // FIXME: Can we only call superclass methods on the current |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
589 // object? If so, and we are looking at something like |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
590 // |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
591 // function meth (obj, ...) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
592 // obj.meth@superclass (...) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
593 // |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
594 // Do we need to verify that the object that was passed to |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
595 // meth is the same as the object we find when looking up |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
596 // obj in the expression obj.meth? If so, what is the right |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
597 // way to perform that check? |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
598 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
599 if (tval.is_classdef_object ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
600 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
601 octave_classdef *cdobj = tval.classdef_object_value (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
602 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
603 obj = cdobj->get_object (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
604 } |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
605 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
606 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
607 if (mname != meth_name) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
608 error ("method name mismatch ('%s' != '%s')", |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
609 mname.c_str (), meth_name.c_str ()); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
610 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
611 if (! is_strict_superclass (cls, ctx)) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
612 error ("'%s' is not a superclass of '%s'", |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
613 cname.c_str (), ctx.get_name ().c_str ()); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
614 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
615 // I see 2 possible implementations here: |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
616 // 1) use cdef_object::subsref with a different class |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
617 // context; this avoids duplicating code, but |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
618 // assumes the object is always the first argument |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
619 // 2) lookup the method manually and call |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
620 // cdef_method::execute; this duplicates part of |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
621 // logic in cdef_object::subsref, but avoid the |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
622 // assumption of 1) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
623 // Not being sure about the assumption of 1), I |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
624 // go with option 2) for the time being. |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
625 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
626 octave::cdef_method meth = cls.find_method (meth_name, false); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
627 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
628 if (! meth.ok ()) |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
629 error ("no method '%s' found in superclass '%s'", |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
630 meth_name.c_str (), cname.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
631 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
632 retval = (obj.ok () |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
633 ? meth.execute (obj, idx, nargout, true, meth_name) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
634 : meth.execute (idx, nargout, true, meth_name)); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
635 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
636 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
637 return retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
638 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
639 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
640 bool |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32426
diff
changeset
|
641 octave_classdef_superclass_ref::is_constructed_object (octave::tree_evaluator& tw, |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
642 const std::string& nm) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
643 { |
27208
5b40cf4896f0
eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents:
27188
diff
changeset
|
644 octave_function *of = tw.current_function (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
645 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
646 if (of->is_classdef_constructor ()) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
647 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
648 octave_user_function *uf = of->user_function_value (true); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
649 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
650 if (uf) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
651 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
652 octave::tree_parameter_list *ret_list = uf->return_list (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
653 |
32936
0b5f3219b650
eliminate all uses of base_list<T> template
John W. Eaton <jwe@octave.org>
parents:
32863
diff
changeset
|
654 if (ret_list && ret_list->size () == 1) |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
655 return (ret_list->front ()->name () == nm); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
656 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
657 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
658 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
659 return false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
660 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
661 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31594
diff
changeset
|
662 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29893
diff
changeset
|
663 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
664 DEFUN (__meta_get_package__, args, , |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
665 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
666 @deftypefn {} {@var{pkg} =} __meta_get_package__ (@var{pkg_name}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
667 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
668 @end deftypefn */) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
669 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
670 if (args.length () != 1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
671 print_usage (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
672 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
673 std::string cname = args(0).xstring_value ("PKG_NAME must be a string"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
674 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
675 return to_ov (lookup_package (cname)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
676 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
677 |
20946 | 678 DEFUN (metaclass, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
679 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
680 @deftypefn {} {@var{metaclass_obj} =} metaclass (obj) |
31594
a3d8915b9f87
doc: more DOCSTRING changes ahead of 8.1 release.
Rik <rik@octave.org>
parents:
31176
diff
changeset
|
681 Return the meta.class object corresponding to the class of @var{obj}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
682 @end deftypefn */) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
683 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
684 if (args.length () != 1) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
685 print_usage (); |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
686 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
687 cdef_object obj = to_cdef (args(0)); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
688 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
689 return to_ov (obj.get_class ()); |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
690 } |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
691 |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
692 // FIXME: What about dynamic properties if obj is a scalar, or the |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
693 // properties of the class of obj if obj is an array? Probably there |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
694 // should be a function to do this job so that the DEFUN is just a |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
695 // simple wrapper. |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
696 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
697 DEFUN (properties, args, nargout, |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
698 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
699 @deftypefn {} {} properties (@var{obj}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
700 @deftypefnx {} {} properties (@var{class_name}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
701 @deftypefnx {} {@var{proplist} =} properties (@dots{}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
702 Display or return the public properties for the classdef object @var{obj} or |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
703 the named class @var{class_name}. |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
704 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
705 If an output value is requested, return the list of property names in a cell |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
706 array. |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
707 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
708 Programming Note: Property names are returned if the @code{GetAccess} attribute |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
709 is public and if the @code{Hidden} attribute is false. |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
710 @seealso{methods} |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
711 @end deftypefn */) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
712 { |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
713 if (args.length () != 1) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
714 print_usage (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
715 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
716 octave_value arg = args(0); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
717 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
718 std::string class_name; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
719 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
720 if (arg.isobject ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
721 class_name = arg.class_name (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
722 else if (arg.is_string ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
723 class_name = arg.string_value (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
724 else |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
725 err_wrong_type_arg ("properties", arg); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
726 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
727 cdef_class cls; |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
728 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
729 cls = lookup_class (class_name, false, true); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
730 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
731 if (! cls.ok ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
732 error ("invalid class: %s", class_name.c_str ()); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
733 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
734 std::map<std::string, cdef_property> property_map = |
27932
b018f553fd85
maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
735 cls.get_property_map (); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
736 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
737 std::list<std::string> property_names; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
738 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
739 for (const auto& pname_prop : property_map) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
740 { |
27188
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
741 // FIXME: this loop duplicates a significant portion of the loops |
792fe198c105
don't print hidden or protected/private classdef properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27186
diff
changeset
|
742 // in octave_classdef::print_raw. |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
743 const cdef_property& prop = pname_prop.second; |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
744 |
27186
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
745 octave_value acc = prop.get ("GetAccess"); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
746 |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
747 if (! acc.is_string () || acc.string_value () != "public") |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
748 continue; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
749 |
27186
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
750 octave_value hid = prop.get ("Hidden"); |
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
751 |
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
752 if (hid.bool_value ()) |
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
753 continue; |
b15b71bcd679
properties function: omit hidden properties (bug #55766)
John W. Eaton <jwe@octave.org>
parents:
27072
diff
changeset
|
754 |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
755 property_names.push_back (pname_prop.first); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
756 } |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
757 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
758 if (nargout > 0) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
759 return octave_value (Cell (string_vector (property_names))); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
760 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
761 octave_stdout << "properties for class " << class_name << ":\n\n"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
762 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
763 for (const auto& nm : property_names) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
764 octave_stdout << " " << nm << "\n"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
765 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
766 octave_stdout << std::endl; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
767 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
768 return octave_value (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
769 } |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
770 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
771 /* |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
772 %!assert (properties ("inputParser"), |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
773 %! {"CaseSensitive"; "FunctionName"; "KeepUnmatched"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
774 %! "Parameters"; "PartialMatching"; "Results"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
775 %! "StructExpand"; "Unmatched"; "UsingDefaults"}); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
776 */ |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
777 |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
778 // FIXME: Need to implement the -full option. |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
779 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
780 DEFMETHOD (__methods__, interp, args, , |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
781 doc: /* -*- texinfo -*- |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
782 @deftypefn {} {[@var{mtds}, @var{found}] =} __methods__ (@var{obj}) |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
783 @deftypefnx {} {[@var{mtds}, @var{found}] =} __methods__ ("classname") |
31594
a3d8915b9f87
doc: more DOCSTRING changes ahead of 8.1 release.
Rik <rik@octave.org>
parents:
31176
diff
changeset
|
784 Implement @code{methods} for Octave class objects and classnames. |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
785 @seealso{methods} |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
786 @end deftypefn */) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
787 { |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
788 // Input validation has already been done in methods.m. |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
789 octave_value arg = args(0); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
790 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
791 std::string class_name; |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
792 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
793 if (arg.isobject ()) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
794 class_name = arg.class_name (); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
795 else if (arg.is_string ()) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
796 class_name = arg.string_value (); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
797 else |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
798 err_wrong_type_arg ("__methods__", arg); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
799 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
800 string_vector sv; |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
801 bool found = false; |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
802 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
803 cdef_class cls = lookup_class (class_name, false, true); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
804 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
805 if (cls.ok ()) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
806 { |
31174
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
807 // Find methods for classdef objects. |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
808 std::map<std::string, cdef_method> method_map |
26950
fbb318c371db
methods: return classdef constructors in list (bug #55858)
John W. Eaton <jwe@octave.org>
parents:
26922
diff
changeset
|
809 = cls.get_method_map (false, true); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
810 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
811 std::list<std::string> method_names; |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
812 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
813 for (const auto& nm_mthd : method_map) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
814 { |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
815 const cdef_method& method = nm_mthd.second; |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
816 |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
817 octave_value acc = method.get ("Access"); |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
818 |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
819 if (! acc.is_string () || acc.string_value () != "public") |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
820 continue; |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
821 |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
822 octave_value hid = method.get ("Hidden"); |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
823 |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
824 if (hid.bool_value ()) |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
825 continue; |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
826 |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
827 method_names.push_back (nm_mthd.first); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
828 } |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
829 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
830 sv = string_vector (method_names); |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
831 found = true; |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
832 } |
31174
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
833 else |
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
834 { |
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
835 // Find methods for legacy @CLASS objects. |
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
836 load_path& lp = interp.get_load_path (); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
837 |
31174
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
838 sv = string_vector (lp.methods (class_name)); |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
839 found = ! sv.empty (); |
31174
fb1c7c8a030b
Fix duplicate names displayed with mixed @class/classdef classes (Bug #62802)
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
840 } |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
841 |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
842 return ovl (Cell (sv), found); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
843 } |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
844 |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
845 /* |
32057
f010a32986e4
Remove test of methods ov-classdef.cc that should have been in cset d98157d51a97.
Rik <rik@octave.org>
parents:
32055
diff
changeset
|
846 // BIST tests are in file methods.m |
f010a32986e4
Remove test of methods ov-classdef.cc that should have been in cset d98157d51a97.
Rik <rik@octave.org>
parents:
32055
diff
changeset
|
847 %!assert (1) |
32055
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
848 */ |
dfd2b1a268a0
Don't list non-public or hidden functions from methods() (bug #64066)
Rik <rik@octave.org>
parents:
31845
diff
changeset
|
849 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31594
diff
changeset
|
850 OCTAVE_END_NAMESPACE(octave) |