Mercurial > octave
annotate libinterp/octave-value/ov-classdef.cc @ 26686:581d01526b34
eliminate unnecessary tree_funcall class
The tree_funcall class was only used to handled generated calls to
internal functions used by classdef superclass reference and metaclass
query operations. This change replaces those function calls by
something more direct.
* pt-classdef.h, pt-classdef.cc (tree_superclass_ref,
tree_metaclass_query): New classes.
* pt-walk.h (tree_walker::visit_tree_funcall): Delete. Update all
derived classes.
(tree_walker::visit_superclass_ref,
tree_walker::visit_metaclass_query): New virtual functions.
* pt-pr-code.h, pt-pr-code.cc (tree_print_code::visit
(tree_print_code::visit_superclass_ref,
tree_print_code::visit_metaclass_query):
Correctly print these parse tree elements.
* oct-parse.yy (superclass_identifier, meta_identifier): Use new
tree_superclass_ref tree_metaclass_query classes instead of
tree_funcall to represent these language elements.
* lex.ll (base_lexer::handle_superclass_identifier): Attempt to make
intent of code clearer. Save line and column info in token.
* pt-eval.h, pt-eval.cc (tree_evaluator::visit_funcall): Delete.
(tree_evaluator::visit_superclass_ref,
tree_evaluator::visit_metaclass_query): New functions. Handle
superclass reference and metaclass query operations more directly.
* ov-classdef.h, ov-classdef.cc (F__superclass_reference__,
F__meta_class_query__): Delete.
(class octave_classdef_superclass_ref): Work directly with
method or object and class names as strings instead of octave_value
objects.
(octave_classdef::superclass_ref, octave_classdef::metaclass_query):
New static functions.
* token.h, token.cc: Attempt to use clearer names for superclass
reference tokens.
* pt-funcall.h, pt-funcall.cc: Delete.
* libinterp/parse-tree/module.mk: Update.
* pt-all.h: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Feb 2019 00:03:55 +0000 |
parents | cf9e10ce3351 |
children | 9b0335f4bc74 |
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> |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
29 #include "call-stack.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
30 #include "defun.h" |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
31 #include "interpreter-private.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
32 #include "interpreter.h" |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
33 #include "load-path.h" |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
34 #include "ov-builtin.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
35 #include "ov-classdef.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 #include "ov-fcn-handle.h" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
37 #include "ov-typeinfo.h" |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
38 #include "ov-usr-fcn.h" |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
39 #include "parse.h" |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
40 #include "pt-assign.h" |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
41 #include "pt-classdef.h" |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
42 #include "pt-eval.h" |
23127
5a91168a30be
avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
23084
diff
changeset
|
43 #include "pt-idx.h" |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
44 #include "pt-misc.h" |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
45 #include "pt-stmt.h" |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
46 #include "pt-walk.h" |
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 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
49 // Define to 1 to enable debugging statements. |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
50 #define DEBUG_TRACE 0 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
51 |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
52 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
53 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
54 err_method_access (const std::string& from, const cdef_method& meth) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
55 { |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
56 octave_value acc = meth.get ("Access"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
57 std::string acc_s; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
58 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
59 if (acc.is_string ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
60 acc_s = acc.string_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
61 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
62 acc_s = "class-restricted"; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
63 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
64 error ("%s: method `%s' has %s access and cannot be run in this context", |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
65 from.c_str (), meth.get_name ().c_str (), acc_s.c_str ()); |
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 |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
68 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
69 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
70 err_property_access (const std::string& from, const cdef_property& prop, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22374
diff
changeset
|
71 bool is_set = false) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
72 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
73 octave_value acc = (prop.get (is_set ? "SetAccess" : "GetAccess")); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
74 std::string acc_s; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
75 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
76 if (acc.is_string ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
77 acc_s = acc.string_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
78 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
79 acc_s = "class-restricted"; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
80 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
81 if (is_set) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
82 error ("%s: property `%s' has %s access and cannot be set in this context", |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
83 from.c_str (), prop.get_name ().c_str (), acc_s.c_str ()); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
84 else |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
85 error ("%s: property `%s' has %s access and cannot be obtained in this context", |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
86 from.c_str (), prop.get_name ().c_str (), acc_s.c_str ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
87 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
88 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
89 static std::string |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
90 get_base_name (const std::string& nm) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
91 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
92 std::string::size_type pos = nm.find_last_of ('.'); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
93 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
94 if (pos != std::string::npos) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
95 return nm.substr (pos + 1); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
96 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
97 return nm; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
98 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
99 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
100 static void |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
101 make_function_of_class (const std::string& class_name, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
102 const octave_value& fcn) |
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 octave_function *of = fcn.function_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
105 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
106 of->stash_dispatch_class (class_name); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
107 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
108 octave_user_function *uf = of->user_function_value (true); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
109 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
110 if (uf) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
111 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
112 if (get_base_name (class_name) == uf->name ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
113 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
114 uf->mark_as_class_constructor (); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
115 uf->mark_as_classdef_constructor (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
116 } |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
117 else |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
118 uf->mark_as_class_method (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
119 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
120 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
121 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
122 static void |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
123 make_function_of_class (const cdef_class& cls, const octave_value& fcn) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
124 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
125 make_function_of_class (cls.get_name (), fcn); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
126 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
127 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
128 static octave_value |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
129 make_fcn_handle (octave_builtin::fcn ff, const std::string& nm) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
130 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
131 octave_value fcn (new octave_builtin (ff, nm)); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
132 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
133 octave_value fcn_handle (new octave_fcn_handle (fcn, nm)); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
134 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
135 return fcn_handle; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
136 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
137 |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
138 static octave_value |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
139 make_fcn_handle (const octave_value& fcn, const std::string& nm) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
140 { |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
141 octave_value retval; |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
142 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
143 if (fcn.is_defined ()) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
144 retval = octave_value (new octave_fcn_handle (fcn, nm)); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
145 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
146 return retval; |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
147 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
148 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
149 static cdef_class |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
150 lookup_class (const std::string& name, bool error_if_not_found = true, |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
151 bool load_if_not_found = true) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
152 { |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
153 cdef_manager& cdm = octave::__get_cdef_manager__ ("lookup_class"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
154 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
155 return cdm.find_class (name, error_if_not_found, load_if_not_found); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
156 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
157 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
158 static cdef_class |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
159 lookup_class (const cdef_class& cls) |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
160 { |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
161 // FIXME: placeholder for the time being, the purpose |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
162 // is to centralized any class update activity here. |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
163 |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
164 return cls; |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
165 } |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
166 |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
167 static cdef_class |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
168 lookup_class (const octave_value& ov) |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
169 { |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
170 if (ov.is_string()) |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
171 return lookup_class (ov.string_value ()); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
172 else |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
173 { |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
174 cdef_class cls (to_cdef (ov)); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
175 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
176 return lookup_class (cls); |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
177 } |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
178 |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
179 return cdef_class (); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
180 } |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
181 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
182 static std::list<cdef_class> |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
183 lookup_classes (const Cell& cls_list) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
184 { |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
185 std::list<cdef_class> retval; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
186 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
187 for (int i = 0; i < cls_list.numel (); i++) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
188 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
189 cdef_class c = lookup_class (cls_list(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
190 |
20678
4b00afb5e9c3
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20580
diff
changeset
|
191 retval.push_back (c); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
192 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
193 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
194 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
195 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
196 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
197 static octave_value |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
198 to_ov (const std::list<cdef_class>& class_list) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
199 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
200 Cell cls (class_list.size (), 1); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
201 int i = 0; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
202 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
203 for (const auto& cdef_cls : class_list) |
22991
53bb781d70c0
Fix regression in multiple inheritance from cset 50495eeb5df1 (bug #49973).
Rik <rik@octave.org>
parents:
22898
diff
changeset
|
204 cls(i++) = to_ov (cdef_cls); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
205 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
206 return octave_value (cls); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
207 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
208 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
209 static bool |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
210 is_superclass (const cdef_class& clsa, const cdef_class& clsb, |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
211 bool allow_equal = true, int max_depth = -1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
212 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
213 bool retval = false; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
214 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
215 if (allow_equal && clsa == clsb) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
216 retval = true; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
217 else if (max_depth != 0) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
218 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
219 Cell c = clsb.get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
220 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
221 for (int i = 0; ! retval && i < c.numel (); i++) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
222 { |
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
223 cdef_class cls = lookup_class (c(i)); |
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
224 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
225 retval = is_superclass (clsa, cls, true, |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
226 max_depth < 0 ? max_depth : max_depth-1); |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
227 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
228 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
229 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
230 return retval; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
231 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
232 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
233 inline bool |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
234 is_strict_superclass (const cdef_class& clsa, const cdef_class& clsb) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
235 { return is_superclass (clsa, clsb, false); } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
236 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
237 inline bool |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
238 is_direct_superclass (const cdef_class& clsa, const cdef_class& clsb) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
239 { return is_superclass (clsa, clsb, false, 1); } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
240 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
241 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
242 class_get_properties (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
243 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
244 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
245 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
246 if (args.length () == 1 && args(0).type_name () == "object") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
247 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
248 cdef_class cls (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
249 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
250 retval(0) = cls.get_properties (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
251 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
252 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
253 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
254 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
255 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
256 static cdef_class |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
257 get_class_context (std::string& name, bool& in_constructor) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
258 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
259 cdef_class cls; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
260 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
261 octave::call_stack& cs = octave::__get_call_stack__ ("get_class_context"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
262 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
263 octave_function *fcn = cs.current (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
264 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
265 in_constructor = false; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
266 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
267 if (fcn && (fcn->is_class_method () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
268 || fcn->is_classdef_constructor () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
269 || fcn->is_anonymous_function_of_class () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
270 || (fcn->is_private_function () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
271 && ! fcn->dispatch_class ().empty ()))) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
272 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
273 cls = lookup_class (fcn->dispatch_class ()); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
274 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
275 name = fcn->name (); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
276 in_constructor = fcn->is_classdef_constructor (); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
277 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
278 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
279 return cls; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
280 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
281 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
282 inline cdef_class |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
283 get_class_context (void) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
284 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
285 std::string dummy_string; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
286 bool dummy_bool; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
287 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
288 return get_class_context (dummy_string, dummy_bool); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
289 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
290 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
291 static bool |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
292 in_class_method (const cdef_class& cls) |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
293 { |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
294 cdef_class ctx = get_class_context (); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
295 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
296 return (ctx.ok () && is_superclass (ctx, cls)); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
297 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
298 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
299 static bool |
18305
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
300 check_access (const cdef_class& cls, const octave_value& acc, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
301 const std::string& meth_name = "", |
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
302 const std::string& prop_name = "", |
18305
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
303 bool is_prop_set = false) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
304 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
305 if (acc.is_string ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
306 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
307 std::string acc_s = acc.string_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
308 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
309 if (acc_s == "public") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
310 return true; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
311 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
312 cdef_class ctx = get_class_context (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
313 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
314 // The access is private or protected, this requires a |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
315 // valid class context. |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
316 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
317 if (ctx.ok ()) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
318 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
319 if (acc_s == "private") |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
320 return (ctx == cls); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
321 else if (acc_s == "protected") |
18305
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
322 { |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
323 if (is_superclass (cls, ctx)) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
324 // Calling a protected method in a superclass. |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
325 return true; |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
326 else if (is_strict_superclass (ctx, cls)) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
327 { |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
328 // Calling a protected method or property in a derived class. |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
329 // This is only allowed if the context class knows about it |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
330 // and has access to it. |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
331 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
332 if (! meth_name.empty ()) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
333 { |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
334 cdef_method m = ctx.find_method (meth_name); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
335 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
336 if (m.ok ()) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
337 return check_access (ctx, m.get ("Access"), meth_name); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
338 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
339 return false; |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
340 } |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
341 else if (! prop_name.empty ()) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
342 { |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
343 cdef_property p = ctx.find_property (prop_name); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
344 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
345 if (p.ok ()) |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
346 { |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
347 octave_value p_access = p.get (is_prop_set ? |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
348 "SetAccess" : |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
349 "GetAccess"); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
350 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
351 return check_access (ctx, p_access, meth_name, |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
352 prop_name, is_prop_set); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
353 } |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
354 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
355 return false; |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
356 } |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
357 else |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
358 panic_impossible (); |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
359 } |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
360 |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
361 return false; |
81c1edd70bfd
Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18263
diff
changeset
|
362 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
363 else |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
364 panic_impossible (); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
365 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
366 } |
25221
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
367 else if (acc.isobject ()) |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
368 { |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
369 cdef_class ctx = get_class_context (); |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
370 |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
371 // At this point, a class context is always required. |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
372 if (ctx.ok ()) |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
373 { |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
374 if (ctx == cls) |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
375 return true; |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
376 |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
377 cdef_class acc_cls (to_cdef (acc)); |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
378 |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
379 if (is_superclass (acc_cls, ctx)) |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
380 return true; |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
381 } |
22ece7843499
Allow a single metaclass for Access property of classdef objects (bug #53601)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
382 } |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
383 else if (acc.iscell ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
384 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
385 Cell acc_c = acc.cell_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
386 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
387 cdef_class ctx = get_class_context (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
388 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
389 // At this point, a class context is always required. |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
390 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
391 if (ctx.ok ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
392 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
393 if (ctx == cls) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
394 return true; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
395 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
396 for (int i = 0; i < acc.numel (); i++) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
397 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
398 cdef_class acc_cls (to_cdef (acc_c(i))); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
399 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
400 if (is_superclass (acc_cls, ctx)) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
401 return true; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
402 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
403 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
404 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
405 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
406 error ("invalid property/method access in class `%s'", |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
407 cls.get_name ().c_str ()); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
408 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
409 return false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
410 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
411 |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
412 static bool |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
413 is_dummy_method (const octave_value& fcn) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
414 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
415 bool retval = false; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
416 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
417 if (fcn.is_defined ()) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
418 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
419 if (fcn.is_user_function ()) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
420 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
421 octave_user_function *uf = fcn.user_function_value (true); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
422 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
423 if (! uf || ! uf->body ()) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
424 retval = true; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
425 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
426 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
427 else |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
428 retval = true; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
429 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
430 return retval; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
431 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
432 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
433 static bool |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
434 is_method_executing (const octave_value& ov, const cdef_object& obj) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
435 { |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
436 octave::tree_evaluator& tw |
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
437 = octave::__get_evaluator__ ("is_method_executing"); |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
438 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
439 octave::call_stack& cs = octave::__get_call_stack__ ("is_method_executing"); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
440 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
441 octave_function *stack_fcn = cs.current (); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
442 |
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
443 octave_function *method_fcn = ov.function_value (true); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
444 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
445 // Does the top of the call stack match our target function? |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
446 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
447 if (stack_fcn && stack_fcn == method_fcn) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
448 { |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
449 octave_user_function *uf = method_fcn->user_function_value (true); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
450 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
451 // We can only check the context object for user-function (not builtin), |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
452 // where we have access to the parameters (arguments and return values). |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
453 // That's ok as there's no need to call this function for builtin |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
454 // methods. |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
455 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
456 if (uf) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
457 { |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
458 // At this point, the method is executing, but we still need to |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
459 // check the context object for which the method is executing. For |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
460 // methods, it's the first argument of the function; for ctors, it |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
461 // is the first return value. |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
462 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
463 octave::tree_parameter_list *pl = uf->is_classdef_constructor () |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
464 ? uf->return_list () : uf->parameter_list (); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
465 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
466 if (pl && pl->size () > 0) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
467 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
468 octave::tree_decl_elt *elt = pl->front (); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
469 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
470 octave_value arg0 = tw.evaluate (elt); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
471 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
472 if (arg0.is_defined () && arg0.type_name () == "object") |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
473 { |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
474 cdef_object arg0_obj = to_cdef (arg0); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
475 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
476 return obj.is (arg0_obj); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
477 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
478 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
479 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
480 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
481 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
482 return false; |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
483 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
484 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
485 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
486 class_get_methods (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
487 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
488 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
489 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
490 if (args.length () == 1 && args(0).type_name () == "object") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
491 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
492 cdef_class cls (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
493 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
494 retval(0) = cls.get_methods (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
495 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
496 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
497 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
498 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
499 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
500 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
501 class_get_superclasses (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
502 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
503 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
504 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
505 if (args.length () == 1 && args(0).type_name () == "object" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
506 && args(0).class_name () == "meta.class") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
507 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
508 cdef_class cls (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
509 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
510 Cell classes = cls.get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
511 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
512 retval(0) = to_ov (lookup_classes (classes)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
513 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
514 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
515 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
516 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
517 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
518 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
519 class_get_inferiorclasses (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
520 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
521 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
522 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
523 if (args.length () == 1 && args(0).type_name () == "object" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
524 && args(0).class_name () == "meta.class") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
525 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
526 cdef_class cls (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
527 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
528 Cell classes = cls.get ("InferiorClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
529 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
530 retval(0) = to_ov (lookup_classes (classes)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
531 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
532 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
533 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
534 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
535 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
536 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
537 class_fromName (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
538 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
539 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
540 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
541 if (args.length () != 1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
542 error ("fromName: invalid number of parameters"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
543 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
544 std::string name = args(0).xstring_value ("fromName: CLASS_NAME must be a string"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
545 |
24100
4d9ceaf17dda
return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents:
23865
diff
changeset
|
546 retval(0) = to_ov (lookup_class (name, false)); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
547 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
548 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
549 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
550 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
551 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
552 class_fevalStatic (const octave_value_list& args, int nargout) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
553 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
554 if (args.length () <= 1 || args(0).type_name () != "object") |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
555 error ("fevalStatic: first argument must be a meta.class object"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
556 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
557 cdef_class cls (to_cdef (args(0))); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
558 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
559 std::string meth_name = args(1).xstring_value ("fevalStatic: method name must be a string"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
560 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
561 cdef_method meth = cls.find_method (meth_name); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
562 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
563 if (! meth.ok ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
564 error ("fevalStatic: method not found: %s", meth_name.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
565 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
566 if (! meth.is_static ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
567 error ("fevalStatic: method `%s' is not static", meth_name.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
568 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
569 return meth.execute (args.splice (0, 2), nargout, true, "fevalStatic"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
570 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
571 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
572 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
573 class_getConstant (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
574 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
575 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
576 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
577 if (args.length () != 2 || args(0).type_name () != "object" |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
578 || args(0).class_name () != "meta.class") |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
579 error ("getConstant: first argument must be a meta.class object"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
580 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
581 cdef_class cls = to_cdef (args(0)); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
582 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
583 std::string prop_name = args(1).xstring_value ("getConstant: property name must be a string"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
584 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
585 cdef_property prop = cls.find_property (prop_name); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
586 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
587 if (! prop.ok ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
588 error ("getConstant: property not found: %s", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
589 prop_name.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
590 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
591 if (! prop.is_constant ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
592 error ("getConstant: property `%s' is not constant", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
593 prop_name.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
594 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
595 retval(0) = prop.get_value (true, "getConstant"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
596 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
597 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
598 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
599 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
600 #define META_CLASS_CMP(OP, CLSA, CLSB, FUN) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
601 static octave_value_list \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
602 class_ ## OP (const octave_value_list& args, int /* nargout */) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
603 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
604 octave_value_list retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
605 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
606 if (args.length () != 2 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
607 || args(0).type_name () != "object" \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
608 || args(1).type_name () != "object" \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
609 || args(0).class_name () != "meta.class" \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
610 || args(1).class_name () != "meta.class") \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
611 error (#OP ": invalid arguments"); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
612 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
613 cdef_class clsa = to_cdef (args(0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
614 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
615 cdef_class clsb = to_cdef (args(1)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
616 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
617 retval(0) = FUN (CLSA, CLSB); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
618 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
619 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22182
diff
changeset
|
620 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
621 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
622 META_CLASS_CMP (lt, clsb, clsa, is_strict_superclass) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
623 META_CLASS_CMP (le, clsb, clsa, is_superclass) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
624 META_CLASS_CMP (gt, clsa, clsb, is_strict_superclass) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
625 META_CLASS_CMP (ge, clsa, clsb, is_superclass) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
626 META_CLASS_CMP (eq, clsa, clsb, operator==) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
627 META_CLASS_CMP (ne, clsa, clsb, operator!=) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
628 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
629 octave_value_list |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
630 property_get_defaultvalue (const octave_value_list& args, int /* nargout */) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
631 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
632 octave_value_list retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
633 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
634 if (args.length () == 1 && args(0).type_name () == "object") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
635 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
636 cdef_property prop (to_cdef (args(0))); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
637 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
638 retval(0) = prop.get ("DefaultValue"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
639 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
640 if (! retval(0).is_defined ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
641 error_with_id ("Octave:class:NotDefaultDefined", |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
642 "no default value for property `%s'", |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
643 prop.get_name ().c_str ()); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
644 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
645 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
646 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
647 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
648 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
649 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
650 handle_delete (const octave_value_list& /* args */, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
651 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
652 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
653 |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
654 // FIXME: implement this. Wait, what is this supposed to do? |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
655 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
656 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
657 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
658 |
24539 | 659 cdef_class |
660 cdef_manager::make_class (const std::string& name, | |
661 const std::list<cdef_class>& super_list) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
662 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
663 cdef_class cls (name, super_list); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
664 |
24539 | 665 cls.set_class (meta_class ()); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
666 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
667 cls.put ("Abstract", false); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
668 cls.put ("ConstructOnLoad", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
669 cls.put ("ContainingPackage", Matrix ()); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
670 cls.put ("Description", ""); |
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
671 cls.put ("DetailedDescription", ""); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
672 cls.put ("Events", Cell ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
673 cls.put ("Hidden", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
674 cls.put ("InferiorClasses", Cell ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
675 cls.put ("Methods", Cell ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
676 cls.put ("Properties", Cell ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
677 cls.put ("Sealed", false); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
678 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
679 if (name == "handle") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
680 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
681 cls.put ("HandleCompatible", true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
682 cls.mark_as_handle_class (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
683 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
684 else if (super_list.empty ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
685 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
686 cls.put ("HandleCompatible", false); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
687 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
688 else |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
689 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
690 bool all_handle_compatible = true; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
691 bool has_handle_class = false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
692 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
693 for (const auto& cl : super_list) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
694 { |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
695 all_handle_compatible = all_handle_compatible |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
696 && cl.get ("HandleCompatible").bool_value (); |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
697 has_handle_class = has_handle_class || cl.is_handle_class (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
698 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
699 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
700 if (has_handle_class && ! all_handle_compatible) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
701 error ("%s: cannot mix handle and non-HandleCompatible classes", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
702 name.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
703 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
704 cls.put ("HandleCompatible", all_handle_compatible); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
705 if (has_handle_class) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
706 cls.mark_as_handle_class (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
707 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
708 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
709 if (! name.empty ()) |
24539 | 710 register_class (cls); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
711 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
712 return cls; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
713 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
714 |
24539 | 715 cdef_class |
716 cdef_manager::make_class (const std::string& name, | |
717 const cdef_class& super) | |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
718 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
719 return make_class (name, std::list<cdef_class> (1, super)); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
720 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
721 |
24539 | 722 cdef_class |
723 cdef_manager::make_meta_class (const std::string& name, | |
724 const cdef_class& super) | |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
725 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
726 cdef_class cls = make_class (name, super); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
727 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
728 cls.put ("Sealed", true); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
729 cls.mark_as_meta_class (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
730 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
731 return cls; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
732 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
733 |
24539 | 734 cdef_property |
735 cdef_manager::make_property (const cdef_class& cls, const std::string& name, | |
736 const octave_value& get_method, | |
737 const std::string& get_access, | |
738 const octave_value& set_method, | |
739 const std::string& set_access) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
740 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
741 cdef_property prop (name); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
742 |
24539 | 743 prop.set_class (meta_property ()); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
744 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
745 prop.put ("Description", ""); |
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
746 prop.put ("DetailedDescription", ""); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
747 prop.put ("Abstract", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
748 prop.put ("Constant", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
749 prop.put ("GetAccess", get_access); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
750 prop.put ("SetAccess", set_access); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
751 prop.put ("Dependent", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
752 prop.put ("Transient", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
753 prop.put ("Hidden", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
754 prop.put ("GetObservable", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
755 prop.put ("SetObservable", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
756 prop.put ("GetMethod", get_method); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
757 prop.put ("SetMethod", set_method); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
758 prop.put ("DefiningClass", to_ov (cls)); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
759 prop.put ("DefaultValue", octave_value ()); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
760 prop.put ("HasDefault", false); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
761 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
762 std::string class_name = cls.get_name (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
763 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
764 if (! get_method.isempty ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
765 make_function_of_class (class_name, get_method); |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
766 if (! set_method.isempty ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
767 make_function_of_class (class_name, set_method); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
768 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
769 return prop; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
770 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
771 |
24539 | 772 cdef_property |
773 cdef_manager::make_attribute (const cdef_class& cls, const std::string& name) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
774 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
775 return make_property (cls, name, Matrix (), "public", Matrix (), "private"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
776 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
777 |
24539 | 778 cdef_method |
779 cdef_manager::make_method (const cdef_class& cls, const std::string& name, | |
780 const octave_value& fcn, | |
781 const std::string& m_access, bool is_static) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
782 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
783 cdef_method meth (name); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
784 |
24539 | 785 meth.set_class (meta_method ()); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
786 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
787 meth.put ("Abstract", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
788 meth.put ("Access", m_access); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
789 meth.put ("DefiningClass", to_ov (cls)); |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
790 meth.put ("Description", ""); |
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
791 meth.put ("DetailedDescription", ""); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
792 meth.put ("Hidden", false); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
793 meth.put ("Sealed", true); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
794 meth.put ("Static", is_static); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
795 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
796 if (fcn.is_defined ()) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
797 make_function_of_class (cls, fcn); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
798 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
799 meth.set_function (fcn); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
800 |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
801 if (is_dummy_method (fcn)) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
802 meth.mark_as_external (cls.get_name ()); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
803 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
804 return meth; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
805 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
806 |
24539 | 807 cdef_method |
808 cdef_manager::make_method (const cdef_class& cls, const std::string& name, | |
809 octave_builtin::fcn ff, | |
810 const std::string& m_access, bool is_static) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
811 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
812 octave_value fcn (new octave_builtin (ff, name)); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
813 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
814 return make_method (cls, name, fcn, m_access, is_static); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
815 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
816 |
24539 | 817 cdef_method |
818 cdef_manager::make_method (const cdef_class& cls, const std::string& name, | |
819 octave_builtin::meth mm, | |
820 const std::string& m_access, bool is_static) | |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
821 { |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
822 octave_value fcn (new octave_builtin (mm, name)); |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
823 |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
824 return make_method (cls, name, fcn, m_access, is_static); |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
825 } |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
826 |
24539 | 827 cdef_package |
828 cdef_manager::make_package (const std::string& nm, const std::string& parent) | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
829 { |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
830 cdef_package pack (nm); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
831 |
24539 | 832 pack.set_class (meta_package ()); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
833 |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
834 if (parent.empty ()) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
835 pack.put ("ContainingPackage", Matrix ()); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
836 else |
24539 | 837 pack.put ("ContainingPackage", to_ov (find_package (parent))); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
838 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
839 if (! nm.empty ()) |
24539 | 840 register_package (pack); |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
841 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
842 return pack; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
843 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
844 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
845 //---------------------------------------------------------------------------- |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
846 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
847 int octave_classdef::t_id (-1); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
848 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
849 const std::string octave_classdef::t_name ("object"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
850 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
851 void |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
852 octave_classdef::register_type (octave::type_info& ti) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
853 { |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
854 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
|
855 octave_value (new octave_classdef ())); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
856 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
857 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
858 octave_value_list |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
859 octave_classdef::subsref (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
860 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
861 int nargout) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
862 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
863 size_t skip = 0; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
864 octave_value_list retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
865 |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
866 cdef_class cls = object.get_class (); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
867 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
868 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
|
869 { |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
870 cdef_method meth = cls.find_method ("subsref"); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
871 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
872 if (meth.ok ()) |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
873 { |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
874 octave_value_list args; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
875 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
876 args(1) = make_idx_args (type, idx, "subsref"); |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
877 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
878 count++; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
879 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
880 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
881 retval = meth.execute (args, nargout, true, "subsref"); |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
882 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
883 return retval; |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
884 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
885 } |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
886 |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
887 // 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
|
888 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
889 retval = object.subsref (type, idx, nargout, skip, cdef_class ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
890 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
891 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
|
892 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
|
893 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
894 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
895 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
896 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
897 octave_value |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
898 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
|
899 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
|
900 bool auto_add) |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
901 { |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
902 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
|
903 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
|
904 |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
905 // 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
|
906 // assignment with multi-level indexing. AFAIK this is only used for internal |
18314
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
907 // purpose (not sure we should even implement this) and any overload subsref |
06eb893b9db6
Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18305
diff
changeset
|
908 // should not be called. |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
909 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
910 retval = object.subsref (type, idx, 1, skip, cdef_class (), auto_add); |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
911 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
912 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
|
913 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
|
914 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
915 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
|
916 } |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
917 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
918 octave_value |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
919 octave_classdef::subsasgn (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
920 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
921 const octave_value& rhs) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
922 { |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
923 octave_value retval; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
924 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
925 cdef_class cls = object.get_class (); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
926 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
927 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
|
928 { |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
929 cdef_method meth = cls.find_method ("subsasgn"); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
930 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
931 if (meth.ok ()) |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
932 { |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
933 octave_value_list args; |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
934 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
935 args(1) = make_idx_args (type, idx, "subsasgn"); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
936 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
937 count++; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
938 args(0) = octave_value (this); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
939 args(2) = rhs; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
940 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
941 octave_value_list retlist; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
942 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
943 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
|
944 |
21885
0806871e3e1e
maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
945 if (retlist.empty ()) |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
946 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
|
947 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
948 retval = retlist(0); |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
949 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
950 } |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
951 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
952 if (! retval.is_defined ()) |
18382
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
953 retval = object.subsasgn (type, idx, rhs); |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
954 |
6e3344111522
Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18355
diff
changeset
|
955 return retval; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
956 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
957 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
958 octave_value |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
959 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
|
960 const std::list<octave_value_list>& idx, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
961 const octave_value& rhs) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
962 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
963 if (type.length () == 1 && type[0] == '(') |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
964 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
965 object = object.make_array (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
966 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
967 return subsasgn (type, idx, rhs); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
968 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
969 else |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
970 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
|
971 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
972 return octave_value (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
973 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
974 |
24802
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
975 octave_idx_type |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
976 octave_classdef::numel (const octave_value_list& idx) |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
977 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
978 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
|
979 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
980 cdef_class cls = object.get_class (); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
981 |
26525
0d3eca5955dc
Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents:
26449
diff
changeset
|
982 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
|
983 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
984 cdef_method meth = cls.find_method ("numel"); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
985 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
986 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
|
987 { |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
988 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
|
989 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
990 count++; |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
991 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
|
992 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
993 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
|
994 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
|
995 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1000 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
|
1001 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1002 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
|
1003 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1004 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1005 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1006 retval = octave_base_value::numel (idx); |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1007 |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1008 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
|
1009 } |
7605e06a50d5
tie octave_classdef::numel method to "numel" user override method (bug #46571)
Sébastien Villemot <sebastien@debian.org>
parents:
23219
diff
changeset
|
1010 |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1011 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1012 octave_classdef::print (std::ostream& os, bool) |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1013 { |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1014 print_raw (os); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1015 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1016 |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1017 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1018 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
|
1019 { |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1020 indent (os); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1021 os << "<object "; |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1022 if (object.is_array ()) |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1023 os << "array "; |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
1024 os << class_name () << '>'; |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1025 newline (os); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1026 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1027 |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1028 bool |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1029 octave_classdef::print_name_tag (std::ostream& os, |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1030 const std::string& name) const |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1031 { |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1032 return octave_base_value::print_name_tag (os, name); |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1033 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1034 |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1035 void |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1036 octave_classdef::print_with_name (std::ostream& os, const std::string& name, |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1037 bool print_padding) |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1038 { |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22871
diff
changeset
|
1039 octave_base_value::print_with_name (os, name, print_padding); |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1040 } |
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18397
diff
changeset
|
1041 |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1042 bool |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1043 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
|
1044 { |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1045 cdef_class cls = lookup_class (cls_name, false, false); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1046 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1047 if (cls.ok ()) |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1048 return is_superclass (cls, object.get_class ()); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1049 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1050 return false; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1051 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19031
diff
changeset
|
1052 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1053 //---------------------------------------------------------------------------- |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1054 |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1055 class octave_classdef_meta : public octave_function |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1056 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1057 public: |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1058 octave_classdef_meta (const cdef_meta_object& obj) |
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1059 : object (obj) { } |
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1060 |
25321
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1061 octave_classdef_meta (const octave_classdef_meta&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1062 |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1063 octave_classdef_meta& operator = (const octave_classdef_meta&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1064 |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1065 ~octave_classdef_meta (void) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1066 { object.meta_release (); } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1067 |
23683
ffd27f53fc79
make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents:
23666
diff
changeset
|
1068 bool is_classdef_meta (void) const { return true; } |
23843
a52eb3f210af
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23838
diff
changeset
|
1069 |
23838
6e0fd7e3c262
Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents:
23829
diff
changeset
|
1070 bool is_package (void) const { return object.is_package(); } |
23683
ffd27f53fc79
make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents:
23666
diff
changeset
|
1071 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
1072 octave_function * function_value (bool = false) { return this; } |
15955
837a4a9b5049
Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15913
diff
changeset
|
1073 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1074 octave_value_list |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1075 subsref (const std::string& type, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1076 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1077 int nargout) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1078 { |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
1079 return object.meta_subsref (type, idx, nargout); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1080 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1081 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
1082 octave_value_list call (octave::tree_evaluator&, int nargout, |
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
1083 const octave_value_list& args) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1084 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1085 // Emulate ()-type meta subsref |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1086 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
1087 std::list<octave_value_list> idx (1, args); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1088 std::string type ("("); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1089 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
1090 return subsref (type, idx, nargout); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1091 } |
15955
837a4a9b5049
Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15913
diff
changeset
|
1092 |
23503
6a2fed2d39ac
improve some function names
John W. Eaton <jwe@octave.org>
parents:
23502
diff
changeset
|
1093 bool accepts_postfix_index (char type) const |
6a2fed2d39ac
improve some function names
John W. Eaton <jwe@octave.org>
parents:
23502
diff
changeset
|
1094 { return object.meta_accepts_postfix_index (type); } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1095 |
18441
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18439
diff
changeset
|
1096 bool |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
1097 is_classdef_constructor (const std::string& cname = "") const |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1098 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1099 bool retval = false; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1100 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1101 if (object.is_class ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1102 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1103 if (cname.empty ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1104 retval = true; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1105 else |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1106 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1107 cdef_class cls (object); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1108 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1109 if (cls.get_name () == cname) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1110 retval = true; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1111 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1112 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1113 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1114 return retval; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1115 } |
18441
b0aba84cf80f
Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18439
diff
changeset
|
1116 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1117 private: |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
1118 cdef_meta_object object; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1119 }; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1120 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1121 //---------------------------------------------------------------------------- |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1122 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1123 class octave_classdef_superclass_ref : public octave_function |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1124 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1125 public: |
25321
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1126 octave_classdef_superclass_ref (void) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1127 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1128 octave_classdef_superclass_ref (const std::string& meth_or_obj, |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1129 const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1130 : octave_function (), m_method_or_object_name (meth_or_obj), |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1131 m_class_name (cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1132 { } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1133 |
25321
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1134 octave_classdef_superclass_ref (const octave_classdef_superclass_ref&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1135 |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1136 octave_classdef_superclass_ref& operator = (const octave_classdef_superclass_ref&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1137 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1138 ~octave_classdef_superclass_ref (void) = default; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1139 |
24114
90932304969a
maint: use correct const qualifier on overridden virtual function
Mike Miller <mtmiller@octave.org>
parents:
24100
diff
changeset
|
1140 bool is_classdef_superclass_ref (void) const { return true; } |
23865
d56c18dc1373
new predicates for classdef_superclass_ref objects
John W. Eaton <jwe@octave.org>
parents:
23843
diff
changeset
|
1141 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
1142 octave_function * function_value (bool = false) { return this; } |
18355
9ca314e79956
Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18316
diff
changeset
|
1143 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1144 octave_value_list |
25360
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
1145 call (octave::tree_evaluator& tw, int nargout, const octave_value_list& idx) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1146 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1147 octave_value_list retval; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1148 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1149 std::string meth_name; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1150 bool in_constructor; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1151 cdef_class ctx; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1152 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1153 ctx = get_class_context (meth_name, in_constructor); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1154 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1155 if (! ctx.ok ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1156 error ("superclass calls can only occur in methods or constructors"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1157 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1158 std::string mname = m_method_or_object_name; |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1159 std::string cname = m_class_name; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1160 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1161 cdef_class cls = lookup_class (cname); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1162 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1163 if (in_constructor) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1164 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1165 if (! is_direct_superclass (cls, ctx)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1166 error ("`%s' is not a direct superclass of `%s'", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1167 cname.c_str (), ctx.get_name ().c_str ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1168 |
25360
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
1169 if (! is_constructed_object (tw, mname)) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1170 error ("cannot call superclass constructor with variable `%s'", |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1171 mname.c_str ()); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1172 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
1173 octave_value sym = tw.varval (mname); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1174 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1175 cls.run_constructor (to_cdef_ref (sym), idx); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1176 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1177 retval(0) = sym; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1178 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1179 else |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1180 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1181 if (mname != meth_name) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1182 error ("method name mismatch (`%s' != `%s')", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1183 mname.c_str (), meth_name.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1184 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1185 if (! is_strict_superclass (cls, ctx)) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1186 error ("`%s' is not a superclass of `%s'", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1187 cname.c_str (), ctx.get_name ().c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1188 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1189 // I see 2 possible implementations here: |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1190 // 1) use cdef_object::subsref with a different class |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1191 // context; this avoids duplicating code, but |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1192 // assumes the object is always the first argument |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1193 // 2) lookup the method manually and call |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1194 // cdef_method::execute; this duplicates part of |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1195 // logic in cdef_object::subsref, but avoid the |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1196 // assumption of 1) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1197 // Not being sure about the assumption of 1), I |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1198 // go with option 2) for the time being. |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1199 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1200 cdef_method meth = cls.find_method (meth_name, false); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1201 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1202 if (! meth.ok ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1203 error ("no method `%s' found in superclass `%s'", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1204 meth_name.c_str (), cname.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1205 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1206 retval = meth.execute (idx, nargout, true, |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1207 meth_name); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1208 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1209 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1210 return retval; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1211 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1212 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1213 private: |
25360
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
1214 bool is_constructed_object (octave::tree_evaluator& tw, |
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
1215 const std::string& nm) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1216 { |
25360
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
1217 octave::call_stack& cs = tw.get_call_stack (); |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
1218 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23534
diff
changeset
|
1219 octave_function *of = cs.current (); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1220 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1221 if (of->is_classdef_constructor ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1222 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1223 octave_user_function *uf = of->user_function_value (true); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1224 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1225 if (uf) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1226 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1227 octave::tree_parameter_list *ret_list = uf->return_list (); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1228 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1229 if (ret_list && ret_list->length () == 1) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1230 return (ret_list->front ()->name () == nm); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1231 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1232 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1233 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1234 return false; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1235 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1236 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1237 private: |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1238 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1239 std::string m_method_or_object_name; |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1240 std::string m_class_name; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1241 }; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1242 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1243 octave_value |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1244 octave_classdef::superclass_ref (const std::string& meth_or_obj, |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1245 const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1246 { |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1247 return octave_value (new octave_classdef_superclass_ref (meth_or_obj, cls)); |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1248 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1249 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1250 octave_value |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1251 octave_classdef::metaclass_query (const std::string& cls) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1252 { |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1253 return to_ov (lookup_class (cls)); |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1254 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
1255 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1256 //---------------------------------------------------------------------------- |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1257 |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1258 void |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1259 cdef_object_rep::release (const cdef_object& obj) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1260 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1261 // We need to be careful to keep a reference to the object if we are |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1262 // calling the delete method. The object is passed to the delete |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1263 // method as an argument and if the count is already zero when we |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1264 // do that, then we will increment the count while creating the |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1265 // argument list for the delete method and then it will be decremented |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1266 // back to zero and we'll find ourselves in an infinite loop. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1267 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1268 if (refcount - 1 > static_count ()) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1269 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1270 --refcount; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1271 return; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1272 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1273 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1274 if (is_handle_object () && ! is_meta_object ()) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1275 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1276 octave::unwind_protect frame; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1277 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1278 // Clear interrupts. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1279 frame.protect_var (octave_interrupt_state); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1280 octave_interrupt_state = 0; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1281 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1282 // Disallow quit(). |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1283 frame.protect_var (quit_allowed); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1284 quit_allowed = false; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1285 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1286 interpreter_try (frame); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1287 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1288 try |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1289 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1290 // Call classdef "delete()" method on object |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1291 get_class ().delete_object (obj); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1292 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1293 catch (const octave::interrupt_exception&) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1294 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1295 octave::interpreter::recover_from_exception (); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1296 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1297 warning ("interrupt occurred in handle class delete method"); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1298 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1299 catch (const octave::execution_exception&) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1300 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1301 std::string msg = last_error_message (); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1302 warning ("error caught while executing handle class delete method:\n%s\n", |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1303 msg.c_str ()); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1304 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1305 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1306 catch (const octave::exit_exception&) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1307 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1308 // This shouldn't happen since we disabled quit above. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1309 warning ("exit disabled while executing handle class delete method"); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1310 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1311 catch (...) // Yes, the black hole. We're in a d-tor. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1312 { |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1313 // This shouldn't happen, in theory. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1314 warning ("internal error: unhandled exception in handle class delete method"); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1315 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1316 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1317 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1318 // Now it is safe to set the count to zero. |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1319 refcount--; |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1320 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1321 destroy (); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1322 } |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
1323 |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1324 octave_map |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1325 cdef_object::map_value (void) const |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1326 { |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1327 octave_map retval; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1328 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1329 warning_with_id ("Octave:classdef-to-struct", |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1330 "struct: converting a classdef object into a struct " |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1331 "overrides the access restrictions defined for properties. " |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1332 "All properties are returned, including private and " |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1333 "protected ones."); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1334 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1335 cdef_class cls = get_class (); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1336 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1337 if (cls.ok ()) |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1338 { |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1339 std::map<std::string, cdef_property> props; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1340 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1341 props = cls.get_property_map (cdef_class::property_all); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1342 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1343 // FIXME: Why not const here? |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1344 for (auto& prop_val : props) |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1345 { |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1346 if (is_array ()) |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1347 { |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1348 Array<cdef_object> a_obj = array_value (); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1349 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1350 Cell cvalue (a_obj.dims ()); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1351 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1352 for (octave_idx_type i = 0; i < a_obj.numel (); i++) |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1353 cvalue (i) = prop_val.second.get_value (a_obj(i), false); |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1354 |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1355 retval.setfield (prop_val.first, cvalue); |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1356 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1357 else |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1358 { |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1359 Cell cvalue (dim_vector (1, 1), |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1360 prop_val.second.get_value (*this, false)); |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1361 |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1362 retval.setfield (prop_val.first, cvalue); |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1363 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1364 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1365 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1366 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1367 return retval; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1368 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
1369 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1370 string_vector |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1371 cdef_object_rep::map_keys (void) const |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1372 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1373 cdef_class cls = get_class (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1374 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1375 if (cls.ok ()) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1376 return cls.get_names (); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
1377 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1378 return string_vector (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1379 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1380 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1381 octave_value_list |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1382 cdef_object_scalar::subsref (const std::string& type, |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1383 const std::list<octave_value_list>& idx, |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1384 int nargout, size_t& skip, |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1385 const cdef_class& context, bool auto_add) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1386 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1387 skip = 0; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1388 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1389 cdef_class cls = (context.ok () ? context : get_class ()); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1390 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1391 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1392 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1393 if (! cls.ok ()) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1394 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1395 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1396 switch (type[0]) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1397 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1398 case '.': |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1399 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1400 std::string name = (idx.front ())(0).string_value (); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1401 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1402 cdef_method meth = cls.find_method (name); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1403 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1404 if (meth.ok ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1405 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1406 int _nargout = (type.length () > 2 ? 1 : nargout); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1407 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1408 octave_value_list args; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1409 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1410 skip = 1; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1411 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1412 if (type.length () > 1 && type[1] == '(') |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1413 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
1414 auto it = idx.begin (); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1415 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1416 args = *++it; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1417 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1418 skip++; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1419 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1420 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1421 if (meth.is_static ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1422 retval = meth.execute (args, _nargout, true, "subsref"); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1423 else |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1424 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1425 refcount++; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1426 retval = meth.execute (cdef_object (this), args, _nargout, |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1427 true, "subsref"); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1428 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1429 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1430 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1431 if (skip == 0) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1432 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1433 cdef_property prop = cls.find_property (name); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1434 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1435 if (! prop.ok ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1436 error ("subsref: unknown method or property: %s", name.c_str ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1437 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1438 if (prop.is_constant ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1439 retval(0) = prop.get_value (true, "subsref"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1440 else |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1441 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1442 refcount++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1443 retval(0) = prop.get_value (cdef_object (this), |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1444 true, "subsref"); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1445 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1446 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1447 skip = 1; |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1448 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1449 break; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1450 } |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1451 |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1452 case '(': |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1453 { |
20189
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1454 const octave_value_list& ival = idx.front (); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1455 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1456 refcount++; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1457 cdef_object this_obj (this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1458 |
20189
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1459 if (ival.empty ()) |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1460 { |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1461 skip++; |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1462 retval(0) = to_ov (this_obj); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1463 } |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1464 else |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1465 { |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1466 Array<cdef_object> arr (dim_vector (1, 1), this_obj); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1467 |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1468 cdef_object new_obj = cdef_object (new cdef_object_array (arr)); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1469 |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1470 new_obj.set_class (get_class ()); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1471 |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1472 retval = new_obj.subsref (type, idx, nargout, skip, cls, auto_add); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1473 } |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1474 } |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1475 break; |
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1476 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1477 default: |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1478 error ("object cannot be indexed with `%c'", type[0]); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1479 break; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1480 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1481 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1482 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1483 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1484 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1485 octave_value |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1486 cdef_object_scalar::subsasgn (const std::string& type, |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1487 const std::list<octave_value_list>& idx, |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1488 const octave_value& rhs) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1489 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1490 octave_value retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1491 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1492 cdef_class cls = get_class (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1493 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1494 switch (type[0]) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1495 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1496 case '.': |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1497 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1498 std::string name = (idx.front ())(0).string_value (); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1499 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1500 cdef_property prop = cls.find_property (name); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1501 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1502 if (! prop.ok ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1503 error ("subsasgn: unknown property: %s", name.c_str ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1504 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1505 if (prop.is_constant ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1506 error ("subsasgn: cannot assign constant property: %s", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1507 name.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1508 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1509 refcount++; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1510 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1511 cdef_object obj (this); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1512 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1513 if (type.length () == 1) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1514 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1515 prop.set_value (obj, rhs, true, "subsasgn"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1516 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1517 retval = to_ov (obj); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1518 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
1519 else |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1520 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1521 octave_value val = |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1522 prop.get_value (obj, true, "subsasgn"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1523 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1524 std::list<octave_value_list> args (idx); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1525 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1526 args.erase (args.begin ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1527 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1528 val = val.assign (octave_value::op_asn_eq, |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1529 type.substr (1), args, rhs); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1530 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1531 if (val.class_name () != "object" |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1532 || ! to_cdef (val).is_handle_object ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1533 prop.set_value (obj, val, true, "subsasgn"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1534 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1535 retval = to_ov (obj); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1536 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1537 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1538 break; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1539 |
16694
50b37deadb66
Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16692
diff
changeset
|
1540 case '(': |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1541 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1542 refcount++; |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1543 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1544 cdef_object this_obj (this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1545 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1546 Array<cdef_object> arr (dim_vector (1, 1), this_obj); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1547 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1548 cdef_object new_obj = cdef_object (new cdef_object_array (arr)); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1549 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1550 new_obj.set_class (get_class ()); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1551 |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1552 octave_value tmp = new_obj.subsasgn (type, idx, rhs); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1553 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1554 retval = tmp; |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1555 } |
16694
50b37deadb66
Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16692
diff
changeset
|
1556 break; |
50b37deadb66
Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16692
diff
changeset
|
1557 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1558 default: |
16694
50b37deadb66
Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16692
diff
changeset
|
1559 error ("subsasgn: object cannot be index with `%c'", type[0]); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1560 break; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1561 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1562 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1563 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1564 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1565 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1566 void |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1567 cdef_object_scalar::mark_for_construction (const cdef_class& cls) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1568 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1569 std::string cls_name = cls.get_name (); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1570 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1571 Cell supcls = cls.get ("SuperClasses").cell_value (); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1572 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1573 std::list<cdef_class> supcls_list = lookup_classes (supcls); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1574 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1575 ctor_list[cls] = supcls_list; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1576 } |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1577 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1578 octave_value_list |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1579 cdef_object_array::subsref (const std::string& type, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1580 const std::list<octave_value_list>& idx, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1581 int /* nargout */, size_t& skip, |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1582 const cdef_class& /* context */, bool auto_add) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1583 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1584 octave_value_list retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1585 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1586 skip = 1; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1587 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1588 switch (type[0]) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1589 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1590 case '(': |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1591 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1592 const octave_value_list& ival = idx.front (); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1593 |
20125
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
1594 if (ival.empty ()) |
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
1595 { |
20189
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1596 refcount++; |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1597 retval(0) = to_ov (cdef_object (this)); |
20125
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
1598 break; |
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
1599 } |
274b52724931
Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents:
20052
diff
changeset
|
1600 |
20189
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1601 bool is_scalar = true; |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1602 Array<idx_vector> iv (dim_vector (1, ival.length ())); |
b2532deba721
Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents:
20125
diff
changeset
|
1603 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1604 for (int i = 0; i < ival.length (); i++) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1605 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1606 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1607 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1608 iv(i) = ival(i).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1609 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22324
diff
changeset
|
1610 catch (octave::index_exception& e) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1611 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1612 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1613 e.set_pos_if_unset (ival.length (), i+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1614 throw; |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1615 } |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1616 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1617 is_scalar = is_scalar && iv(i).is_scalar (); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1618 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1619 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1620 Array<cdef_object> ires = array.index (iv, auto_add); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1621 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1622 // If resizing is enabled (auto_add = true), it's possible |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1623 // indexing was out-of-bound and the result array contains |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1624 // invalid cdef_objects. |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1625 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1626 if (auto_add) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1627 fill_empty_values (ires); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1628 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1629 if (is_scalar) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1630 retval(0) = to_ov (ires(0)); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1631 else |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1632 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1633 cdef_object array_obj (new cdef_object_array (ires)); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1634 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1635 array_obj.set_class (get_class ()); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1636 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1637 retval(0) = to_ov (array_obj); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1638 } |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1639 } |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1640 break; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1641 |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1642 case '.': |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1643 if (type.size () == 1 && idx.size () == 1) |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1644 { |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1645 Cell c (dims ()); |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1646 |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1647 octave_idx_type n = array.numel (); |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1648 |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1649 // dummy variables |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1650 size_t dummy_skip; |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1651 cdef_class dummy_cls; |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1652 |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1653 for (octave_idx_type i = 0; i < n; i++) |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1654 { |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1655 octave_value_list r = array(i).subsref (type, idx, 1, dummy_skip, |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1656 dummy_cls); |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1657 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1658 if (r.length () > 0) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1659 c(i) = r(0); |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1660 } |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1661 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1662 retval(0) = octave_value (c, true); |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1663 |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1664 break; |
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1665 } |
23826
d69021d58a61
avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1666 OCTAVE_FALLTHROUGH; |
16692
b9833510355d
Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16691
diff
changeset
|
1667 |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1668 default: |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
1669 error ("can't perform indexing operation on array of %s objects", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
1670 class_name ().c_str ()); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1671 break; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1672 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1673 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1674 return retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1675 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1676 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1677 octave_value |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1678 cdef_object_array::subsasgn (const std::string& type, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1679 const std::list<octave_value_list>& idx, |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1680 const octave_value& rhs) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1681 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1682 octave_value retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1683 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1684 switch (type[0]) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1685 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1686 case '(': |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1687 if (type.length () == 1) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1688 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1689 cdef_object rhs_obj = to_cdef (rhs); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1690 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1691 if (rhs_obj.get_class () != get_class ()) |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1692 error ("can't assign %s object into array of %s objects.", |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1693 rhs_obj.class_name ().c_str (), |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1694 class_name ().c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1695 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1696 const octave_value_list& ival = idx.front (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1697 bool is_scalar = true; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1698 Array<idx_vector> iv (dim_vector (1, ival.length ())); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1699 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1700 for (int i = 0; i < ival.length (); i++) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1701 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1702 try |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1703 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1704 iv(i) = ival(i).index_vector (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1705 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22324
diff
changeset
|
1706 catch (octave::index_exception& e) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1707 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1708 e.set_pos_if_unset (ival.length (), i+1); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1709 throw; // var name set in pt-idx.cc / pt-assign.cc |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1710 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1711 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1712 is_scalar = is_scalar && iv(i).is_scalar (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1713 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1714 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1715 Array<cdef_object> rhs_mat; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1716 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1717 if (! rhs_obj.is_array ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1718 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1719 rhs_mat = Array<cdef_object> (dim_vector (1, 1)); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1720 rhs_mat(0) = rhs_obj; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1721 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1722 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1723 rhs_mat = rhs_obj.array_value (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1724 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1725 octave_idx_type n = array.numel (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1726 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1727 array.assign (iv, rhs_mat, cdef_object ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1728 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1729 if (array.numel () > n) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1730 fill_empty_values (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1731 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1732 refcount++; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1733 retval = to_ov (cdef_object (this)); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1734 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1735 else |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1736 { |
23345
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1737 const octave_value_list& ivl = idx.front (); |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1738 |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1739 // Fill in trailing singleton dimensions so that |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1740 // array.index doesn't create a new blank entry (bug #46660). |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1741 const octave_idx_type one = static_cast<octave_idx_type> (1); |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1742 const octave_value_list& ival = ivl.length () >= 2 |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1743 ? ivl : ((array.dims ()(0) == 1) |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1744 ? ovl (one, ivl(0)) |
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1745 : ovl (ivl(0), one)); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1746 |
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1747 bool is_scalar = true; |
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1748 |
23345
0b6810085ed3
Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23220
diff
changeset
|
1749 Array<idx_vector> iv (dim_vector (1, ival.length ())); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1750 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1751 for (int i = 0; i < ival.length (); i++) |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1752 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1753 try |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1754 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1755 iv(i) = ival(i).index_vector (); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1756 } |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22324
diff
changeset
|
1757 catch (octave::index_exception& e) |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1758 { |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1759 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1760 e.set_pos_if_unset (ival.length (), i+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20488
diff
changeset
|
1761 throw; |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1762 } |
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1763 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1764 is_scalar = is_scalar && iv(i).is_scalar (); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1765 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1766 if (! is_scalar) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1767 error ("subsasgn: invalid indexing for object array assignment" |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1768 ", the index must reference a single object in the " |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1769 "array."); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1770 } |
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1771 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1772 Array<cdef_object> a = array.index (iv, true); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1773 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1774 if (a.numel () != 1) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1775 error ("subsasgn: invalid indexing for object array assignment"); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1776 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1777 cdef_object obj = a(0); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1778 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1779 int ignore_copies = 0; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1780 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1781 // If the object in 'a' is not valid, this means the index |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1782 // was out-of-bound and we need to create a new object. |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1783 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1784 if (! obj.ok ()) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1785 obj = get_class ().construct_object (octave_value_list ()); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1786 else |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
1787 // Optimize the subsasgn call to come. There are 2 copies |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1788 // that we can safely ignore: |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1789 // - 1 in "array" |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1790 // - 1 in "a" |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1791 ignore_copies = 2; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1792 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1793 std::list<octave_value_list> next_idx (idx); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1794 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1795 next_idx.erase (next_idx.begin ()); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1796 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1797 octave_value tmp = obj.subsasgn (type.substr (1), next_idx, |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1798 rhs, ignore_copies); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1799 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1800 cdef_object robj = to_cdef (tmp); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1801 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1802 if (! robj.ok () |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1803 || robj.is_array () |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1804 || robj.get_class () != get_class ()) |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1805 error ("subasgn: invalid assignment into array of %s objects", |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1806 class_name ().c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1807 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1808 // Small optimization, when dealing with handle |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1809 // objects, we don't need to re-assign the result |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1810 // of subsasgn back into the array. |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1811 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1812 if (! robj.is (a(0))) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1813 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1814 Array<cdef_object> rhs_a (dim_vector (1, 1), |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1815 robj); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1816 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1817 octave_idx_type n = array.numel (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1818 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1819 array.assign (iv, rhs_a); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1820 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1821 if (array.numel () > n) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1822 fill_empty_values (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1823 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1824 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1825 refcount++; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1826 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1827 retval = to_ov (cdef_object (this)); |
16695
2823f8e3da77
Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16694
diff
changeset
|
1828 } |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1829 break; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1830 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1831 default: |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
1832 error ("can't perform indexing operation on array of %s objects", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
1833 class_name ().c_str ()); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1834 break; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1835 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1836 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1837 return retval; |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1838 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1839 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1840 void |
16696
665fa0f621cc
Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16695
diff
changeset
|
1841 cdef_object_array::fill_empty_values (Array<cdef_object>& arr) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1842 { |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1843 cdef_class cls = get_class (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1844 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1845 cdef_object obj; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1846 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1847 int n = arr.numel (); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1848 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1849 for (int i = 0; i < n; i++) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1850 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1851 if (! arr.xelem (i).ok ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1852 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1853 if (! obj.ok ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1854 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1855 obj = cls.construct_object (octave_value_list ()); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1856 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1857 arr.xelem (i) = obj; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1858 } |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1859 else |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1860 arr.xelem (i) = obj.copy (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1861 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1862 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
1863 } |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
1864 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1865 bool |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1866 cdef_object_scalar::is_constructed_for (const cdef_class& cls) const |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1867 { |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1868 return (is_constructed () |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1869 || ctor_list.find (cls) == ctor_list.end ()); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1870 } |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1871 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1872 bool |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1873 cdef_object_scalar::is_partially_constructed_for (const cdef_class& cls) const |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1874 { |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23533
diff
changeset
|
1875 std::map< cdef_class, std::list<cdef_class>>::const_iterator it; |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1876 |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1877 if (is_constructed ()) |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1878 return true; |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1879 else if ((it = ctor_list.find (cls)) == ctor_list.end () |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1880 || it->second.empty ()) |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1881 return true; |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1882 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1883 for (const auto& cdef_cls : it->second) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1884 if (! is_constructed_for (cdef_cls)) |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1885 return false; |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1886 |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1887 return true; |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1888 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1889 |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20912
diff
changeset
|
1890 inline void |
20841
9851a296cf87
Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents:
20181
diff
changeset
|
1891 cdef_object_scalar::mark_as_constructed (const cdef_class& cls) |
9851a296cf87
Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents:
20181
diff
changeset
|
1892 { |
9851a296cf87
Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents:
20181
diff
changeset
|
1893 ctor_list.erase (cls); |
9851a296cf87
Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents:
20181
diff
changeset
|
1894 } |
9851a296cf87
Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents:
20181
diff
changeset
|
1895 |
15870
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1896 handle_cdef_object::~handle_cdef_object (void) |
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1897 { |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1898 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1899 std::cerr << "deleting " << get_class ().get_name () |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1900 << " object (handle)" << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1901 #endif |
15870
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1902 } |
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1903 |
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1904 value_cdef_object::~value_cdef_object (void) |
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1905 { |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1906 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1907 std::cerr << "deleting " << get_class ().get_name () |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1908 << " object (value)" << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
1909 #endif |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1910 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1911 |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
1912 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>& superclasses) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1913 : cdef_meta_object_rep (), member_count (0), handle_class (false), |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1914 object_count (0), meta (false) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1915 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1916 put ("SuperClasses", to_ov (superclasses)); |
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1917 implicit_ctor_list = superclasses; |
15870
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1918 } |
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
1919 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1920 cdef_method |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1921 cdef_class::cdef_class_rep::find_method (const std::string& nm, bool local) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1922 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
1923 auto it = method_map.find (nm); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1924 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1925 if (it == method_map.end ()) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1926 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1927 // FIXME: look into class directory |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1928 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1929 else |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1930 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1931 cdef_method& meth = it->second; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1932 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1933 // FIXME: check if method reload needed |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1934 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1935 if (meth.ok ()) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
1936 return meth; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1937 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1938 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1939 if (! local) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1940 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1941 // Look into superclasses |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1942 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1943 Cell super_classes = get ("SuperClasses").cell_value (); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1944 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1945 for (int i = 0; i < super_classes.numel (); i++) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1946 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1947 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1948 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1949 cdef_method meth = cls.find_method (nm); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1950 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1951 if (meth.ok ()) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1952 return meth; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
1953 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1954 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1955 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1956 return cdef_method (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1957 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1958 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1959 class ctor_analyzer : public octave::tree_walker |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1960 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1961 public: |
25321
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1962 ctor_analyzer (void) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1963 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
1964 ctor_analyzer (const std::string& ctor, const std::string& obj) |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1965 : octave::tree_walker (), who (ctor), obj_name (obj) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1966 |
25321
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1967 ctor_analyzer (const ctor_analyzer&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1968 |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1969 ctor_analyzer& operator = (const ctor_analyzer&) = delete; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1970 |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1971 ~ctor_analyzer (void) = default; |
089852fc8929
use explict default and deleted ctors and dtors for classdef classes
John W. Eaton <jwe@octave.org>
parents:
25320
diff
changeset
|
1972 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1973 void visit_statement_list (octave::tree_statement_list& t) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1974 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1975 for (const auto& stmt_p : t) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
1976 stmt_p->accept (*this); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1977 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1978 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1979 void visit_statement (octave::tree_statement& t) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1980 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1981 if (t.is_expression ()) |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1982 t.expression ()->accept (*this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1983 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1984 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1985 void visit_simple_assignment (octave::tree_simple_assignment& t) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1986 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1987 t.right_hand_side ()->accept (*this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1988 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1989 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1990 void visit_multi_assignment (octave::tree_multi_assignment& t) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1991 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1992 t.right_hand_side ()->accept (*this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1993 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1994 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
1995 void visit_index_expression (octave::tree_index_expression& t) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1996 { |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1997 t.expression ()->accept (*this); |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1998 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
1999 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2000 std::list<cdef_class> get_constructor_list (void) const |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2001 { return ctor_list; } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2002 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2003 // NO-OP |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2004 void visit_anon_fcn_handle (octave::tree_anon_fcn_handle&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2005 void visit_argument_list (octave::tree_argument_list&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2006 void visit_binary_expression (octave::tree_binary_expression&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2007 void visit_break_command (octave::tree_break_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2008 void visit_colon_expression (octave::tree_colon_expression&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2009 void visit_continue_command (octave::tree_continue_command&) { } |
23469
2699c5974844
handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
2010 void visit_decl_command (octave::tree_decl_command&) { } |
2699c5974844
handle global and persistent in tree_decl_command, not as separate classes
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
2011 void visit_decl_init_list (octave::tree_decl_init_list&) { } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2012 void visit_decl_elt (octave::tree_decl_elt&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2013 void visit_simple_for_command (octave::tree_simple_for_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2014 void visit_complex_for_command (octave::tree_complex_for_command&) { } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2015 void visit_octave_user_script (octave_user_script&) { } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2016 void visit_octave_user_function (octave_user_function&) { } |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2017 void visit_function_def (octave::tree_function_def&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2018 void visit_identifier (octave::tree_identifier&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2019 void visit_if_clause (octave::tree_if_clause&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2020 void visit_if_command (octave::tree_if_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2021 void visit_if_command_list (octave::tree_if_command_list&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2022 void visit_switch_case (octave::tree_switch_case&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2023 void visit_switch_case_list (octave::tree_switch_case_list&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2024 void visit_switch_command (octave::tree_switch_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2025 void visit_matrix (octave::tree_matrix&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2026 void visit_cell (octave::tree_cell&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2027 void visit_no_op_command (octave::tree_no_op_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2028 void visit_constant (octave::tree_constant&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2029 void visit_fcn_handle (octave::tree_fcn_handle&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2030 void visit_parameter_list (octave::tree_parameter_list&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2031 void visit_postfix_expression (octave::tree_postfix_expression&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2032 void visit_prefix_expression (octave::tree_prefix_expression&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2033 void visit_return_command (octave::tree_return_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2034 void visit_return_list (octave::tree_return_list&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2035 void visit_try_catch_command (octave::tree_try_catch_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2036 void visit_unwind_protect_command (octave::tree_unwind_protect_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2037 void visit_while_command (octave::tree_while_command&) { } |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2038 void visit_do_until_command (octave::tree_do_until_command&) { } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2039 |
26686
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2040 void visit_superclass_ref (octave::tree_superclass_ref& t) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2041 { |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2042 if (t.method_or_object_name () == obj_name) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2043 { |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2044 std::string class_name = t.class_name (); |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2045 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2046 cdef_class cls = lookup_class (class_name, false); |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2047 |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2048 if (cls.ok ()) |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2049 ctor_list.push_back (cls); |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2050 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2051 } |
581d01526b34
eliminate unnecessary tree_funcall class
John W. Eaton <jwe@octave.org>
parents:
26661
diff
changeset
|
2052 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2053 private: |
20946 | 2054 // The name of the constructor being analyzed. |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2055 std::string who; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2056 |
20946 | 2057 // The name of the first output argument of the constructor. |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2058 std::string obj_name; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2059 |
20946 | 2060 // The list of superclass constructors that are explicitly called. |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2061 std::list<cdef_class> ctor_list; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2062 }; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2063 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2064 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2065 cdef_class::cdef_class_rep::install_method (const cdef_method& meth) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2066 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2067 method_map[meth.get_name ()] = meth; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2068 |
15911
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
2069 member_count++; |
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
2070 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2071 if (meth.is_constructor ()) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2072 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2073 // Analyze the constructor code to determine what superclass |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2074 // constructors are called explicitly. |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2075 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2076 octave_function *of = meth.get_function ().function_value (true); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2077 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2078 if (of) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2079 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2080 octave_user_function *uf = of->user_function_value (true); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2081 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2082 if (uf) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2083 { |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2084 octave::tree_parameter_list *ret_list = uf->return_list (); |
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2085 octave::tree_statement_list *body = uf->body (); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2086 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2087 if (! ret_list || ret_list->size () != 1) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
2088 error ("%s: invalid constructor output arguments", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
2089 meth.get_name ().c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2090 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2091 std::string obj_name = ret_list->front ()->name (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2092 ctor_analyzer a (meth.get_name (), obj_name); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2093 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2094 body->accept (a); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2095 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2096 std::list<cdef_class> explicit_ctor_list |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2097 = a.get_constructor_list (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2098 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2099 for (const auto& cdef_cls : explicit_ctor_list) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2100 { |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2101 #if DEBUG_TRACE |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2102 std::cerr << "explicit superclass constructor: " |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2103 << cdef_cls.get_name () << std::endl; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2104 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2105 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2106 implicit_ctor_list.remove (cdef_cls); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2107 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2108 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2109 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2110 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2111 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2112 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2113 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2114 cdef_class::cdef_class_rep::load_all_methods (void) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2115 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2116 // FIXME: re-scan class directory |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2117 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2118 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2119 Cell |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2120 cdef_class::cdef_class_rep::get_methods (void) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2121 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2122 std::map<std::string,cdef_method> meths; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2123 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2124 find_methods (meths, false); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2125 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2126 Cell c (meths.size (), 1); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2127 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2128 int idx = 0; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2129 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2130 for (const auto& nm_mthd : meths) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2131 c(idx++, 0) = to_ov (nm_mthd.second); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2132 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2133 return c; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2134 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2135 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2136 void |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2137 cdef_class::cdef_class_rep::find_methods (std::map<std::string, |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2138 cdef_method>& meths, |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2139 bool only_inherited) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2140 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2141 load_all_methods (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2142 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2143 method_const_iterator it; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2144 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2145 for (it = method_map.begin (); it != method_map.end (); ++it) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2146 { |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2147 if (! it->second.is_constructor ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2148 { |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2149 std::string nm = it->second.get_name (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2150 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2151 if (meths.find (nm) == meths.end ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2152 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2153 if (only_inherited) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2154 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2155 octave_value acc = it->second.get ("Access"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2156 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2157 if (! acc.is_string () |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2158 || acc.string_value () == "private") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2159 continue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2160 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2161 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2162 meths[nm] = it->second; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2163 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2164 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2165 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2166 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2167 // Look into superclasses |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2168 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2169 Cell super_classes = get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2170 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2171 for (int i = 0; i < super_classes.numel (); i++) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2172 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2173 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2174 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2175 cls.get_rep ()->find_methods (meths, true); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2176 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2177 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2178 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2179 cdef_property |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2180 cdef_class::cdef_class_rep::find_property (const std::string& nm) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2181 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
2182 auto it = property_map.find (nm); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2183 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2184 if (it != property_map.end ()) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2185 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2186 cdef_property& prop = it->second; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2187 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2188 if (prop.ok ()) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
2189 return prop; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2190 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2191 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2192 // Look into superclasses |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2193 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2194 Cell super_classes = get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2195 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2196 for (int i = 0; i < super_classes.numel (); i++) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2197 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2198 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2199 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2200 cdef_property prop = cls.find_property (nm); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2201 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2202 if (prop.ok ()) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2203 return prop; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2204 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2205 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2206 return cdef_property (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2207 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2208 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2209 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2210 cdef_class::cdef_class_rep::install_property (const cdef_property& prop) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2211 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2212 property_map[prop.get_name ()] = prop; |
15911
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
2213 |
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
2214 member_count++; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2215 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2216 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2217 Cell |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2218 cdef_class::cdef_class_rep::get_properties (int mode) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2219 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2220 std::map<std::string,cdef_property> props; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2221 |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2222 props = get_property_map (mode); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2223 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2224 Cell c (props.size (), 1); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2225 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2226 int idx = 0; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2227 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2228 for (const auto& pname_prop : props) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2229 c(idx++, 0) = to_ov (pname_prop.second); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2230 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2231 return c; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2232 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2233 |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2234 std::map<std::string, cdef_property> |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2235 cdef_class::cdef_class_rep::get_property_map (int mode) |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2236 { |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2237 std::map<std::string,cdef_property> props; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2238 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2239 find_properties (props, mode); |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2240 |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2241 return props; |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2242 } |
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2243 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2244 void |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2245 cdef_class::cdef_class_rep::find_properties (std::map<std::string, |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2246 cdef_property>& props, |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2247 int mode) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2248 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2249 property_const_iterator it; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2250 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2251 for (it = property_map.begin (); it != property_map.end (); ++it) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2252 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2253 std::string nm = it->second.get_name (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2254 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2255 if (props.find (nm) == props.end ()) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
2256 { |
19184
e0a7718ac085
Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
19103
diff
changeset
|
2257 if (mode == property_inherited) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2258 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2259 octave_value acc = it->second.get ("GetAccess"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2260 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2261 if (! acc.is_string () |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2262 || acc.string_value () == "private") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2263 continue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2264 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2265 |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
2266 props[nm] = it->second; |
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
2267 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2268 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2269 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2270 // Look into superclasses |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2271 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2272 Cell super_classes = get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2273 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2274 for (int i = 0; i < super_classes.numel (); i++) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2275 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2276 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2277 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2278 cls.get_rep ()->find_properties (props, |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2279 (mode == property_all |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2280 ? property_all |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2281 : property_inherited)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2282 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2283 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2284 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2285 void |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2286 cdef_class::cdef_class_rep::find_names (std::set<std::string>& names, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2287 bool all) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2288 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2289 load_all_methods (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2290 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2291 for (const auto& cls_fnmap : method_map) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2292 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2293 if (! cls_fnmap.second.is_constructor ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2294 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2295 std::string nm = cls_fnmap.second.get_name (); |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2296 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2297 if (! all) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2298 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2299 octave_value acc = cls_fnmap.second.get ("Access"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2300 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2301 if (! acc.is_string() |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2302 || acc.string_value () != "public") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2303 continue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2304 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2305 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2306 names.insert (nm); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2307 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2308 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2309 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2310 for (const auto& pname_prop : property_map) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2311 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2312 std::string nm = pname_prop.second.get_name (); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2313 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2314 if (! all) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2315 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2316 octave_value acc = pname_prop.second.get ("GetAccess"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2317 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2318 if (! acc.is_string() |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2319 || acc.string_value () != "public") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2320 continue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2321 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2322 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2323 names.insert (nm); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2324 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2325 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2326 // Look into superclasses |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2327 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2328 Cell super_classes = get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2329 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2330 for (int i = 0; i < super_classes.numel (); i++) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2331 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2332 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2333 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2334 cls.get_rep ()->find_names (names, all); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2335 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2336 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2337 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2338 string_vector |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2339 cdef_class::cdef_class_rep::get_names (void) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2340 { |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2341 std::set<std::string> names; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2342 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2343 find_names (names, false); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2344 |
22374
f38e81248556
ov-classdef.cc: use string_vector constructor for string containers.
Carnë Draug <carandraug@octave.org>
parents:
22327
diff
changeset
|
2345 string_vector v (names); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2346 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2347 return v.sort (true); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2348 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2349 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2350 void |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2351 cdef_class::cdef_class_rep::delete_object (const cdef_object& obj) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2352 { |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2353 cdef_method dtor = find_method ("delete"); |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2354 |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2355 if (dtor.ok ()) |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2356 dtor.execute (obj, octave_value_list (), 0, true, "destructor"); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2357 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2358 // FIXME: should we destroy corresponding properties here? |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2359 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2360 // Call "delete" in super classes |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2361 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2362 Cell super_classes = get ("SuperClasses").cell_value (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2363 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2364 for (int i = 0; i < super_classes.numel (); i++) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2365 { |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2366 cdef_class cls = lookup_class (super_classes(i)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2367 |
25367
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2368 if (cls.get_name () != "handle") |
0548e32e6b27
call delete method correctly for handle class objects (bug #53844)
John W. Eaton <jwe@octave.org>
parents:
25319
diff
changeset
|
2369 cls.delete_object (obj); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2370 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2371 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2372 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2373 octave_value_list |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2374 cdef_class::cdef_class_rep::meta_subsref (const std::string& type, |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2375 const std::list<octave_value_list>& idx, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2376 int nargout) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2377 { |
15956
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2378 size_t skip = 1; |
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2379 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2380 octave_value_list retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2381 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2382 switch (type[0]) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2383 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2384 case '(': |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2385 // Constructor call |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2386 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2387 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2388 std::cerr << "constructor" << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2389 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2390 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2391 retval(0) = construct (idx.front ()); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2392 break; |
15956
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2393 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2394 case '.': |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2395 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2396 // Static method, constant (or property?) |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2397 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2398 #if DEBUG_TRACE |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2399 std::cerr << "static method/property" << std::endl; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2400 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2401 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2402 if (idx.front ().length () != 1) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2403 error ("invalid meta.class indexing"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2404 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2405 std::string nm = idx.front ()(0).xstring_value ("invalid meta.class indexing, expected a method or property name"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2406 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2407 cdef_method meth = find_method (nm); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2408 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2409 if (meth.ok ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2410 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2411 if (! meth.is_static ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2412 error ("method `%s' is not static", nm.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2413 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2414 octave_value_list args; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2415 |
26449
f8107140087c
maint: small indentation changes for readability.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2416 if (type.length () > 1 && idx.size () > 1 && type[1] == '(') |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2417 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2418 args = *(++(idx.begin ())); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2419 skip++; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2420 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2421 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2422 retval = meth.execute (args, (type.length () > skip |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2423 ? 1 : nargout), true, |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2424 "meta.class"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2425 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2426 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2427 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2428 cdef_property prop = find_property (nm); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2429 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2430 if (! prop.ok ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2431 error ("no such method or property `%s'", nm.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2432 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2433 if (! prop.is_constant ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2434 error ("property `%s' is not constant", nm.c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2435 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2436 retval(0) = prop.get_value (true, "meta.class"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2437 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2438 } |
15956
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2439 break; |
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2440 |
d8553705f8f0
Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15955
diff
changeset
|
2441 default: |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
2442 error ("invalid meta.class indexing"); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2443 break; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2444 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2445 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2446 if (type.length () > skip && idx.size () > skip && ! retval.empty ()) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2447 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
|
2448 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2449 return retval; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2450 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2451 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2452 void |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2453 cdef_class::cdef_class_rep::meta_release (void) |
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2454 { |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2455 cdef_manager& cdm |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2456 = octave::__get_cdef_manager__ ("cdef_class::cdef_class_rep::meta_release"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2457 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2458 cdm.unregister_class (wrap ()); |
15986
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2459 } |
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2460 |
14aa0b5a980c
Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15968
diff
changeset
|
2461 void |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2462 cdef_class::cdef_class_rep::initialize_object (cdef_object& obj) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2463 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2464 // Populate the object with default property values |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2465 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2466 std::list<cdef_class> super_classes = lookup_classes ( |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2467 get ("SuperClasses").cell_value ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2468 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2469 for (auto& cls : super_classes) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2470 cls.initialize_object (obj); |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2471 |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2472 for (const auto& pname_prop : property_map) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2473 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2474 if (! pname_prop.second.get ("Dependent").bool_value ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2475 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2476 octave_value pvalue = pname_prop.second.get ("DefaultValue"); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2477 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2478 if (pvalue.is_defined ()) |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2479 obj.put (pname_prop.first, pvalue); |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2480 else |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2481 obj.put (pname_prop.first, octave_value (Matrix ())); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2482 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2483 } |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2484 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2485 refcount++; |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2486 obj.mark_for_construction (cdef_class (this)); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2487 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2488 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2489 void |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2490 cdef_class::cdef_class_rep::run_constructor (cdef_object& obj, |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2491 const octave_value_list& args) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2492 { |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2493 octave_value_list empty_args; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2494 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2495 for (const auto& cls : implicit_ctor_list) |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2496 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2497 cdef_class supcls = lookup_class (cls); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2498 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2499 supcls.run_constructor (obj, empty_args); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2500 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2501 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2502 std::string cls_name = get_name (); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2503 std::string ctor_name = get_base_name (cls_name); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2504 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2505 cdef_method ctor = find_method (ctor_name); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2506 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2507 if (ctor.ok ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2508 { |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2509 octave_value_list ctor_args (args); |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2510 octave_value_list ctor_retval; |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2511 |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2512 ctor_args.prepend (to_ov (obj)); |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2513 ctor_retval = ctor.execute (ctor_args, 1, true, "constructor"); |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2514 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2515 if (ctor_retval.length () != 1) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2516 error ("%s: invalid number of output arguments for classdef constructor", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2517 ctor_name.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2518 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2519 obj = to_cdef (ctor_retval(0)); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2520 } |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2521 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2522 obj.mark_as_constructed (wrap ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2523 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2524 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2525 octave_value |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2526 cdef_class::cdef_class_rep::construct (const octave_value_list& args) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2527 { |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2528 cdef_object obj = construct_object (args); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2529 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2530 if (obj.ok ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2531 return to_ov (obj); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2532 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2533 return octave_value (); |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2534 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2535 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2536 cdef_object |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2537 cdef_class::cdef_class_rep::construct_object (const octave_value_list& args) |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2538 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2539 if (is_abstract ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2540 error ("cannot instantiate object for abstract class `%s'", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2541 get_name ().c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2542 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2543 cdef_object obj; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2544 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2545 if (is_meta_class ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2546 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2547 // This code path is only used to create empty meta objects |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2548 // as filler for the empty values within a meta object array. |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2549 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2550 cdef_class this_cls = wrap (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2551 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2552 static cdef_object empty_class; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2553 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2554 cdef_manager& cdm |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2555 = octave::__get_cdef_manager__ ("cdef_class::cdef_class_rep::construct_object"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2556 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2557 if (this_cls == cdm.meta_class ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2558 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2559 if (! empty_class.ok ()) |
24539 | 2560 empty_class = cdm.make_class ("", std::list<cdef_class> ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2561 obj = empty_class; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2562 } |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2563 else if (this_cls == cdm.meta_property ()) |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2564 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2565 static cdef_property empty_property; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2566 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2567 if (! empty_class.ok ()) |
24539 | 2568 empty_class = cdm.make_class ("", std::list<cdef_class> ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2569 if (! empty_property.ok ()) |
24539 | 2570 empty_property = cdm.make_property (empty_class, ""); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2571 obj = empty_property; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2572 } |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2573 else if (this_cls == cdm.meta_method ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2574 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2575 static cdef_method empty_method; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2576 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2577 if (! empty_class.ok ()) |
24539 | 2578 empty_class = cdm.make_class ("", std::list<cdef_class> ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2579 if (! empty_method.ok ()) |
24539 | 2580 empty_method = cdm.make_method (empty_class, "", octave_value ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2581 obj = empty_method; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2582 } |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2583 else if (this_cls == cdm.meta_package ()) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2584 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2585 static cdef_package empty_package; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2586 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2587 if (! empty_package.ok ()) |
24539 | 2588 empty_package = cdm.make_package (""); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2589 obj = empty_package; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2590 } |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2591 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2592 panic_impossible (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2593 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2594 return obj; |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2595 } |
15870
2b6fe094e615
Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15869
diff
changeset
|
2596 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2597 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2598 if (is_handle_class ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2599 obj = cdef_object (new handle_cdef_object ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2600 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2601 obj = cdef_object (new value_cdef_object ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2602 obj.set_class (wrap ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2603 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2604 initialize_object (obj); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2605 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2606 run_constructor (obj, args); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2607 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2608 return obj; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2609 } |
15913
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2610 |
8521321604df
Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15911
diff
changeset
|
2611 return cdef_object (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2612 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2613 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2614 static octave_value |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2615 compute_attribute_value (octave::tree_evaluator& tw, |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
2616 octave::tree_classdef_attribute *t) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2617 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2618 octave::tree_expression *expr = t->expression (); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2619 |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2620 if (expr) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2621 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2622 if (expr->is_identifier ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2623 { |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2624 std::string s = expr->name (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2625 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2626 if (s == "public") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2627 return std::string ("public"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2628 else if (s == "protected") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2629 return std::string ("protected"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2630 else if (s == "private") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2631 return std::string ("private"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2632 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2633 |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2634 return tw.evaluate (expr); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2635 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2636 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2637 return octave_value (true); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2638 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2639 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
2640 template <typename T> |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2641 static std::string |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
2642 attribute_value_to_string (T *t, octave_value v) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2643 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2644 if (v.is_string ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2645 return v.string_value (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2646 else if (t->expression ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2647 return t->expression ()->original_text (); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2648 else |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23826
diff
changeset
|
2649 return "true"; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2650 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2651 |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2652 cdef_class |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2653 cdef_class::make_meta_class (octave::interpreter& interp, |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
2654 octave::tree_classdef *t, bool is_at_folder) |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2655 { |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2656 cdef_class retval; |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2657 std::string class_name, full_class_name; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2658 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2659 // Class creation |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2660 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2661 class_name = full_class_name = t->ident ()->name (); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2662 if (! t->package_name ().empty ()) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
2663 full_class_name = t->package_name () + '.' + full_class_name; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2664 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2665 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2666 std::cerr << "class: " << full_class_name << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2667 #endif |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2668 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2669 std::list<cdef_class> slist; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2670 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2671 if (t->superclass_list ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2672 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2673 for (auto& scls : (*t->superclass_list ())) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2674 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2675 std::string sclass_name = (scls)->class_name (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2676 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2677 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2678 std::cerr << "superclass: " << sclass_name << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2679 #endif |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2680 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2681 cdef_class sclass = lookup_class (sclass_name); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2682 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2683 if (sclass.get ("Sealed").bool_value ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2684 error ("`%s' cannot inherit from `%s', because it is sealed", |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2685 full_class_name.c_str (), sclass_name.c_str ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2686 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2687 slist.push_back (sclass); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2688 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2689 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2690 |
24539 | 2691 cdef_manager& cdm |
2692 = octave::__get_cdef_manager__ ("cdef_class::make_meta_class"); | |
2693 | |
2694 retval = cdm.make_class (full_class_name, slist); | |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2695 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2696 // Package owning this class |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2697 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2698 if (! t->package_name ().empty ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2699 { |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
2700 cdef_package pack = cdm.find_package (t->package_name ()); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2701 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2702 if (pack.ok ()) |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2703 retval.put ("ContainingPackage", to_ov (pack)); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2704 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
2705 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2706 // Class attributes |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2707 |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2708 octave::tree_evaluator& tw = interp.get_evaluator (); |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2709 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2710 if (t->attribute_list ()) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2711 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2712 for (const auto& attr : (*t->attribute_list ())) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2713 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2714 std::string aname = attr->ident ()->name (); |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2715 octave_value avalue = compute_attribute_value (tw, attr); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2716 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2717 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2718 std::cerr << "class attribute: " << aname << " = " |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2719 << attribute_value_to_string (attr, avalue) << std::endl; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2720 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2721 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2722 retval.put (aname, avalue); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2723 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2724 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2725 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
2726 octave::tree_classdef_body *b = t->body (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2727 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2728 if (b) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2729 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
2730 // Keep track of the get/set accessor methods. They will be used |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2731 // later on when creating properties. |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2732 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2733 std::map<std::string, octave_value> get_methods; |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2734 std::map<std::string, octave_value> set_methods; |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2735 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2736 // Method blocks |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2737 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2738 std::list<octave::tree_classdef_methods_block *> mb_list = b->methods_list (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2739 |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2740 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
2741 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2742 for (auto& mb_p : mb_list) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2743 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2744 std::map<std::string, octave_value> amap; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2745 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2746 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2747 std::cerr << "method block" << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2748 #endif |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2749 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2750 // Method attributes |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2751 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2752 if (mb_p->attribute_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2753 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2754 for (auto& attr_p : *mb_p->attribute_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2755 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2756 std::string aname = attr_p->ident ()->name (); |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2757 octave_value avalue = compute_attribute_value (tw, attr_p); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2758 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2759 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2760 std::cerr << "method attribute: " << aname << " = " |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2761 << attribute_value_to_string (attr_p, avalue) |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2762 << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2763 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2764 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2765 amap[aname] = avalue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2766 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2767 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2768 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2769 // Methods |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2770 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2771 if (mb_p->element_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2772 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2773 for (auto& mtd : *mb_p->element_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2774 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2775 std::string mname = mtd.function_value ()->name (); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2776 std::string mprefix = mname.substr (0, 4); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2777 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2778 if (mprefix == "get.") |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2779 get_methods[mname.substr (4)] = |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
2780 make_fcn_handle (mtd, full_class_name + '>' + mname); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2781 else if (mprefix == "set.") |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2782 set_methods[mname.substr (4)] = |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
2783 make_fcn_handle (mtd, full_class_name + '>' + mname); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2784 else |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2785 { |
24539 | 2786 cdef_method meth = cdm.make_method (retval, mname, mtd); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2787 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2788 #if DEBUG_TRACE |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2789 std::cerr << (mname == class_name ? "constructor" |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2790 : "method") |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2791 << ": " << mname << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2792 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2793 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2794 for (auto& attrnm_val : amap) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2795 meth.put (attrnm_val.first, attrnm_val.second); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2796 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2797 retval.install_method (meth); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2798 } |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2799 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2800 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2801 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2802 |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2803 if (is_at_folder) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2804 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2805 // Look for all external methods visible on octave path at the |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2806 // time of loading of the class. |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2807 // |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2808 // FIXME: This is an "extension" to Matlab behavior, which only looks |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2809 // in the @-folder containing the original classdef file. However, |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2810 // this is easier to implement it that way at the moment. |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2811 |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
2812 std::list<std::string> external_methods |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
2813 = lp.methods (full_class_name); |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2814 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2815 for (const auto& mtdnm : external_methods) |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2816 { |
21578
683a1beee538
maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents:
21574
diff
changeset
|
2817 // FIXME: should we issue a warning if the method is already |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2818 // defined in the classdef file? |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2819 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2820 if (mtdnm != class_name |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2821 && ! retval.find_method (mtdnm, true).ok ()) |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2822 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2823 // Create a dummy method that is used until the actual |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2824 // method is loaded. |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2825 octave_user_function *fcn = new octave_user_function (); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2826 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2827 fcn->stash_function_name (mtdnm); |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2828 |
24539 | 2829 cdef_method meth |
2830 = cdm.make_method (retval, mtdnm, octave_value (fcn)); | |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2831 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2832 retval.install_method (meth); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2833 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2834 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2835 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
2836 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2837 // Property blocks |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2838 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2839 // FIXME: default property expression should be able to call static |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
2840 // methods of the class being constructed. A restricted CLASSNAME |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2841 // symbol should be added to the scope before evaluating default |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2842 // value expressions. |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2843 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23052
diff
changeset
|
2844 std::list<octave::tree_classdef_properties_block *> pb_list |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2845 = b->properties_list (); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2846 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2847 for (auto& pb_p : pb_list) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2848 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2849 std::map<std::string, octave_value> amap; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2850 |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2851 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2852 std::cerr << "property block" << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2853 #endif |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2854 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2855 // Property attributes |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2856 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2857 if (pb_p->attribute_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2858 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2859 for (auto& attr_p : *pb_p->attribute_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2860 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2861 std::string aname = attr_p->ident ()->name (); |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2862 octave_value avalue = compute_attribute_value (tw, attr_p); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2863 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2864 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2865 std::cerr << "property attribute: " << aname << " = " |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2866 << attribute_value_to_string (attr_p, avalue) |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2867 << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2868 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2869 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2870 if (aname == "Access") |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2871 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2872 amap["GetAccess"] = avalue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2873 amap["SetAccess"] = avalue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2874 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2875 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2876 amap[aname] = avalue; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2877 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2878 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2879 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2880 // Properties |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2881 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2882 if (pb_p->element_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2883 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2884 for (auto& prop_p : *pb_p->element_list ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2885 { |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2886 std::string prop_name = prop_p->ident ()->name (); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2887 |
24539 | 2888 cdef_property prop = cdm.make_property (retval, prop_name); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2889 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2890 #if DEBUG_TRACE |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2891 std::cerr << "property: " << prop_p->ident ()->name () |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2892 << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2893 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2894 |
23435
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2895 octave::tree_expression *expr = prop_p->expression (); |
c452180ab672
begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents:
23345
diff
changeset
|
2896 if (expr) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2897 { |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
2898 octave_value pvalue = tw.evaluate (expr); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2899 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2900 #if DEBUG_TRACE |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2901 std::cerr << "property default: " |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2902 << attribute_value_to_string (*pit, pvalue) |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2903 << std::endl; |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2904 #endif |
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
2905 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2906 prop.put ("DefaultValue", pvalue); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2907 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2908 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2909 // Install property attributes. This is done before assigning |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2910 // the property accessors so we can do validation by using |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2911 // cdef_property methods. |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2912 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2913 for (auto& attrnm_val : amap) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
2914 prop.put (attrnm_val.first, attrnm_val.second); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2915 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
2916 // Install property access methods, if any. Remove the |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20125
diff
changeset
|
2917 // accessor methods from the temporary storage map, so we can |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2918 // detect which ones are invalid and do not correspond to a |
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2919 // defined property. |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2920 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
2921 auto git = get_methods.find (prop_name); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2922 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2923 if (git != get_methods.end ()) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2924 { |
18462
00ba456b9aa8
Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18441
diff
changeset
|
2925 make_function_of_class (retval, git->second); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2926 prop.put ("GetMethod", git->second); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2927 get_methods.erase (git); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2928 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2929 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
2930 auto sit = set_methods.find (prop_name); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2931 |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2932 if (sit != set_methods.end ()) |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2933 { |
18462
00ba456b9aa8
Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18441
diff
changeset
|
2934 make_function_of_class (retval, sit->second); |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2935 prop.put ("SetMethod", sit->second); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2936 set_methods.erase (sit); |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2937 } |
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
2938 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2939 retval.install_property (prop); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2940 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2941 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2942 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2943 } |
15037
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2944 |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2945 return retval; |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2946 } |
56b8eb7c9c04
improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents:
15036
diff
changeset
|
2947 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2948 octave_function* |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2949 cdef_class::get_method_function (const std::string& /* nm */) |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2950 { |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
2951 octave_classdef_meta *p = new octave_classdef_meta (*this); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2952 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2953 return p; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2954 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
2955 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2956 octave_value |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2957 cdef_property::cdef_property_rep::get_value (const cdef_object& obj, |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2958 bool do_check_access, |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2959 const std::string& who) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2960 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2961 octave_value retval; |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2962 |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2963 if (do_check_access && ! check_get_access ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
2964 err_property_access (who, wrap (), false); |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2965 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2966 if (! obj.is_constructed ()) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2967 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2968 cdef_class cls (to_cdef (get ("DefiningClass"))); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2969 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
2970 if (! obj.is_partially_constructed_for (cls)) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2971 error ("cannot reference properties of class `%s' for non-constructed object", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
2972 cls.get_name ().c_str ()); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2973 } |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
2974 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2975 octave_value get_fcn = get ("GetMethod"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2976 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2977 // FIXME: should check whether we're already in get accessor method |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
2978 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
2979 if (get_fcn.isempty () || is_method_executing (get_fcn, obj)) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2980 retval = obj.get (get ("Name").string_value ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2981 else |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2982 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2983 octave_value_list args; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2984 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2985 args(0) = to_ov (obj); |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
2986 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
2987 args = octave::feval (get_fcn, args, 1); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2988 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
2989 retval = args(0); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2990 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2991 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2992 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2993 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2994 |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2995 octave_value |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2996 cdef_property::cdef_property_rep::get_value (bool do_check_access, |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2997 const std::string& who) |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2998 { |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
2999 if (do_check_access && ! check_get_access ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
3000 err_property_access (who, wrap (), false); |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3001 |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3002 return get ("DefaultValue"); |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3003 } |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3004 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3005 bool |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3006 cdef_property::cdef_property_rep::is_recursive_set (const cdef_object& /* obj */) const |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3007 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3008 // FIXME: implement |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3009 return false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3010 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3011 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3012 void |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3013 cdef_property::cdef_property_rep::set_value (cdef_object& obj, |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3014 const octave_value& val, |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3015 bool do_check_access, |
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3016 const std::string& who) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3017 { |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3018 if (do_check_access && ! check_set_access ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
3019 err_property_access (who, wrap (), true); |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3020 |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3021 if (! obj.is_constructed ()) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3022 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3023 cdef_class cls (to_cdef (get ("DefiningClass"))); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3024 |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
3025 if (! obj.is_partially_constructed_for (cls)) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3026 error ("cannot reference properties of class `%s' for non-constructed object", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3027 cls.get_name ().c_str ()); |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3028 } |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19343
diff
changeset
|
3029 |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3030 octave_value set_fcn = get ("SetMethod"); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3031 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
3032 if (set_fcn.isempty () || is_method_executing (set_fcn, obj)) |
16698
13b3b92ea99c
Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16696
diff
changeset
|
3033 obj.put (get ("Name").string_value (), val); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3034 else |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3035 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3036 octave_value_list args; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3037 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3038 args(0) = to_ov (obj); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3039 args(1) = val; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3040 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
3041 args = octave::feval (set_fcn, args, 1); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3042 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3043 if (args.length () > 0 && args(0).is_defined ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3044 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3045 if (args (0).is_classdef_object ()) |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3046 { |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3047 cdef_object new_obj = to_cdef (args(0)); |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3048 |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3049 obj = new_obj; |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3050 } |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3051 else |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3052 ::warning ("set-method of property `%s' returned a non-classdef object", |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3053 get_name ().c_str ()); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3054 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3055 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3056 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3057 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3058 bool |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3059 cdef_property::cdef_property_rep::check_get_access (void) const |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3060 { |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3061 cdef_class cls (to_cdef (get ("DefiningClass"))); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3062 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
3063 return ::check_access (cls, get ("GetAccess"), "", |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3064 get_name (), false); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3065 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3066 return false; |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3067 } |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3068 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3069 bool |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3070 cdef_property::cdef_property_rep::check_set_access (void) const |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3071 { |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3072 cdef_class cls (to_cdef (get ("DefiningClass"))); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3073 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
3074 return ::check_access (cls, get ("SetAccess"), "", |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3075 get_name (), true); |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3076 |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3077 return false; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3078 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3079 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3080 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3081 cdef_method::cdef_method_rep::check_method (void) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3082 { |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3083 if (is_external ()) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3084 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3085 if (is_dummy_method (function)) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3086 { |
23445
8e310ef0fa97
move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23438
diff
changeset
|
3087 octave::load_path& lp |
8e310ef0fa97
move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23438
diff
changeset
|
3088 = octave::__get_load_path__ ("cdef_method::cdef_method_rep::check_method"); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3089 |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3090 std::string name = get_name (); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3091 std::string cls_name = dispatch_type; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3092 std::string pack_name; |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3093 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3094 size_t pos = cls_name.rfind ('.'); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3095 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3096 if (pos != std::string::npos) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3097 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3098 pack_name = cls_name.substr (0, pos); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3099 cls_name = cls_name.substr (pos + 1); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3100 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3101 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3102 std::string dir_name; |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3103 std::string file_name = lp.find_method (cls_name, name, |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3104 dir_name, pack_name); |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3105 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3106 if (! file_name.empty ()) |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3107 { |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3108 octave_value ov_fcn |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3109 = octave::load_fcn_from_file (file_name, dir_name, |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3110 dispatch_type, pack_name); |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3111 |
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3112 if (ov_fcn.is_defined ()) |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3113 { |
23653
3bb0a937c071
avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents:
23652
diff
changeset
|
3114 function = ov_fcn; |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3115 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3116 make_function_of_class (dispatch_type, function); |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3117 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3118 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3119 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3120 else |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3121 { |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3122 // FIXME: check out-of-date status |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3123 } |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3124 |
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3125 if (is_dummy_method (function)) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
3126 error ("no definition found for method `%s' of class `%s'", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
20193
diff
changeset
|
3127 get_name ().c_str (), dispatch_type.c_str ()); |
18263
b5be1a2aa5ab
Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18262
diff
changeset
|
3128 } |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3129 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3130 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3131 octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3132 cdef_method::cdef_method_rep::execute (const octave_value_list& args, |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3133 int nargout, bool do_check_access, |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3134 const std::string& who) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3135 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3136 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3137 |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3138 if (do_check_access && ! check_access ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
3139 err_method_access (who, wrap ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3140 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3141 if (get ("Abstract").bool_value ()) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3142 error ("%s: cannot execute abstract method", |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3143 get ("Name").string_value ().c_str ()); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3144 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3145 check_method (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3146 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3147 if (function.is_defined ()) |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
3148 retval = octave::feval (function, args, nargout); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3149 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3150 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3151 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3152 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3153 octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3154 cdef_method::cdef_method_rep::execute (const cdef_object& obj, |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3155 const octave_value_list& args, |
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3156 int nargout, bool do_check_access, |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3157 const std::string& who) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3158 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3159 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3160 |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3161 if (do_check_access && ! check_access ()) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
3162 err_method_access (who, wrap ()); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3163 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3164 if (get ("Abstract").bool_value ()) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3165 error ("%s: cannot execute abstract method", |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3166 get ("Name").string_value ().c_str ()); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3167 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3168 check_method (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3169 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3170 if (function.is_defined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3171 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3172 octave_value_list new_args; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3173 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3174 new_args.resize (args.length () + 1); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3175 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3176 new_args(0) = to_ov (obj); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3177 for (int i = 0; i < args.length (); i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3178 new_args(i+1) = args(i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3179 |
23532
084245f9bd03
pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents:
23503
diff
changeset
|
3180 retval = octave::feval (function, new_args, nargout); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3181 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3182 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3183 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3184 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3185 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3186 bool |
15896
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3187 cdef_method::cdef_method_rep::is_constructor (void) const |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3188 { |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3189 if (function.is_function()) |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3190 return function.function_value ()->is_classdef_constructor (); |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3191 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3192 return false; |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3193 } |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3194 |
57be060d7672
Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15870
diff
changeset
|
3195 bool |
15968
cdeb6eb656be
Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15958
diff
changeset
|
3196 cdef_method::cdef_method_rep::check_access (void) const |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3197 { |
15869
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3198 cdef_class cls (to_cdef (get ("DefiningClass"))); |
5e5705b3e505
Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15841
diff
changeset
|
3199 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3200 return ::check_access (cls, get ("Access"), get_name ()); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3201 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3202 |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3203 octave_value_list |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3204 cdef_method::cdef_method_rep::meta_subsref |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3205 (const std::string& type, const std::list<octave_value_list>& idx, |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3206 int nargout) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3207 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3208 octave_value_list retval; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3209 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3210 switch (type[0]) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3211 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3212 case '(': |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
3213 retval = (execute (idx.front (), type.length () > 1 ? 1 : nargout, true)); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3214 break; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3215 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3216 default: |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3217 error ("invalid meta.method indexing"); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3218 break; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3219 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3220 |
20563
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3221 if (type.length () > 1 && idx.size () > 1 && ! retval.empty ()) |
c1a6c31ac29a
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3222 retval = retval(0).next_subsref (nargout, type, idx, 1); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3223 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3224 return retval; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3225 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3226 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3227 static cdef_package |
24100
4d9ceaf17dda
return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents:
23865
diff
changeset
|
3228 lookup_package (const std::string& name, bool error_if_not_found = true, |
4d9ceaf17dda
return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents:
23865
diff
changeset
|
3229 bool load_if_not_found = true) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3230 { |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3231 cdef_manager& cdm = octave::__get_cdef_manager__ ("lookup_package"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3232 |
24100
4d9ceaf17dda
return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents:
23865
diff
changeset
|
3233 return cdm.find_package (name, error_if_not_found, load_if_not_found); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3234 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3235 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3236 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3237 package_fromName (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3238 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3239 octave_value_list retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3240 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3241 if (args.length () != 1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3242 error ("fromName: invalid number of parameters"); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3243 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3244 std::string name = args(0).xstring_value ("fromName: PACKAGE_NAME must be a string"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3245 |
24100
4d9ceaf17dda
return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents:
23865
diff
changeset
|
3246 retval(0) = to_ov (lookup_package (name, false)); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3247 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3248 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3249 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3250 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3251 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3252 package_get_classes (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3253 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3254 octave_value_list retval (1, Matrix ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3255 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3256 if (args.length () == 1 && args(0).type_name () == "object" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3257 && args(0).class_name () == "meta.package") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3258 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3259 cdef_package pack (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3260 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3261 retval(0) = pack.get_classes (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3262 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3263 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3264 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3265 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3266 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3267 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3268 package_get_functions (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3269 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3270 octave_value_list retval (1, Matrix ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3271 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3272 if (args.length () == 0 && args(0).type_name () == "object" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3273 && args(0).class_name () == "meta.package") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3274 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3275 cdef_package pack (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3276 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3277 retval(0) = pack.get_functions (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3278 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3279 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3280 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3281 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3282 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3283 static octave_value_list |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3284 package_get_packages (const octave_value_list& args, int /* nargout */) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3285 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3286 octave_value_list retval (1, Matrix ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3287 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3288 if (args.length () == 0 && args(0).type_name () == "object" |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3289 && args(0).class_name () == "meta.package") |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3290 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3291 cdef_package pack (to_cdef (args(0))); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3292 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3293 retval(0) = pack.get_packages (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3294 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3295 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3296 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3297 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3298 |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3299 static octave_value_list |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
3300 package_getAllPackages (octave::interpreter& interp, |
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
3301 const octave_value_list& /* args */, int /* nargout */) |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3302 { |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3303 std::map<std::string, cdef_package> toplevel_packages; |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3304 |
23533
8edbc923a7dc
begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents:
23532
diff
changeset
|
3305 octave::load_path& lp = interp.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3306 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3307 std::list<std::string> names = lp.get_all_package_names (); |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3308 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3309 cdef_manager& cdm = octave::__get_cdef_manager__ ("package_getAllPackages"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3310 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3311 toplevel_packages["meta"] = cdm.find_package ("meta", false, false); |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3312 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3313 for (const auto& nm : names) |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3314 toplevel_packages[nm] = cdm.find_package (nm, false, true); |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3315 |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3316 Cell c (toplevel_packages.size (), 1); |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3317 |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3318 int i = 0; |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3319 |
22871
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3320 for (const auto& nm_pkg : toplevel_packages) |
50495eeb5df1
maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3321 c(i++,0) = to_ov (nm_pkg.second); |
16690
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3322 |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3323 return octave_value_list (octave_value (c)); |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3324 } |
1c45e22fc444
Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16689
diff
changeset
|
3325 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3326 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3327 cdef_package::cdef_package_rep::install_class (const cdef_class& cls, |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3328 const std::string& nm) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3329 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3330 class_map[nm] = cls; |
15911
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
3331 |
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
3332 member_count++; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3333 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3334 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3335 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3336 cdef_package::cdef_package_rep::install_function (const octave_value& fcn, |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3337 const std::string& nm) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3338 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3339 function_map[nm] = fcn; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3340 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3341 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3342 void |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3343 cdef_package::cdef_package_rep::install_package (const cdef_package& pack, |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3344 const std::string& nm) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3345 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3346 package_map[nm] = pack; |
15911
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
3347 |
b18b7e560236
More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15910
diff
changeset
|
3348 member_count++; |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3349 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3350 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
3351 template <typename T1, typename T2> |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3352 Cell |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3353 map2Cell (const std::map<T1, T2>& m) |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3354 { |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3355 Cell retval (1, m.size ()); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3356 int i = 0; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3357 |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
3358 for (auto it = m.begin (); it != m.end (); ++it, ++i) |
25342
416856765a55
be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents:
25337
diff
changeset
|
3359 retval(i) = to_ov (it->second); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3360 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3361 return retval; |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3362 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3363 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3364 Cell |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3365 cdef_package::cdef_package_rep::get_classes (void) const |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3366 { return map2Cell (class_map); } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3367 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3368 Cell |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3369 cdef_package::cdef_package_rep::get_functions (void) const |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3370 { return map2Cell (function_map); } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3371 |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3372 Cell |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3373 cdef_package::cdef_package_rep::get_packages (void) const |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3374 { return map2Cell (package_map); } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3375 |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3376 octave_value |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3377 cdef_package::cdef_package_rep::find (const std::string& nm) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3378 { |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
3379 std::string symbol_name = get_name () + '.' + nm; |
16684
edbb123cbe3a
Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16676
diff
changeset
|
3380 |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
3381 octave::interpreter& interp |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
3382 = octave::__get_interpreter__ ("cdef_package::cdef_package_rep::find"); |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
3383 |
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
3384 return interp.find (symbol_name); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3385 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3386 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3387 octave_value_list |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3388 cdef_package::cdef_package_rep::meta_subsref |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3389 (const std::string& type, const std::list<octave_value_list>& idx, |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3390 int nargout) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3391 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3392 octave_value_list retval; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3393 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3394 switch (type[0]) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3395 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3396 case '.': |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3397 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3398 if (idx.front ().length () != 1) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3399 error ("invalid meta.package indexing"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3400 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3401 std::string nm = idx.front ()(0).xstring_value ("invalid meta.package indexing, expected a symbol name"); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20563
diff
changeset
|
3402 |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
3403 #if DEBUG_TRACE |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3404 std::cerr << "meta.package query: " << nm << std::endl; |
19031
1f36981ab323
allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents:
18692
diff
changeset
|
3405 #endif |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3406 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3407 octave_value o = find (nm); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3408 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3409 if (! o.is_defined ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3410 error ("member `%s' in package `%s' does not exist", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3411 nm.c_str (), get_name ().c_str ()); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3412 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3413 if (o.is_function ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3414 { |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23445
diff
changeset
|
3415 octave_function *fcn = o.function_value (); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3416 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3417 // NOTE: the case where the package query is the last |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3418 // part of this subsref index is handled in the parse |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3419 // tree, because there is some logic to handle magic |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3420 // "end" that makes it impossible to execute the |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3421 // function call at this stage. |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3422 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3423 if (type.size () > 1 |
23503
6a2fed2d39ac
improve some function names
John W. Eaton <jwe@octave.org>
parents:
23502
diff
changeset
|
3424 && ! fcn->accepts_postfix_index (type[1])) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3425 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3426 octave_value_list tmp_args; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3427 |
23501
1ee4b394a687
use feval instead of do_multi_index_op
John W. Eaton <jwe@octave.org>
parents:
23476
diff
changeset
|
3428 retval = octave::feval (o, tmp_args, nargout); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3429 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3430 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3431 retval(0) = o; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3432 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3433 if (type.size () > 1 && idx.size () > 1) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3434 retval = retval(0).next_subsref (nargout, type, |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3435 idx, 1); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3436 } |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3437 else if (type.size () > 1 && idx.size () > 1) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3438 retval = o.next_subsref (nargout, type, idx, 1); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3439 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3440 retval(0) = o; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
3441 } |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3442 break; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3443 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3444 default: |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3445 error ("invalid meta.package indexing"); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3446 break; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3447 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3448 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3449 return retval; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3450 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3451 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3452 void |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3453 cdef_package::cdef_package_rep::meta_release (void) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3454 { |
16689
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3455 // FIXME: Do we really want to unregister the package, as it |
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3456 // could still be referenced by classes or sub-packages? |
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3457 // If the package object is recreated later on, it won't |
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3458 // match the one already referenced by those classes or |
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3459 // sub-packages. |
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3460 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3461 cdef_manager& cdm |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3462 = octave::__get_cdef_manager__ ("cdef_package::cdef_package_rep::meta_release"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3463 |
24541
3d1b40992075
Don't unregister 'meta' package in meta_release (Bug #52111)
Piotr Held <pjheld@gmail.com>
parents:
24540
diff
changeset
|
3464 // Don't delete the "meta" package. |
3d1b40992075
Don't unregister 'meta' package in meta_release (Bug #52111)
Piotr Held <pjheld@gmail.com>
parents:
24540
diff
changeset
|
3465 if (this != cdm.meta ().get_rep ()) |
3d1b40992075
Don't unregister 'meta' package in meta_release (Bug #52111)
Piotr Held <pjheld@gmail.com>
parents:
24540
diff
changeset
|
3466 cdm.unregister_package (wrap ()); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3467 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3468 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3469 //---------------------------------------------------------------------------- |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
3470 |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3471 cdef_manager::cdef_manager (octave::interpreter& interp) |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3472 : m_interpreter (interp), m_all_classes (), m_all_packages (), |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3473 m_meta_class (), m_meta_property (), m_meta_method (), |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3474 m_meta_package (), m_meta () |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3475 { |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3476 octave::type_info& ti = m_interpreter.get_type_info (); |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3477 |
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24539
diff
changeset
|
3478 octave_classdef::register_type (ti); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3479 |
20946 | 3480 // bootstrap |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3481 cdef_class tmp_handle = make_class ("handle"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3482 |
24539 | 3483 m_meta_class = make_meta_class ("meta.class", tmp_handle); |
3484 | |
3485 tmp_handle.set_class (m_meta_class); | |
3486 m_meta_class.set_class (m_meta_class); | |
15909
b8bff84022d6
Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15897
diff
changeset
|
3487 |
20946 | 3488 // meta classes |
24539 | 3489 m_meta_property = make_meta_class ("meta.property", tmp_handle); |
3490 | |
3491 m_meta_method = make_meta_class ("meta.method", tmp_handle); | |
3492 | |
3493 m_meta_package = make_meta_class ("meta.package", tmp_handle); | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3494 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3495 cdef_class tmp_meta_event |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3496 = make_meta_class ("meta.event", tmp_handle); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3497 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3498 cdef_class tmp_meta_dynproperty |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3499 = make_meta_class ("meta.dynamicproperty", tmp_handle); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3500 |
20946 | 3501 // meta.class properties |
24539 | 3502 m_meta_class.install_property |
3503 (make_attribute (m_meta_class, "Abstract")); | |
3504 | |
3505 m_meta_class.install_property | |
3506 (make_attribute (m_meta_class, "ConstructOnLoad")); | |
3507 | |
3508 m_meta_class.install_property | |
3509 (make_property (m_meta_class, "ContainingPackage")); | |
3510 | |
3511 m_meta_class.install_property | |
3512 (make_property (m_meta_class, "Description")); | |
3513 | |
3514 m_meta_class.install_property | |
3515 (make_property (m_meta_class, "DetailedDescription")); | |
3516 | |
3517 m_meta_class.install_property | |
3518 (make_property (m_meta_class, "Events")); | |
3519 | |
3520 m_meta_class.install_property | |
3521 (make_attribute (m_meta_class, "HandleCompatible")); | |
3522 | |
3523 m_meta_class.install_property | |
3524 (make_attribute (m_meta_class, "Hidden")); | |
3525 | |
3526 m_meta_class.install_property | |
3527 (make_property (m_meta_class, "InferiorClasses", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3528 make_fcn_handle (class_get_inferiorclasses, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3529 "meta.class>get.InferiorClasses"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3530 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3531 |
24539 | 3532 m_meta_class.install_property |
3533 (make_property (m_meta_class, "Methods", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3534 make_fcn_handle (class_get_methods, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3535 "meta.class>get.Methods"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3536 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3537 |
24539 | 3538 m_meta_class.install_property |
3539 (make_property (m_meta_class, "MethodList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3540 make_fcn_handle (class_get_methods, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3541 "meta.class>get.MethodList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3542 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3543 |
24539 | 3544 m_meta_class.install_property (make_attribute (m_meta_class, "Name")); |
3545 | |
3546 m_meta_class.install_property | |
3547 (make_property (m_meta_class, "Properties", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3548 make_fcn_handle (class_get_properties, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3549 "meta.class>get.Properties"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3550 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3551 |
24539 | 3552 m_meta_class.install_property |
3553 (make_property (m_meta_class, "PropertyList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3554 make_fcn_handle (class_get_properties, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3555 "meta.class>get.PropertyList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3556 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3557 |
24539 | 3558 m_meta_class.install_property (make_attribute (m_meta_class, "Sealed")); |
3559 | |
3560 m_meta_class.install_property | |
3561 (make_property (m_meta_class, "SuperClasses", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3562 make_fcn_handle (class_get_superclasses, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3563 "meta.class>get.SuperClasses"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3564 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3565 |
24539 | 3566 m_meta_class.install_property |
3567 (make_property (m_meta_class, "SuperClassList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3568 make_fcn_handle (class_get_superclasses, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3569 "meta.class>get.SuperClassList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3570 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3571 |
20946 | 3572 // meta.class methods |
24539 | 3573 m_meta_class.install_method |
3574 (make_method (m_meta_class, "fromName", class_fromName, "public", true)); | |
3575 | |
3576 m_meta_class.install_method | |
3577 (make_method (m_meta_class, "fevalStatic", class_fevalStatic, "public", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3578 false)); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3579 |
24539 | 3580 m_meta_class.install_method |
3581 (make_method (m_meta_class, "getConstant", class_getConstant, "public", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3582 false)); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3583 |
24539 | 3584 m_meta_class.install_method (make_method (m_meta_class, "eq", class_eq)); |
3585 m_meta_class.install_method (make_method (m_meta_class, "ne", class_ne)); | |
3586 m_meta_class.install_method (make_method (m_meta_class, "lt", class_lt)); | |
3587 m_meta_class.install_method (make_method (m_meta_class, "le", class_le)); | |
3588 m_meta_class.install_method (make_method (m_meta_class, "gt", class_gt)); | |
3589 m_meta_class.install_method (make_method (m_meta_class, "ge", class_ge)); | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3590 |
20946 | 3591 // meta.method properties |
24539 | 3592 m_meta_method.install_property |
3593 (make_attribute (m_meta_method, "Abstract")); | |
3594 | |
3595 m_meta_method.install_property | |
3596 (make_attribute (m_meta_method, "Access")); | |
3597 | |
3598 m_meta_method.install_property | |
3599 (make_attribute (m_meta_method, "DefiningClass")); | |
3600 | |
3601 m_meta_method.install_property | |
3602 (make_attribute (m_meta_method, "Description")); | |
3603 | |
3604 m_meta_method.install_property | |
3605 (make_attribute (m_meta_method, "DetailedDescription")); | |
3606 | |
3607 m_meta_method.install_property | |
3608 (make_attribute (m_meta_method, "Hidden")); | |
3609 | |
3610 m_meta_method.install_property | |
3611 (make_attribute (m_meta_method, "Name")); | |
3612 | |
3613 m_meta_method.install_property | |
3614 (make_attribute (m_meta_method, "Sealed")); | |
3615 | |
3616 m_meta_method.install_property | |
3617 (make_attribute (m_meta_method, "Static")); | |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3618 |
20946 | 3619 // meta.property properties |
24539 | 3620 m_meta_property.install_property |
3621 (make_attribute (m_meta_property, "Name")); | |
3622 | |
3623 m_meta_property.install_property | |
3624 (make_attribute (m_meta_property, "Description")); | |
3625 | |
3626 m_meta_property.install_property | |
3627 (make_attribute (m_meta_property, "DetailedDescription")); | |
3628 | |
3629 m_meta_property.install_property | |
3630 (make_attribute (m_meta_property, "Abstract")); | |
3631 | |
3632 m_meta_property.install_property | |
3633 (make_attribute (m_meta_property, "Constant")); | |
3634 | |
3635 m_meta_property.install_property | |
3636 (make_attribute (m_meta_property, "GetAccess")); | |
3637 | |
3638 m_meta_property.install_property | |
3639 (make_attribute (m_meta_property, "SetAccess")); | |
3640 | |
3641 m_meta_property.install_property | |
3642 (make_attribute (m_meta_property, "Dependent")); | |
3643 | |
3644 m_meta_property.install_property | |
3645 (make_attribute (m_meta_property, "Transient")); | |
3646 | |
3647 m_meta_property.install_property | |
3648 (make_attribute (m_meta_property, "Hidden")); | |
3649 | |
3650 m_meta_property.install_property | |
3651 (make_attribute (m_meta_property, "GetObservable")); | |
3652 | |
3653 m_meta_property.install_property | |
3654 (make_attribute (m_meta_property, "SetObservable")); | |
3655 | |
3656 m_meta_property.install_property | |
3657 (make_attribute (m_meta_property, "GetMethod")); | |
3658 | |
3659 m_meta_property.install_property | |
3660 (make_attribute (m_meta_property, "SetMethod")); | |
3661 | |
3662 m_meta_property.install_property | |
3663 (make_attribute (m_meta_property, "DefiningClass")); | |
3664 | |
3665 m_meta_property.install_property | |
3666 (make_property (m_meta_property, "DefaultValue", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3667 make_fcn_handle (property_get_defaultvalue, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3668 "meta.property>get.DefaultValue"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3669 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3670 |
24539 | 3671 m_meta_property.install_property |
3672 (make_attribute (m_meta_property, "HasDefault")); | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3673 |
20946 | 3674 // meta.property events |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3675 // FIXME: add events |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3676 |
20946 | 3677 // handle methods |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3678 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3679 tmp_handle.install_method |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3680 (make_method (tmp_handle, "delete", handle_delete)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3681 |
20946 | 3682 // meta.package properties |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3683 |
24539 | 3684 m_meta_package.install_property |
3685 (make_attribute (m_meta_package, "Name")); | |
3686 | |
3687 m_meta_package.install_property | |
3688 (make_property (m_meta_package, "ContainingPackage")); | |
3689 | |
3690 m_meta_package.install_property | |
3691 (make_property (m_meta_package, "ClassList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3692 make_fcn_handle (package_get_classes, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3693 "meta.package>get.ClassList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3694 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3695 |
24539 | 3696 m_meta_package.install_property |
3697 (make_property (m_meta_package, "Classes", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3698 make_fcn_handle (package_get_classes, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3699 "meta.package>get.Classes"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3700 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3701 |
24539 | 3702 m_meta_package.install_property |
3703 (make_property (m_meta_package, "FunctionList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3704 make_fcn_handle (package_get_functions, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3705 "meta.package>get.FunctionList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3706 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3707 |
24539 | 3708 m_meta_package.install_property |
3709 (make_property (m_meta_package, "Functions", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3710 make_fcn_handle (package_get_functions, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3711 "meta.package>get.Functions"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3712 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3713 |
24539 | 3714 m_meta_package.install_property |
3715 (make_property (m_meta_package, "PackageList", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3716 make_fcn_handle (package_get_packages, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3717 "meta.package>get.PackageList"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3718 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3719 |
24539 | 3720 m_meta_package.install_property |
3721 (make_property (m_meta_package, "Packages", | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3722 make_fcn_handle (package_get_packages, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3723 "meta.package>get.Packages"), |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3724 "public", Matrix (), "private")); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3725 |
24539 | 3726 m_meta_package.install_method |
3727 (make_method (m_meta_package, "fromName", package_fromName, | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3728 "public", true)); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3729 |
24539 | 3730 m_meta_package.install_method |
3731 (make_method (m_meta_package, "getAllPackages", package_getAllPackages, | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3732 "public", true)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3733 |
20946 | 3734 // create "meta" package |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3735 cdef_package package_meta |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3736 = m_meta |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3737 = make_package ("meta"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3738 |
24539 | 3739 package_meta.install_class (m_meta_class, "class"); |
3740 package_meta.install_class (m_meta_property, "property"); | |
3741 package_meta.install_class (m_meta_method, "method"); | |
3742 package_meta.install_class (m_meta_package, "package"); | |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3743 package_meta.install_class (tmp_meta_event, "event"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3744 package_meta.install_class (tmp_meta_dynproperty, "dynproperty"); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3745 |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23683
diff
changeset
|
3746 octave::symbol_table& symtab = m_interpreter.get_symbol_table (); |
16689
04e110438873
Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16684
diff
changeset
|
3747 |
20946 | 3748 // install built-in classes into the symbol table |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
3749 symtab.install_built_in_function |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3750 ("meta.class", |
24539 | 3751 octave_value (m_meta_class.get_constructor_function ())); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3752 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
3753 symtab.install_built_in_function |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3754 ("meta.method", |
24539 | 3755 octave_value (m_meta_method.get_constructor_function ())); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3756 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23577
diff
changeset
|
3757 symtab.install_built_in_function |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3758 ("meta.property", |
24539 | 3759 octave_value (m_meta_property.get_constructor_function ())); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3760 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3761 symtab.install_built_in_function |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3762 ("meta.package", |
24539 | 3763 octave_value (m_meta_package.get_constructor_function ())); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3764 |
24542
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3765 // FIXME: meta.event and meta.dynproperty are not implemented |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3766 // and should not be installed into symbol table. |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3767 |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3768 // symtab.install_built_in_function |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3769 // ("meta.event", |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3770 // octave_value (tmp_meta_event.get_constructor_function ())); |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3771 |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3772 // symtab.install_built_in_function |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3773 // ("meta.dynproperty", |
d6f06eeb8917
Don't install meta.event and meta.dynproperty in the symbol table.
Piotr Held <pjheld@gmail.com>
parents:
24541
diff
changeset
|
3774 // octave_value (tmp_meta_dynproperty.get_constructor_function ())); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3775 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3776 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3777 cdef_class |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3778 cdef_manager::find_class (const std::string& name, bool error_if_not_found, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3779 bool load_if_not_found) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3780 { |
25337
3ff9192b676e
use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents:
25321
diff
changeset
|
3781 auto it = m_all_classes.find (name); |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3782 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3783 if (it == m_all_classes.end ()) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3784 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3785 if (load_if_not_found) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3786 { |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3787 octave_value ov_cls; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3788 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3789 size_t pos = name.rfind ('.'); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3790 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3791 if (pos == std::string::npos) |
26661
cf9e10ce3351
move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents:
26525
diff
changeset
|
3792 ov_cls = m_interpreter.find (name); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3793 else |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3794 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3795 std::string pack_name = name.substr (0, pos); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3796 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3797 cdef_package pack = find_package (pack_name, false, true); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3798 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3799 if (pack.ok ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3800 ov_cls = pack.find (name.substr (pos+1)); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3801 } |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3802 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3803 if (ov_cls.is_defined ()) |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3804 it = m_all_classes.find (name); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3805 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3806 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3807 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3808 if (it == m_all_classes.end ()) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3809 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3810 if (error_if_not_found) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3811 error ("class not found: %s", name.c_str ()); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3812 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3813 else |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3814 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3815 cdef_class cls = it->second; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3816 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3817 if (! cls.is_builtin ()) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3818 cls = lookup_class (cls); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3819 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3820 if (cls.ok ()) |
18692
fe0e34be5576
maint: untabify recently added code files.
Rik <rik@octave.org>
parents:
18520
diff
changeset
|
3821 return cls; |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3822 else |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3823 m_all_classes.erase (it); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3824 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3825 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3826 return cdef_class (); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3827 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3828 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3829 octave_function * |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3830 cdef_manager::find_method_symbol (const std::string& method_name, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3831 const std::string& class_name) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3832 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
3833 octave_function *retval = nullptr; |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3834 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3835 cdef_class cls = find_class (class_name, false, false); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3836 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3837 if (cls.ok ()) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3838 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3839 cdef_method meth = cls.find_method (method_name); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3840 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3841 if (meth.ok ()) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3842 retval = new octave_classdef_meta (meth); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3843 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3844 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3845 return retval; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3846 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3847 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3848 cdef_package |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3849 cdef_manager::find_package (const std::string& name, bool error_if_not_found, |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3850 bool load_if_not_found) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3851 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3852 cdef_package retval; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3853 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3854 std::map<std::string, cdef_package>::const_iterator it |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3855 = m_all_packages.find (name); |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3856 |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3857 if (it != m_all_packages.end ()) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3858 { |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3859 retval = it->second; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3860 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3861 if (! retval.ok ()) |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3862 error ("invalid package `%s'", name.c_str ()); |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3863 } |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3864 else |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3865 { |
25360
bc5f225bc578
eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents:
25342
diff
changeset
|
3866 octave::load_path& lp = m_interpreter.get_load_path (); |
23438
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3867 |
d24d01273bd0
eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents:
23435
diff
changeset
|
3868 if (load_if_not_found && lp.find_package (name)) |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3869 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3870 size_t pos = name.find ('.'); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3871 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3872 if (pos == std::string::npos) |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
3873 retval = make_package (name, ""); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3874 else |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3875 { |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3876 std::string parent_name = name.substr (0, pos); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3877 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3878 retval = make_package (name, parent_name); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3879 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3880 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3881 else if (error_if_not_found) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3882 error ("unknown package `%s'", name.c_str ()); |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3883 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3884 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3885 return retval; |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3886 } |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3887 |
23651
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3888 octave_function * |
5c6cceef132b
don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents:
23611
diff
changeset
|
3889 cdef_manager::find_package_symbol (const std::string& pack_name) |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3890 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
3891 octave_function *retval = nullptr; |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3892 |
20052
8b501a0db1e9
only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents:
19864
diff
changeset
|
3893 cdef_package pack = find_package (pack_name, false); |
16676
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3894 |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3895 if (pack.ok ()) |
7368654f302f
Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
3896 retval = new octave_classdef_meta (pack); |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3897 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3898 return retval; |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3899 } |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3900 |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3901 //---------------------------------------------------------------------------- |
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15986
diff
changeset
|
3902 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
3903 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
|
3904 doc: /* -*- texinfo -*- |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22297
diff
changeset
|
3905 @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
|
3906 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
|
3907 @end deftypefn */) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3908 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3909 if (args.length () != 1) |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3910 print_usage (); |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3911 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3912 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
|
3913 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3914 return to_ov (lookup_package (cname)); |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3915 } |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3916 |
20946 | 3917 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
|
3918 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
|
3919 @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
|
3920 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
|
3921 @end deftypefn */) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
3922 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3923 if (args.length () != 1) |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
3924 print_usage (); |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
3925 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3926 cdef_object obj = to_cdef (args(0)); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3927 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
3928 return to_ov (obj.get_class ()); |
15897
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
3929 } |
a413c6fe1726
Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15896
diff
changeset
|
3930 |
15036
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3931 /* |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3932 ;;; Local Variables: *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3933 ;;; mode: C++ *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3934 ;;; End: *** |
aa1f9e479c6e
octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3935 */ |