Mercurial > octave
annotate libinterp/octave-value/ov-classdef.cc @ 26922:072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
* ov.h (octave_value::xnumel (const octave_value_list&)):
Rename from numel. Change all uses.
* ov-base.h, ov-base.cc, ov-class.h, ov-class.cc, ov-classdef.h,
ov-classdef.cc: Rename "numel (const octave_value_list&) method to
xnumel. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 15 Mar 2019 07:16:27 +0000 |
parents | 8cad08868ffd |
children | fbb318c371db |
rev | line source |
---|---|
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1 /* |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2 |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26119
diff
changeset
|
3 Copyright (C) 2012-2019 Michael Goffioul |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
4 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
6 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
16 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
20 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
21 */ |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
22 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 #endif |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
26 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
27 #include <algorithm> |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
28 #include <iomanip> |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
29 |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
30 #include "call-stack.h" |
26772
d1419ac09564
split method, package, and property classes from cdef-class file
John W. Eaton <jwe@octave.org>
parents:
26769
diff
changeset
|
31 #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
|
32 #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
|
33 #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
|
34 #include "cdef-property.h" |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
35 #include "cdef-utils.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 #include "defun.h" |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
37 #include "errwarn.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
38 #include "interpreter-private.h" |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
39 #include "load-path.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
40 #include "ov-classdef.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
41 #include "ov-fcn-handle.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 #include "ov-typeinfo.h" |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
43 #include "ov-usr-fcn.h" |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
44 #include "parse.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
45 #include "pt-eval.h" |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
46 #include "pt-misc.h" |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
47 #include "symtab.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
48 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
49 static bool |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
50 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
|
51 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
52 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
|
53 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
54 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
|
55 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
56 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
57 int octave_classdef::t_id (-1); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
58 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
59 const std::string octave_classdef::t_name ("object"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
60 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
61 void |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
62 octave_classdef::register_type (octave::type_info& ti) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
63 { |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
64 t_id = ti.register_type (octave_classdef::t_name, "<unknown>", |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
65 octave_value (new octave_classdef ())); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
66 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
67 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
68 octave_value_list |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
69 octave_classdef::subsref (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
70 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
71 int nargout) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
72 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
73 size_t skip = 0; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
74 octave_value_list retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
75 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
76 octave::cdef_class cls = object.get_class (); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
77 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
78 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
|
79 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
80 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
|
81 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
82 if (meth.ok ()) |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
83 { |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
84 octave_value_list args; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
85 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
86 args(1) = make_idx_args (type, idx, "subsref"); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
87 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
88 count++; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
89 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
90 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
91 retval = meth.execute (args, nargout, true, "subsref"); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
92 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
93 return retval; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
94 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
95 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
96 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
97 // 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
|
98 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
99 retval = 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
|
100 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
101 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
|
102 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
|
103 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
104 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
105 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
106 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
107 octave_value |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
108 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
|
109 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
|
110 bool auto_add) |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
111 { |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
112 size_t skip = 0; |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
113 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
|
114 |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
115 // 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
|
116 // 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
|
117 // 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
|
118 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
119 octave::cdef_class cls = 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
|
120 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
121 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
|
122 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
123 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
|
124 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
125 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
|
126 { |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
127 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
|
128 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
129 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
|
130 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
131 count++; |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
132 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
|
133 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
134 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
|
135 |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
136 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
|
137 } |
17d806c3f7cd
fix overloaded classdef subsasgn with curly braces (bug #55223, bug #54783)
S?bastien Villemot <sebastien@debian.org>
parents:
26525
diff
changeset
|
138 } |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
139 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
140 retval = object.subsref (type, idx, 1, skip, 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
|
141 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
142 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
|
143 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
|
144 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
145 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
|
146 } |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
147 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
148 octave_value |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
149 octave_classdef::subsasgn (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
150 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
151 const octave_value& rhs) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
152 { |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
153 octave_value retval; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
154 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
155 octave::cdef_class cls = object.get_class (); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
156 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
157 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
|
158 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
159 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
|
160 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
161 if (meth.ok ()) |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
162 { |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
163 octave_value_list args; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
164 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
165 args(1) = make_idx_args (type, idx, "subsasgn"); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
166 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
167 count++; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
168 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
169 args(2) = rhs; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
170 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
171 octave_value_list retlist; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
172 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
173 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
|
174 |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
175 if (retlist.empty ()) |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
176 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
|
177 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
178 retval = retlist(0); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
179 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
180 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
181 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
182 if (! retval.is_defined ()) |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
183 retval = object.subsasgn (type, idx, rhs); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
184 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
185 return retval; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
186 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
187 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
188 octave_value |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
189 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
|
190 const std::list<octave_value_list>& idx, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
191 const octave_value& rhs) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
192 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
193 if (type.length () == 1 && type[0] == '(') |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
194 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
195 object = object.make_array (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
196 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
197 return subsasgn (type, idx, rhs); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
198 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
199 else |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
200 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
|
201 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
202 return octave_value (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
203 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
204 |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
205 octave_idx_type |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26778
diff
changeset
|
206 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
|
207 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
208 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
|
209 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
210 octave::cdef_class cls = 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
|
211 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
212 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
|
213 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
214 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
|
215 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
216 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
|
217 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
218 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
|
219 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
220 count++; |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
221 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
|
222 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
223 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
|
224 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
|
225 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
230 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
|
231 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
232 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
|
233 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
234 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
235 |
26922
072d0610cc56
avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents:
26778
diff
changeset
|
236 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
|
237 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
238 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
|
239 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
240 |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
241 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
242 octave_classdef::print (std::ostream& os, bool) |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
243 { |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
244 print_raw (os); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
245 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
246 |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
247 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
248 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
|
249 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
250 octave::cdef_class cls = 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
|
251 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
252 if (cls.ok ()) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
253 { |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
254 indent (os); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
255 os << class_name () << " object"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
256 if (object.is_array ()) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
257 os << " array"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
258 os << " with properties:"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
259 newline (os); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
260 newline (os); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
261 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
262 std::map<std::string, octave::cdef_property> props; |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
263 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
264 props = cls.get_property_map (); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
265 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
266 size_t max_len = 0; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
267 for (const auto& nm_prop : props) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
268 { |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
269 const std::string& nm = nm_prop.first; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
270 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
271 size_t sz = nm.size (); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
272 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
273 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
|
274 max_len = sz; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
275 } |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
276 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
277 for (auto& nm_prop : props) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
278 { |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
279 const std::string& nm = nm_prop.first; |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
280 octave::cdef_property& prop = nm_prop.second; |
26749
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
281 octave_value val = prop.get_value (object, false); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
282 dim_vector dims = val.dims (); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
283 |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
284 os << std::setw (max_len+2) << nm << ": "; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
285 if (val.is_string ()) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
286 os << val.string_value (); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
287 else if (val.islogical ()) |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
288 os << val.bool_value (); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
289 else |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
290 os << "[" << dims.str () << " " << val.class_name () << "]"; |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
291 newline (os); |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
292 } |
2c4ad1958cab
display property names and info by default for classdef objects
John W. Eaton <jwe@octave.org>
parents:
26745
diff
changeset
|
293 } |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
294 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
295 |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
296 bool |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
297 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
|
298 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
299 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
|
300 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
301 if (cls.ok ()) |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
302 return is_superclass (cls, object.get_class ()); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
303 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
304 return false; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
305 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
306 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
307 octave_value |
26718
9b0335f4bc74
revise naming of the parts of a superclass reference
John W. Eaton <jwe@octave.org>
parents:
26686
diff
changeset
|
308 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
|
309 const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
310 { |
26718
9b0335f4bc74
revise naming of the parts of a superclass reference
John W. Eaton <jwe@octave.org>
parents:
26686
diff
changeset
|
311 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
|
312 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
313 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
314 octave_value |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
315 octave_classdef::metaclass_query (const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
316 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
317 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
|
318 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
319 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
320 bool 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
|
321 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
322 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
|
323 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
324 if (object.is_class ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
325 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
326 if (cname.empty ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
327 retval = true; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
328 else |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
329 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
330 octave::cdef_class cls (object); |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
331 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
332 if (cls.get_name () == cname) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
333 retval = true; |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
334 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
335 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
336 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
337 return retval; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
338 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
339 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
340 octave_value_list |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
341 octave_classdef_superclass_ref::call (octave::tree_evaluator& tw, |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
342 int nargout, const octave_value_list& idx) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
343 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
344 octave_value_list retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
345 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
346 std::string meth_name; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
347 bool in_constructor; |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
348 octave::cdef_class ctx; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
349 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
350 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
|
351 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
352 if (! ctx.ok ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
353 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
|
354 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
355 std::string mname = m_method_name; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
356 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
|
357 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
358 // 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
|
359 // pkg.class names. |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
360 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
361 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
|
362 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
363 if (in_constructor) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
364 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
365 if (! is_direct_superclass (cls, ctx)) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
366 error ("`%s' is not a direct superclass of `%s'", |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
367 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
|
368 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
369 if (! is_constructed_object (tw, mname)) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
370 error ("cannot call superclass constructor with variable `%s'", |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
371 mname.c_str ()); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
372 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
373 octave_value sym = tw.varval (mname); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
374 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
375 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
|
376 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
377 retval(0) = sym; |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
378 } |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
379 else |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
380 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
381 size_t pos = mname.find ('.'); |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
382 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
383 octave::cdef_object obj; |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
384 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
385 if (pos != std::string::npos) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
386 { |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
387 // We are looking at obj.meth. |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
388 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
389 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
|
390 mname = mname.substr (pos + 1); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
391 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
392 octave_value tval = tw.varval (oname); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
393 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
394 // 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
|
395 // 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
|
396 // |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
397 // function meth (obj, ...) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
398 // obj.meth@superclass (...) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
399 // |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
400 // 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
|
401 // 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
|
402 // 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
|
403 // way to perform that check? |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
404 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
405 if (tval.is_classdef_object ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
406 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
407 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
|
408 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
409 obj = cdobj->get_object (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
410 } |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
411 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
412 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
413 if (mname != meth_name) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
414 error ("method name mismatch (`%s' != `%s')", |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
415 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
|
416 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
417 if (! is_strict_superclass (cls, ctx)) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
418 error ("`%s' is not a superclass of `%s'", |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
419 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
|
420 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
421 // I see 2 possible implementations here: |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
422 // 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
|
423 // context; this avoids duplicating code, but |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
424 // 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
|
425 // 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
|
426 // 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
|
427 // 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
|
428 // assumption of 1) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
429 // 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
|
430 // 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
|
431 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
432 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
|
433 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
434 if (! meth.ok ()) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
435 error ("no method `%s' found in superclass `%s'", |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
436 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
|
437 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
438 retval = (obj.ok () |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
439 ? 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
|
440 : 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
|
441 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
442 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
443 return retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
444 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
445 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
446 bool octave_classdef_superclass_ref::is_constructed_object (octave::tree_evaluator& tw, |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
447 const std::string& nm) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
448 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
449 octave::call_stack& cs = tw.get_call_stack (); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
450 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
451 octave_function *of = cs.current (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
452 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
453 if (of->is_classdef_constructor ()) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
454 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
455 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
|
456 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
457 if (uf) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
458 { |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
459 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
|
460 |
26769
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
461 if (ret_list && ret_list->length () == 1) |
2f847e3e8d6b
split classdef into multiple smaller source files
John W. Eaton <jwe@octave.org>
parents:
26758
diff
changeset
|
462 return (ret_list->front ()->name () == nm); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
463 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
464 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
465 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
466 return false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
467 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
468 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
469 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
|
470 doc: /* -*- texinfo -*- |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22297
diff
changeset
|
471 @deftypefn {} {} __meta_get_package__ () |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
472 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
|
473 @end deftypefn */) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
474 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
475 if (args.length () != 1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
476 print_usage (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
477 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
478 std::string cname = args(0).xstring_value ("PACKAGE_NAME must be a string"); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
479 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
480 return octave::to_ov (octave::lookup_package (cname)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
481 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
482 |
20946 | 483 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
|
484 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
485 @deftypefn {} {} metaclass (obj) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
486 Returns the meta.class object corresponding to the class of @var{obj}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
487 @end deftypefn */) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
488 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
489 if (args.length () != 1) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
490 print_usage (); |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
491 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
492 octave::cdef_object obj = octave::to_cdef (args(0)); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
493 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
494 return octave::to_ov (obj.get_class ()); |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
495 } |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
496 |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
497 // 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
|
498 // 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
|
499 // 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
|
500 // simple wrapper. |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
501 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
502 DEFUN (properties, args, nargout, |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
503 doc: /* -*- texinfo -*- |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
504 @deftypefn {} {} properties (@var{class_name}) |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
505 @deftypefnx {} {} properties (@var{obj}) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
506 @deftypefnx {} {@var{plist} =} properties (@dots{}) |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
507 Return or display the public properties for the named class @var{class_name} or |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
508 classdef object @var{obj}. |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
509 |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
510 If an output value is requested, return the list of property names in a cell |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
511 array. |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
512 |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
513 Programming Note: Property names are returned if the @code{GetAccess} attribute is public and if the @code{Hidden} attribute is false. |
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
514 @seealso{methods} |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
515 @end deftypefn */) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
516 { |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
517 if (args.length () != 1) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
518 print_usage (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
519 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
520 octave_value arg = args(0); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
521 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
522 std::string class_name; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
523 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
524 if (arg.isobject ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
525 class_name = arg.class_name (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
526 else if (arg.is_string ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
527 class_name = arg.string_value (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
528 else |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
529 err_wrong_type_arg ("properties", arg); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
530 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
531 octave::cdef_class cls; |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
532 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
533 cls = octave::lookup_class (class_name, false, true); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
534 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
535 if (! cls.ok ()) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
536 error ("invalid class: %s", class_name.c_str ()); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
537 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
538 std::map<std::string, octave::cdef_property> property_map = cls.get_property_map (); |
26723
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
539 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
540 std::list<std::string> property_names; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
541 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
542 for (const auto& pname_prop : property_map) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
543 { |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
544 std::string nm = pname_prop.second.get_name (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
545 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
546 octave_value acc = pname_prop.second.get ("GetAccess"); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
547 |
26778
8cad08868ffd
Return help text for properties() function (bug #55764).
Rik <rik@octave.org>
parents:
26774
diff
changeset
|
548 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
|
549 continue; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
550 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
551 property_names.push_back (nm); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
552 } |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
553 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
554 if (nargout > 0) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
555 return octave_value (Cell (string_vector (property_names))); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
556 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
557 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
|
558 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
559 for (const auto& nm : property_names) |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
560 octave_stdout << " " << nm << "\n"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
561 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
562 octave_stdout << std::endl; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
563 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
564 return octave_value (); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
565 } |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
566 |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
567 /* |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
568 %!assert (properties ("inputParser"), |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
569 %! {"CaseSensitive"; "FunctionName"; "KeepUnmatched"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
570 %! "Parameters"; "PartialMatching"; "Results"; |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
571 %! "StructExpand"; "Unmatched"; "UsingDefaults"}); |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
572 */ |
259953dac9b8
implement properties function (bug #53614)
John W. Eaton <jwe@octave.org>
parents:
26719
diff
changeset
|
573 |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
574 // 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
|
575 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
576 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
|
577 doc: /* -*- texinfo -*- |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
578 @deftypefn {} {} __methods__ (@var{x}) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
579 @deftypefnx {} {} __methods__ ("classname") |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
580 Internal function. |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
581 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
582 Implements @code{methods} for Octave class objects and classnames. |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
583 @seealso{methods} |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
584 @end deftypefn */) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
585 { |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
586 // 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
|
587 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
|
588 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
589 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
|
590 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
591 if (arg.isobject ()) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 else |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
596 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
|
597 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
598 string_vector sv; |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
599 |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
600 octave::cdef_class cls = octave::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
|
601 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
602 if (cls.ok ()) |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
603 { |
26774
568c2ab2782d
move classdef classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26772
diff
changeset
|
604 std::map<std::string, octave::cdef_method> method_map = cls.get_method_map (); |
26724
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
605 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
606 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
|
607 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
608 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
|
609 { |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
610 std::string nm = nm_mthd.first; |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
611 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
612 method_names.push_back (nm); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
613 } |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
614 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
615 sv = string_vector (method_names); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
616 } |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
617 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
618 // The following will also find methods for legacy @CLASS objects. |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
619 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
620 octave::load_path& lp = interp.get_load_path (); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
621 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
622 sv.append (lp.methods (class_name)); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
623 |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
624 return ovl (Cell (sv)); |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
625 } |
84355b7b9521
allow methods function to work for classdef objects (bug #42510)
John W. Eaton <jwe@octave.org>
parents:
26723
diff
changeset
|
626 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
627 /* |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
628 ;;; Local Variables: *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
629 ;;; mode: C++ *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
630 ;;; End: *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
631 */ |