annotate libinterp/octave-value/ov-classdef.cc @ 24540:46440078d73b

don't use singleton for octave_value_typeinfo * ov-typeinfo.h, ov-typeinfo.cc (type_info): New class containing the functionaity provided by the non-static functions in the octave_value_typeinfo class. Define in octave namespace. (octave_value_typeinfo): Now a namespace containing global functions instead of a class containing all static functions. Provided for backward compatibility, so all functions are tagged as deprecated. * ops.h (INSTALL_UNOP_TI, INSTALL_NCUNOP_TI, INSTALL_BINOP_TI, INSTALL_CATOP_TI, INSTALL_ASSIGNOP_TI, INSTALL_ASSIGNANYOP_TI, INSTALL_ASSIGNCONV_TI, INSTALL_WIDENOP_TI): New macros. (install_ops): Accept reference to type_info object as an argument. * mk-ops.sh: Generate function decls and calls that pass reference to type_info object as an argument. * op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc): Use new _T1 macros. Update install_TYPE_ops function for each type to accept reference to type_info object as argument. * interpreter.h, interpreter.cc (interpreter::m_type_info): New member variable. (interpreter::get_type_info): New function. (interpreter::interpreter): Initialize m_type_info before m_symbol_table. Don't call install_types or install ops. That is now handled by the in type_info constructor. Don't call m_cdef_manager. That is now handled by the cdef_manager constructor. * interpreter-private.h, interpreter-private.cc (__get_type_info__): New function. Use where necessary to get reference to interpreter::m_type_info object. * ov-classdef.cc, ov-classdef.h (octave_classdef::octave_classdef): Handle all initialization here. (octave_classdef::initialize): Delete unused function. * ov.h, ov.cc (install_types): Accept reference to type_info object as argument. Pass on to individual register_type functions. * ov-base.h, ov-base.cc (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA): Update to define additional register_type functions that accepts reference to type_info object. (install_base_type_conversions): Update to use new *_TI macros.
author John W. Eaton <jwe@octave.org>
date Fri, 05 Jan 2018 18:44:53 -0500
parents 4e2ca22b3cf9
children 3d1b40992075
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2012-2017 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"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
39 #include "pt-assign.h"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
40 #include "pt-classdef.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
41 #include "pt-eval.h"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
42 #include "pt-funcall.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 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23553
diff changeset
367 else if (acc.iscell ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
368 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
369 Cell acc_c = acc.cell_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
370
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
371 cdef_class ctx = get_class_context ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
372
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
373 // 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
374
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
375 if (ctx.ok ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
376 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
377 if (ctx == cls)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
378 return true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
379
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
380 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
381 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
382 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
383
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
384 if (is_superclass (acc_cls, ctx))
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
385 return true;
15869
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 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
388 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
389 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
390 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
391 cls.get_name ().c_str ());
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
392
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
393 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
394 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
395
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
396 static bool
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
397 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
398 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
399 bool retval = false;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
400
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
401 if (fcn.is_defined ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
402 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
403 if (fcn.is_user_function ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
404 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
405 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
406
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
407 if (! uf || ! uf->body ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
408 retval = true;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
409 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
410 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
411 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
412 retval = true;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
413
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
414 return retval;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
415 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
416
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
417 static bool
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
418 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
419 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
420 octave::tree_evaluator& tw
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
421 = octave::__get_evaluator__ ("is_method_executing");
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
422
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
423 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
424
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
425 octave_function *stack_fcn = cs.current ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
426
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
427 octave_function *method_fcn = ov.function_value (true);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
428
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
429 // 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
430
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
431 if (stack_fcn && stack_fcn == method_fcn)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
432 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
433 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
434
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
435 // 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
436 // 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
437 // 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
438 // methods.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
439
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
440 if (uf)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
441 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
442 // 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
443 // 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
444 // 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
445 // is the first return value.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
446
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
447 octave::tree_parameter_list *pl = uf->is_classdef_constructor ()
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
448 ? uf->return_list () : uf->parameter_list ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
449
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
450 if (pl && pl->size () > 0)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
451 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
452 octave::tree_decl_elt *elt = pl->front ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
453
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
454 octave_value arg0 = tw.evaluate (elt);
16698
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 (arg0.is_defined () && arg0.type_name () == "object")
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 cdef_object arg0_obj = to_cdef (arg0);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
459
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
460 return obj.is (arg0_obj);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
461 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
462 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
463 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
464 }
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 return false;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
467 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
468
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
469 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
470 class_get_methods (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
471 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
472 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
473
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474 if (args.length () == 1 && args(0).type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
475 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
476 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
477
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478 retval(0) = cls.get_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
479 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
480
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
481 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
482 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
483
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
484 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
485 class_get_superclasses (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
486 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
487 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
488
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
489 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
490 && args(0).class_name () == "meta.class")
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 Cell classes = cls.get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
495
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
496 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
497 }
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
500 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
501
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
502 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
503 class_get_inferiorclasses (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
506
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
507 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
508 && args(0).class_name () == "meta.class")
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 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
511
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
512 Cell classes = cls.get ("InferiorClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
513
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
514 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
515 }
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
518 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
519
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
520 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
521 class_fromName (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
524
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
525 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
527
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
528 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
529
24100
4d9ceaf17dda return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
530 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
531
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
532 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
533 }
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 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
536 class_fevalStatic (const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
537 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
538 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
539 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
540
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
541 cdef_class cls (to_cdef (args(0)));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
542
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
543 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
544
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
545 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
546
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
547 if (! meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
548 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
549
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
550 if (! meth.is_static ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
551 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
552
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
553 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
554 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
555
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
556 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
557 class_getConstant (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
558 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
559 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
560
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
561 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
562 || args(0).class_name () != "meta.class")
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
563 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
564
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
565 cdef_class cls = to_cdef (args(0));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
566
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
567 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
568
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
569 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
570
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
571 if (! prop.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
572 error ("getConstant: property not found: %s",
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
573 prop_name.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
574
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
575 if (! prop.is_constant ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
576 error ("getConstant: property `%s' is not constant",
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
577 prop_name.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
578
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
579 retval(0) = prop.get_value (true, "getConstant");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
580
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
581 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
582 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
583
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
584 #define META_CLASS_CMP(OP, CLSA, CLSB, FUN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
585 static octave_value_list \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
586 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
587 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
588 octave_value_list retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
589 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
590 if (args.length () != 2 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
591 || args(0).type_name () != "object" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
592 || args(1).type_name () != "object" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
593 || args(0).class_name () != "meta.class" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
594 || args(1).class_name () != "meta.class") \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
595 error (#OP ": invalid arguments"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
596 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
597 cdef_class clsa = to_cdef (args(0)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
598 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
599 cdef_class clsb = to_cdef (args(1)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
600 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
601 retval(0) = FUN (CLSA, CLSB); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
602 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
603 return retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
604 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
605
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
606 META_CLASS_CMP (lt, clsb, clsa, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
607 META_CLASS_CMP (le, clsb, clsa, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
608 META_CLASS_CMP (gt, clsa, clsb, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
609 META_CLASS_CMP (ge, clsa, clsb, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
610 META_CLASS_CMP (eq, clsa, clsb, operator==)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
611 META_CLASS_CMP (ne, clsa, clsb, operator!=)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
612
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
613 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
614 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
615 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
616 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
617
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
618 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
619 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
620 cdef_property prop (to_cdef (args(0)));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
621
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
622 retval(0) = prop.get ("DefaultValue");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
623
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
624 if (! retval(0).is_defined ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
625 error_with_id ("Octave:class:NotDefaultDefined",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
626 "no default value for property `%s'",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
627 prop.get_name ().c_str ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
628 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
629
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
630 return retval;
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
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
633 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
634 handle_delete (const octave_value_list& /* args */, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
635 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
636 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
637
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
638 // FIXME: implement this
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
639
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
640 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
641 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
642
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
643 cdef_class
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
644 cdef_manager::make_class (const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
645 const std::list<cdef_class>& super_list)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
646 {
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
647 cdef_class cls (name, super_list);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
648
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
649 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
650
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
651 cls.put ("Abstract", false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
652 cls.put ("ConstructOnLoad", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
653 cls.put ("ContainingPackage", Matrix ());
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
654 cls.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
655 cls.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
656 cls.put ("Events", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
657 cls.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
658 cls.put ("InferiorClasses", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
659 cls.put ("Methods", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
660 cls.put ("Properties", Cell ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
661 cls.put ("Sealed", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
662
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
663 if (name == "handle")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
664 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
665 cls.put ("HandleCompatible", true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
666 cls.mark_as_handle_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
667 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
668 else if (super_list.empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
669 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
670 cls.put ("HandleCompatible", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
671 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
672 else
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
673 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
674 bool all_handle_compatible = true;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
675 bool has_handle_class = false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
676
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
677 for (const auto& cl : super_list)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
678 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
679 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
680 && 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
681 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
682 }
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 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
685 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
686 name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
687
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
688 cls.put ("HandleCompatible", all_handle_compatible);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
689 if (has_handle_class)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
690 cls.mark_as_handle_class ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
691 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
692
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
693 if (! name.empty ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
694 register_class (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
695
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
696 return cls;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
697 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
698
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
699 cdef_class
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
700 cdef_manager::make_class (const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
701 const cdef_class& super)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
702 {
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
703 return make_class (name, std::list<cdef_class> (1, super));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
704 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
705
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
706 cdef_class
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
707 cdef_manager::make_meta_class (const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
708 const cdef_class& super)
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
709 {
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
710 cdef_class cls = make_class (name, super);
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
711
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
712 cls.put ("Sealed", true);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
713 cls.mark_as_meta_class ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
714
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
715 return cls;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
716 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
717
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
718 cdef_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
719 cdef_manager::make_property (const cdef_class& cls, const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
720 const octave_value& get_method,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
721 const std::string& get_access,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
722 const octave_value& set_method,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
723 const std::string& set_access)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
724 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
725 cdef_property prop (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
726
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
727 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
728
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
729 prop.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
730 prop.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
731 prop.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
732 prop.put ("Constant", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
733 prop.put ("GetAccess", get_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
734 prop.put ("SetAccess", set_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
735 prop.put ("Dependent", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
736 prop.put ("Transient", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
737 prop.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
738 prop.put ("GetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
739 prop.put ("SetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
740 prop.put ("GetMethod", get_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
741 prop.put ("SetMethod", set_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
742 prop.put ("DefiningClass", to_ov (cls));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
743 prop.put ("DefaultValue", octave_value ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
744 prop.put ("HasDefault", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
745
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
746 std::string class_name = cls.get_name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
747
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
748 if (! get_method.isempty ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
749 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
750 if (! set_method.isempty ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
751 make_function_of_class (class_name, set_method);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
752
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
753 return prop;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
754 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
755
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
756 cdef_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
757 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
758 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
759 return make_property (cls, name, Matrix (), "public", Matrix (), "private");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
760 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
761
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
762 cdef_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
763 cdef_manager::make_method (const cdef_class& cls, const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
764 const octave_value& fcn,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
765 const std::string& m_access, bool is_static)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
766 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
767 cdef_method meth (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
768
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
769 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
770
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
771 meth.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
772 meth.put ("Access", m_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
773 meth.put ("DefiningClass", to_ov (cls));
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
774 meth.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
775 meth.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
776 meth.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
777 meth.put ("Sealed", true);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
778 meth.put ("Static", is_static);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
779
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
780 if (fcn.is_defined ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
781 make_function_of_class (cls, fcn);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
782
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
783 meth.set_function (fcn);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
785 if (is_dummy_method (fcn))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
786 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
787
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
788 return meth;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
789 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
791 cdef_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
792 cdef_manager::make_method (const cdef_class& cls, const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
793 octave_builtin::fcn ff,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
794 const std::string& m_access, bool is_static)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
795 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
796 octave_value fcn (new octave_builtin (ff, name));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
797
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
798 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
799 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
800
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
801 cdef_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
802 cdef_manager::make_method (const cdef_class& cls, const std::string& name,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
803 octave_builtin::meth mm,
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
804 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
805 {
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
806 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
807
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
808 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
809 }
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
810
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
811 cdef_package
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
812 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
813 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
814 cdef_package pack (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
815
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
816 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
817
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
818 if (parent.empty ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
819 pack.put ("ContainingPackage", Matrix ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
820 else
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
821 pack.put ("ContainingPackage", to_ov (find_package (parent)));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
822
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
823 if (! nm.empty ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
824 register_package (pack);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
825
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
826 return pack;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
827 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
828
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
829 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
830
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
831 int octave_classdef::t_id (-1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
832
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
833 const std::string octave_classdef::t_name ("object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
834
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
835 void
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24539
diff changeset
836 octave_classdef::register_type (octave::type_info& ti)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
837 {
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24539
diff changeset
838 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
839 octave_value (new octave_classdef ()));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
840 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
841
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
842 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
843 octave_classdef::subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
844 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
845 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
846 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
847 size_t skip = 0;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
848 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
849
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
850 cdef_class cls = object.get_class ();
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
851
18316
ff311e5ff6d8 Don't call classdef-overloaded subsref from builtin calls.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18314
diff changeset
852 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
853 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
854 cdef_method meth = cls.find_method ("subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
855
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
856 if (meth.ok ())
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
857 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
858 octave_value_list args;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
859
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
860 args(1) = make_idx_args (type, idx, "subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
861
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
862 count++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
863 args(0) = octave_value (this);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
864
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
865 retval = meth.execute (args, nargout, true, "subsref");
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
866
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
867 return retval;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
868 }
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
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
871 // 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
872
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
873 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
874
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
875 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
876 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
877
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
878 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
879 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
880
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
881 octave_value
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
882 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
883 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
884 bool auto_add)
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
885 {
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
886 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
887 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
888
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
889 // 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
890 // 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
891 // 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
892 // 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
893
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
894 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
895
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
896 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
897 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
898
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
899 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
900 }
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 octave_value
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
903 octave_classdef::subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
904 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
905 const octave_value& rhs)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
906 {
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
907 octave_value retval;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
908
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
909 cdef_class cls = object.get_class ();
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
910
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
911 if (! in_class_method (cls) && ! called_from_builtin ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
912 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
913 cdef_method meth = cls.find_method ("subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
914
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
915 if (meth.ok ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
916 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
917 octave_value_list args;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
918
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
919 args(1) = make_idx_args (type, idx, "subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
920
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
921 count++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
922 args(0) = octave_value (this);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
923 args(2) = rhs;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
924
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
925 octave_value_list retlist;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
926
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
927 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
928
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21751
diff changeset
929 if (retlist.empty ())
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
930 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
931
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
932 retval = retlist(0);
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
933 }
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
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
936 if (! retval.is_defined ())
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
937 retval = object.subsasgn (type, idx, rhs);
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
938
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
939 return retval;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
940 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
941
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
942 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
943 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
944 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
945 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
946 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
947 if (type.length () == 1 && type[0] == '(')
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
948 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
949 object = object.make_array ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
950
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
951 return subsasgn (type, idx, rhs);
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
952 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
953 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
954 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
955
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
956 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
957 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
958
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
959 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
960 octave_classdef::print (std::ostream& os, bool)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
961 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
962 print_raw (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
963 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
964
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
965 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
966 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
967 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
968 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
969 os << "<object ";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
970 if (object.is_array ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
971 os << "array ";
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23693
diff changeset
972 os << class_name () << '>';
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
973 newline (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
974 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
975
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
976 bool
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
977 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
978 const std::string& name) const
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
979 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
980 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
981 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
982
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
983 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
984 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
985 bool print_padding)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
986 {
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22871
diff changeset
987 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
988 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
989
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
990 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
991 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
992 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
993 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
994
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
995 if (cls.ok ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
996 return is_superclass (cls, object.get_class ());
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
997
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
998 return false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
999 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1000
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1001 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1002
15986
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1003 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
1004 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1005 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
1006 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
1007 : 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
1008
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1009 ~octave_classdef_meta (void)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1010 { object.meta_release (); }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1011
23683
ffd27f53fc79 make +package function calls work again (bug #51295, #51296)
John W. Eaton <jwe@octave.org>
parents: 23666
diff changeset
1012 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
1013
23838
6e0fd7e3c262 Fix argument lookup in '+' package functions (Bug #51532).
Piotr Held <pjheld@gmail.com>
parents: 23829
diff changeset
1014 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
1015
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
1016 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
1017
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1018 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1019 subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1020 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1021 int nargout)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1022 {
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
1023 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
1024 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1025
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
1026 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
1027 const octave_value_list& args)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1028 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1029 // Emulate ()-type meta subsref
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1030
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
1031 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
1032 std::string type ("(");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1033
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
1034 return subsref (type, idx, nargout);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1035 }
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1036
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
1037 bool accepts_postfix_index (char type) const
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
1038 { 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
1039
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1040 bool
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
1041 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
1042 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1043 bool retval = false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1044
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1045 if (object.is_class ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1046 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1047 if (cname.empty ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1048 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1049 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1050 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1051 cdef_class cls (object);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1052
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1053 if (cls.get_name () == cname)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1054 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1055 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1056 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1057
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1058 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1059 }
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1060
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1061 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
1062 cdef_meta_object object;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1063 };
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1064
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1065 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1066
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1067 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
1068 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1069 public:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1070 octave_classdef_superclass_ref (const octave_value_list& a)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1071 : octave_function (), args (a) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1072
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
1073 ~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
1074
24114
90932304969a maint: use correct const qualifier on overridden virtual function
Mike Miller <mtmiller@octave.org>
parents: 24100
diff changeset
1075 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
1076
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
1077 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
1078
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1079 octave_value_list
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
1080 call (octave::tree_evaluator&, 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
1081 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1082 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1083
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1084 std::string meth_name;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1085 bool in_constructor;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1086 cdef_class ctx;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1087
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1088 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
1089
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1090 if (! ctx.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1091 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
1092
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1093 std::string mname = args(0).string_value ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1094 std::string cname = args(1).string_value ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1095
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1096 cdef_class cls = lookup_class (cname);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1097
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1098 if (in_constructor)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1099 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1100 if (! is_direct_superclass (cls, ctx))
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1101 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
1102 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
1103
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1104 if (! is_constructed_object (mname))
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21040
diff changeset
1105 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
1106 mname.c_str ());
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1107
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1108 octave::symbol_scope scope
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1109 = octave::__require_current_scope__ ("octave_classdef_superclass_ref::call");
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23599
diff changeset
1110
24361
8bcfddad15ec use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents: 24270
diff changeset
1111 octave_value sym = scope.varval (mname);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1112
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1113 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
1114
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1115 retval(0) = sym;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1116 }
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1117 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1118 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1119 if (mname != meth_name)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1120 error ("method name mismatch (`%s' != `%s')",
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1121 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
1122
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1123 if (! is_strict_superclass (cls, ctx))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1124 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
1125 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
1126
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1127 // I see 2 possible implementations here:
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1128 // 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
1129 // context; this avoids duplicating code, but
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1130 // 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
1131 // 2) lookup the method manually and call
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1132 // cdef_method::execute; this duplicates part of
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1133 // 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
1134 // assumption of 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1135 // 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
1136 // 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
1137
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1138 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
1139
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1140 if (! meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1141 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
1142 meth_name.c_str (), cname.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1143
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1144 retval = meth.execute (idx, nargout, true,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1145 meth_name);
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
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1148 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1149 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1150
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1151 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1152 bool is_constructed_object (const std::string nm)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1153 {
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
1154 octave::call_stack& cs
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
1155 = octave::__get_call_stack__ ("octave_classdef_superclass_ref::is_constructed_object");
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
1156
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23534
diff changeset
1157 octave_function *of = cs.current ();
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1158
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1159 if (of->is_classdef_constructor ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1160 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1161 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
1162
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1163 if (uf)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1164 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1165 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
1166
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1167 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
1168 return (ret_list->front ()->name () == nm);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1169 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1170 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1171
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1172 return false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1173 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1174
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1175 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1176 octave_value_list args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1177 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1178
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1179 //----------------------------------------------------------------------------
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1180
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1181 octave_map
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1182 cdef_object::map_value (void) const
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1183 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1184 octave_map retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1185
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1186 warning_with_id ("Octave:classdef-to-struct",
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1187 "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
1188 "overrides the access restrictions defined for properties. "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1189 "All properties are returned, including private and "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1190 "protected ones.");
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1191
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1192 cdef_class cls = get_class ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1193
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1194 if (cls.ok ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1195 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1196 std::map<std::string, cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1197
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1198 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
1199
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1200 // 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
1201 for (auto& prop_val : props)
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1202 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1203 if (is_array ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1204 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1205 Array<cdef_object> a_obj = array_value ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1206
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1207 Cell cvalue (a_obj.dims ());
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1208
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1209 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
1210 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
1211
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1212 retval.setfield (prop_val.first, cvalue);
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1213 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1214 else
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1215 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1216 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
1217 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
1218
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1219 retval.setfield (prop_val.first, cvalue);
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1220 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1221 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1222 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1223
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1224 return retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1225 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1226
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1227 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1228 cdef_object_rep::map_keys (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1229 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1230 cdef_class cls = get_class ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1231
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1232 if (cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1233 return cls.get_names ();
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
1234
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1235 return string_vector ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1236 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1237
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1238 octave_value_list
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1239 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
1240 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
1241 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
1242 const cdef_class& context, bool auto_add)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1243 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1244 skip = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1245
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1246 cdef_class cls = (context.ok () ? context : get_class ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1247
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1248 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1249
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1250 if (! cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1251 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1252
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1253 switch (type[0])
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1254 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1255 case '.':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1256 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1257 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
1258
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1259 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
1260
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1261 if (meth.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1262 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1263 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
1264
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1265 octave_value_list args;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1266
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1267 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1268
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1269 if (type.length () > 1 && type[1] == '(')
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1270 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1271 std::list<octave_value_list>::const_iterator it = idx.begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1272
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1273 args = *++it;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1274
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1275 skip++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1276 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1277
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1278 if (meth.is_static ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1279 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
1280 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1281 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1282 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1283 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
1284 true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1285 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1286 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1287
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1288 if (skip == 0)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1289 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1290 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
1291
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1292 if (! prop.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1293 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
1294
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1295 if (prop.is_constant ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1296 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
1297 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1298 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1299 refcount++;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1300 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
1301 true, "subsref");
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1302 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1303
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1304 skip = 1;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1305 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1306 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1307 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1308
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1309 case '(':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1310 {
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1311 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
1312
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1313 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1314 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1315
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1316 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
1317 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1318 skip++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1319 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
1320 }
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1321 else
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1322 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1323 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
1324
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1325 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
1326
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1327 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
1328
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1329 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
1330 }
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1331 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1332 break;
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1333
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1334 default:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1335 error ("object cannot be indexed with `%c'", type[0]);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1336 break;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1337 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1338
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1339 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1340 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1341
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1342 octave_value
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1343 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
1344 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
1345 const octave_value& rhs)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1346 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1347 octave_value retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1348
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1349 cdef_class cls = get_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1350
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1351 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1352 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1353 case '.':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1354 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1355 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
1356
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1357 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
1358
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1359 if (! prop.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1360 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
1361
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1362 if (prop.is_constant ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1363 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
1364 name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1365
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1366 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1367
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1368 cdef_object obj (this);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1369
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1370 if (type.length () == 1)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1371 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1372 prop.set_value (obj, rhs, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1373
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1374 retval = to_ov (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1375 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1376 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1377 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1378 octave_value val =
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1379 prop.get_value (obj, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1380
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1381 std::list<octave_value_list> args (idx);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1382
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1383 args.erase (args.begin ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1384
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1385 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
1386 type.substr (1), args, rhs);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1387
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1388 if (val.class_name () != "object"
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1389 || ! to_cdef (val).is_handle_object ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1390 prop.set_value (obj, val, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1391
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1392 retval = to_ov (obj);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1393 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1394 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1395 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1396
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1397 case '(':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1398 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1399 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1400
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1401 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1402
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1403 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
1404
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1405 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
1406
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1407 new_obj.set_class (get_class ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1408
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1409 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
1410
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1411 retval = tmp;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1412 }
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1413 break;
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1414
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1415 default:
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1416 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
1417 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1418 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1419
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1420 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1421 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1422
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1423 void
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1424 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
1425 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1426 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
1427
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1428 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
1429
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1430 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
1431
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1432 ctor_list[cls] = supcls_list;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1433 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1434
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1435 octave_value_list
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1436 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
1437 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1438 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
1439 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
1440 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1441 octave_value_list retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1442
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1443 skip = 1;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1444
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1445 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1446 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1447 case '(':
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 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
1450
20125
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1451 if (ival.empty ())
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1452 {
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1453 refcount++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1454 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
1455 break;
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1456 }
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1457
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1458 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
1459 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
1460
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1461 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
1462 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1463 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1464 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1465 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
1466 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22324
diff changeset
1467 catch (octave::index_exception& e)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1468 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1469 // 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
1470 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
1471 throw;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1472 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1473
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1474 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
1475 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1476
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1477 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
1478
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1479 // 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
1480 // 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
1481 // invalid cdef_objects.
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1482
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1483 if (auto_add)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1484 fill_empty_values (ires);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1485
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1486 if (is_scalar)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1487 retval(0) = to_ov (ires(0));
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1488 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1489 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1490 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
1491
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1492 array_obj.set_class (get_class ());
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1493
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1494 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
1495 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1496 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1497 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1498
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1499 case '.':
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1500 if (type.size () == 1 && idx.size () == 1)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1501 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1502 Cell c (dims ());
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1503
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1504 octave_idx_type n = array.numel ();
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1505
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1506 // dummy variables
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1507 size_t dummy_skip;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1508 cdef_class dummy_cls;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1509
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1510 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
1511 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1512 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
1513 dummy_cls);
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1514
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1515 if (r.length () > 0)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1516 c(i) = r(0);
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1517 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1518
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1519 retval(0) = octave_value (c, true);
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1520
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1521 break;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1522 }
23826
d69021d58a61 avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1523 OCTAVE_FALLTHROUGH;
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1524
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1525 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
1526 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
1527 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1528 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1529 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1530
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1531 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1532 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1533
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1534 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1535 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
1536 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1537 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1538 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1539 octave_value retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1540
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1541 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1542 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1543 case '(':
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1544 if (type.length () == 1)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1545 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1546 cdef_object rhs_obj = to_cdef (rhs);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1547
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1548 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
1549 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
1550 rhs_obj.class_name ().c_str (),
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1551 class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1552
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1553 const octave_value_list& ival = idx.front ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1554 bool is_scalar = true;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1555 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
1556
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1557 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
1558 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1559 try
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1560 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1561 iv(i) = ival(i).index_vector ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1562 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22324
diff changeset
1563 catch (octave::index_exception& e)
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1564 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1565 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
1566 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
1567 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1568
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1569 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
1570 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1571
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1572 Array<cdef_object> rhs_mat;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1573
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1574 if (! rhs_obj.is_array ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1575 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1576 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
1577 rhs_mat(0) = rhs_obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1578 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1579 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1580 rhs_mat = rhs_obj.array_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1581
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1582 octave_idx_type n = array.numel ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1583
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1584 array.assign (iv, rhs_mat, cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1585
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1586 if (array.numel () > n)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1587 fill_empty_values ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1588
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1589 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1590 retval = to_ov (cdef_object (this));
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1591 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1592 else
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1593 {
23345
0b6810085ed3 Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 23220
diff changeset
1594 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
1595
0b6810085ed3 Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 23220
diff changeset
1596 // 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
1597 // 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
1598 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
1599 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
1600 ? 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
1601 ? 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
1602 : ovl (ivl(0), one));
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1603
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1604 bool is_scalar = true;
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1605
23345
0b6810085ed3 Altering class member of object array modifies other class members (bug #46660).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 23220
diff changeset
1606 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
1607
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1608 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
1609 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1610 try
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
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 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
1613 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22324
diff changeset
1614 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
1615 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1616 // 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
1617 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
1618 throw;
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1619 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1620
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1621 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
1622
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1623 if (! is_scalar)
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21040
diff changeset
1624 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
1625 ", 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
1626 "array.");
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1627 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1628
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1629 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
1630
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1631 if (a.numel () != 1)
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21040
diff changeset
1632 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
1633
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1634 cdef_object obj = a(0);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1635
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1636 int ignore_copies = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1637
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1638 // 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
1639 // 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
1640
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1641 if (! obj.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1642 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
1643 else
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1644 // 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
1645 // that we can safely ignore:
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1646 // - 1 in "array"
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1647 // - 1 in "a"
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1648 ignore_copies = 2;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1649
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1650 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
1651
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1652 next_idx.erase (next_idx.begin ());
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1653
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1654 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
1655 rhs, ignore_copies);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1656
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1657 cdef_object robj = to_cdef (tmp);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1658
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1659 if (! robj.ok ()
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1660 || robj.is_array ()
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1661 || 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
1662 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
1663 class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1664
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1665 // Small optimization, when dealing with handle
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1666 // 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
1667 // of subsasgn back into the array.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1668
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1669 if (! robj.is (a(0)))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1670 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1671 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
1672 robj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1673
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1674 octave_idx_type n = array.numel ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1675
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1676 array.assign (iv, rhs_a);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1677
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1678 if (array.numel () > n)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1679 fill_empty_values ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1680 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1681
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1682 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1683
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1684 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
1685 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1686 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1687
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1688 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
1689 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
1690 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1691 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1692 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1693
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1694 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1695 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1696
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1697 void
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1698 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
1699 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1700 cdef_class cls = get_class ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1701
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1702 cdef_object obj;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1703
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1704 int n = arr.numel ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1705
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1706 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
1707 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1708 if (! arr.xelem (i).ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1709 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1710 if (! obj.ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1711 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1712 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
1713
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1714 arr.xelem (i) = obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1715 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1716 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1717 arr.xelem (i) = obj.copy ();
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1718 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1719 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1720 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
1721
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1722 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1723 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
1724 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1725 return (is_constructed ()
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1726 || 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
1727 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1728
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1729 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1730 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
1731 {
23534
b6498c088fca maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents: 23533
diff changeset
1732 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
1733
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1734 if (is_constructed ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1735 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1736 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
1737 || it->second.empty ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1738 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1739
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1740 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
1741 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
1742 return false;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1743
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1744 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1745 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1746
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20912
diff changeset
1747 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
1748 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
1749 {
9851a296cf87 Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20181
diff changeset
1750 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
1751 }
9851a296cf87 Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20181
diff changeset
1752
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1753 handle_cdef_object::~handle_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1754 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1755 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1756 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
1757 << " object (handle)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1758 #endif
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1759 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1760
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1761 value_cdef_object::~value_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1762 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1763 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1764 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
1765 << " object (value)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1766 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1767 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1768
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
1769 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>& superclasses)
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
1770 : cdef_meta_object_rep (), member_count (0), handle_class (false),
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
1771 object_count (0), meta (false)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1772 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1773 put ("SuperClasses", to_ov (superclasses));
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1774 implicit_ctor_list = superclasses;
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1775 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1776
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1777 cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1778 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
1779 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1780 method_iterator it = method_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1781
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1782 if (it == method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1783 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1784 // FIXME: look into class directory
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1785 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1786 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1787 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1788 cdef_method& meth = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1789
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1790 // FIXME: check if method reload needed
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1791
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1792 if (meth.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
1793 return meth;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1794 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1795
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1796 if (! local)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1797 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1798 // Look into superclasses
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1799
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1800 Cell super_classes = get ("SuperClasses").cell_value ();
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1801
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1802 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
1803 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1804 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1805
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1806 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
1807
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1808 if (meth.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1809 return meth;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1810 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1811 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1812
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1813 return cdef_method ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1814 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1815
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1816 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
1817 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1818 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1819 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
1820 : 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
1821
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1822 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
1823 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1824 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
1825 stmt_p->accept (*this);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1826 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1827
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1828 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
1829 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1830 if (t.is_expression ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1831 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1832 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1833
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1834 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
1835 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1836 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1837 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1838
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1839 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
1840 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1841 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1842 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1843
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1844 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
1845 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1846 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1847 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1848
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1849 void visit_funcall (octave::tree_funcall& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1850 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1851 octave_value fcn = t.function ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1852
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1853 if (fcn.is_function ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1854 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1855 octave_function *of = fcn.function_value (true);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1856
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1857 if (of)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1858 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1859 if (of->name () == "__superclass_reference__")
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1860 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1861 octave_value_list args = t.arguments ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1862
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1863 if (args(0).string_value () == obj_name)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1864 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1865 std::string class_name = args(1).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1866
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1867 cdef_class cls = lookup_class (class_name, false);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1868
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1869 if (cls.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1870 ctor_list.push_back (cls);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1871 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1872 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1873 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1874 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1875 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1876
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1877 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
1878 { return ctor_list; }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1879
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1880 // NO-OP
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1881 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
1882 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
1883 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
1884 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
1885 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
1886 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
1887 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
1888 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
1889 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
1890 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
1891 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
1892 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
1893 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
1894 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
1895 void visit_identifier (octave::tree_identifier&) { }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1896 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
1897 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
1898 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
1899 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
1900 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
1901 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
1902 void visit_matrix (octave::tree_matrix&) { }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1903 void visit_cell (octave::tree_cell&) { }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1904 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
1905 void visit_constant (octave::tree_constant&) { }
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1906 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
1907 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
1908 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
1909 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
1910 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
1911 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
1912 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
1913 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
1914 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
1915 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
1916
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1917 private:
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1918 // 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
1919 std::string who;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1920
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1921 // 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
1922 std::string obj_name;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1923
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1924 // 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
1925 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
1926 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1927
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1928 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1929 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
1930 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1931 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
1932
15911
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
1933 member_count++;
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
1934
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1935 if (meth.is_constructor ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1936 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1937 // 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
1938 // constructors are called explicitly.
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1939
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1940 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
1941
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1942 if (of)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1943 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1944 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
1945
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1946 if (uf)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1947 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1948 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
1949 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
1950
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1951 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
1952 error ("%s: invalid constructor output arguments",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
1953 meth.get_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1954
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1955 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
1956 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
1957
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1958 body->accept (a);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1959
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1960 std::list<cdef_class> explicit_ctor_list
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1961 = a.get_constructor_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1962
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1963 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
1964 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1965 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1966 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
1967 << 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
1968 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1969
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1970 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
1971 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1972 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1973 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1974 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1975 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1976
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1977 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1978 cdef_class::cdef_class_rep::load_all_methods (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1979 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1980 // FIXME: re-scan class directory
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1981 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1982
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1983 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1984 cdef_class::cdef_class_rep::get_methods (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1985 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1986 std::map<std::string,cdef_method> meths;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1987
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1988 find_methods (meths, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1989
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1990 Cell c (meths.size (), 1);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1991
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1992 int idx = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1993
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
1994 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
1995 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
1996
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1997 return c;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1998 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1999
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2000 void
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2001 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
2002 cdef_method>& meths,
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2003 bool only_inherited)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2004 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2005 load_all_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2006
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2007 method_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2008
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2009 for (it = method_map.begin (); it != method_map.end (); ++it)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2010 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2011 if (! it->second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2012 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2013 std::string nm = it->second.get_name ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2014
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2015 if (meths.find (nm) == meths.end ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2016 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2017 if (only_inherited)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2018 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2019 octave_value acc = it->second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2020
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2021 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2022 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2023 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2024 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2025
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2026 meths[nm] = it->second;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2027 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2028 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2029 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2030
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2031 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2032
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2033 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2034
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2035 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2036 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2037 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2038
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2039 cls.get_rep ()->find_methods (meths, true);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2040 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2041 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2042
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2043 cdef_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2044 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
2045 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2046 property_iterator it = property_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2047
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2048 if (it != property_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2049 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2050 cdef_property& prop = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2051
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2052 if (prop.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2053 return prop;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2054 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2055
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2056 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2057
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2058 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2059
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2060 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2061 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2062 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2063
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2064 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
2065
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2066 if (prop.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2067 return prop;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2068 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2069
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2070 return cdef_property ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2071 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2072
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2073 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2074 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
2075 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2076 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
2077
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
2078 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2079 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2080
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2081 Cell
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2082 cdef_class::cdef_class_rep::get_properties (int mode)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2083 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2084 std::map<std::string,cdef_property> props;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2085
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2086 props = get_property_map (mode);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2087
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2088 Cell c (props.size (), 1);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2089
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2090 int idx = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2091
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2092 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
2093 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
2094
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2095 return c;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2096 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2097
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2098 std::map<std::string, cdef_property>
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2099 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
2100 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2101 std::map<std::string,cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2102
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2103 find_properties (props, mode);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2104
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2105 return props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2106 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2107
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2108 void
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2109 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
2110 cdef_property>& props,
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2111 int mode)
15036
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 property_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2114
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2115 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
2116 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2117 std::string nm = it->second.get_name ();
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 if (props.find (nm) == props.end ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2120 {
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2121 if (mode == property_inherited)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2122 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2123 octave_value acc = it->second.get ("GetAccess");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2124
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2125 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2126 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2127 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2128 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2129
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2130 props[nm] = it->second;
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2131 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2132 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2133
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2134 // Look into superclasses
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 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2137
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2138 for (int i = 0; i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2139 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2140 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2141
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2142 cls.get_rep ()->find_properties (props,
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2143 (mode == property_all
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2144 ? property_all
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2145 : property_inherited));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2146 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2147 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2148
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2149 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2150 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
2151 bool all)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2152 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2153 load_all_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2154
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2155 for (const auto& cls_fnmap : method_map)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2156 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2157 if (! cls_fnmap.second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2158 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2159 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
2160
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2161 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2162 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2163 octave_value acc = cls_fnmap.second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2164
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2165 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2166 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2167 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2168 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2169
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2170 names.insert (nm);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2171 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2172 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2173
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2174 for (const auto& pname_prop : property_map)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2175 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2176 std::string nm = pname_prop.second.get_name ();
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2177
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2178 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2179 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2180 octave_value acc = pname_prop.second.get ("GetAccess");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2181
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2182 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2183 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2184 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2185 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2186
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2187 names.insert (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2188 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2189
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2190 // Look into superclasses
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 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2193
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2194 for (int i = 0; i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2195 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2196 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2197
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2198 cls.get_rep ()->find_names (names, all);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2199 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2200 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2201
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2202 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2203 cdef_class::cdef_class_rep::get_names (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2204 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2205 std::set<std::string> names;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2206
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2207 find_names (names, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2208
22374
f38e81248556 ov-classdef.cc: use string_vector constructor for string containers.
Carnë Draug <carandraug@octave.org>
parents: 22327
diff changeset
2209 string_vector v (names);
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2210
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2211 return v.sort (true);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2212 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2213
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2214 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2215 cdef_class::cdef_class_rep::delete_object (cdef_object obj)
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 method_iterator it = method_map.find ("delete");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2218
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2219 if (it != method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2220 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2221 cdef_class cls = obj.get_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2222
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2223 obj.set_class (wrap ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2224
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2225 it->second.execute (obj, octave_value_list (), 0, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2226
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2227 obj.set_class (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2228 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2229
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2230 // FIXME: should we destroy corresponding properties here?
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2231
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2232 // Call "delete" in super classes
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2233
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2234 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2235
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2236 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2237 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2238 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2239
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2240 cls.delete_object (obj);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2241 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2242 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2243
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2244 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
2245 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
2246 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2247 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2248 {
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2249 size_t skip = 1;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2250
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2251 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2252
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2253 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2254 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2255 case '(':
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2256 // Constructor call
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2257
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2258 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2259 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
2260 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2261
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2262 retval(0) = construct (idx.front ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2263 break;
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2264
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2265 case '.':
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2266 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2267 // 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
2268
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2269 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2270 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
2271 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2272
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2273 if (idx.front ().length () != 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2274 error ("invalid meta.class indexing");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2275
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2276 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
2277
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2278 cdef_method meth = find_method (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2279
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2280 if (meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2281 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2282 if (! meth.is_static ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2283 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
2284
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2285 octave_value_list args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2286
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2287 if (type.length () > 1 && idx.size () > 1
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2288 && type[1] == '(')
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2289 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2290 args = *(++(idx.begin ()));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2291 skip++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2292 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2293
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2294 retval = meth.execute (args, (type.length () > skip
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2295 ? 1 : nargout), true,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2296 "meta.class");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2297 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2298 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2299 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2300 cdef_property prop = find_property (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2301
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2302 if (! prop.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2303 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
2304
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2305 if (! prop.is_constant ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2306 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
2307
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2308 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
2309 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2310 }
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2311 break;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2312
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2313 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
2314 error ("invalid meta.class indexing");
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2315 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2316 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2317
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2318 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
2319 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
2320
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2321 return retval;
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
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2324 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
2325 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
2326 {
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2327 cdef_manager& cdm
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2328 = 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
2329
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2330 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
2331 }
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2332
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2333 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2334 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
2335 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2336 // Populate the object with default property values
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2337
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2338 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
2339 get ("SuperClasses").cell_value ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2340
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2341 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
2342 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
2343
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2344 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
2345 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2346 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
2347 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2348 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
2349
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2350 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
2351 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
2352 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
2353 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
2354 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2355 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2356
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2357 refcount++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2358 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
2359 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2360
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2361 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2362 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
2363 const octave_value_list& args)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2364 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2365 octave_value_list empty_args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2366
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2367 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
2368 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2369 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
2370
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2371 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
2372 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2373
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2374 std::string cls_name = get_name ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2375 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
2376
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2377 cdef_method ctor = find_method (ctor_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2378
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2379 if (ctor.ok ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2380 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2381 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
2382 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
2383
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2384 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
2385 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
2386
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2387 if (ctor_retval.length () != 1)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
2388 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
2389 ctor_name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2390
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2391 obj = to_cdef (ctor_retval(0));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2392 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2393
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2394 obj.mark_as_constructed (wrap ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2395 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2396
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2397 octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2398 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
2399 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2400 cdef_object obj = construct_object (args);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2401
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2402 if (obj.ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2403 return to_ov (obj);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2404
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2405 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2406 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2407
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2408 cdef_object
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2409 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
2410 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2411 if (is_abstract ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2412 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
2413 get_name ().c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2414
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2415 cdef_object obj;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2416
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2417 if (is_meta_class ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2418 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2419 // 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
2420 // 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
2421
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2422 cdef_class this_cls = wrap ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2423
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2424 static cdef_object empty_class;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2425
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2426 cdef_manager& cdm
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2427 = 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
2428
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2429 if (this_cls == cdm.meta_class ())
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2430 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2431 if (! empty_class.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2432 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
2433 obj = empty_class;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2434 }
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2435 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
2436 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2437 static cdef_property empty_property;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2438
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2439 if (! empty_class.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2440 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
2441 if (! empty_property.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2442 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
2443 obj = empty_property;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2444 }
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2445 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
2446 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2447 static cdef_method empty_method;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2448
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2449 if (! empty_class.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2450 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
2451 if (! empty_method.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2452 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
2453 obj = empty_method;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2454 }
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2455 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
2456 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2457 static cdef_package empty_package;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2458
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2459 if (! empty_package.ok ())
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2460 empty_package = cdm.make_package ("");
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2461 obj = empty_package;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2462 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2463 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2464 panic_impossible ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2465
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2466 return obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2467 }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
2468 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2469 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2470 if (is_handle_class ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2471 obj = cdef_object (new handle_cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2472 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2473 obj = cdef_object (new value_cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2474 obj.set_class (wrap ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2475
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2476 initialize_object (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2477
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2478 run_constructor (obj, args);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2479
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2480 return obj;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2481 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2482
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2483 return cdef_object ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2484 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2485
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2486 static octave_value
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2487 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
2488 octave::tree_classdef_attribute *t)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2489 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2490 octave::tree_expression *expr = t->expression ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2491
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2492 if (expr)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2493 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2494 if (expr->is_identifier ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2495 {
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2496 std::string s = expr->name ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2497
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2498 if (s == "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2499 return std::string ("public");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2500 else if (s == "protected")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2501 return std::string ("protected");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2502 else if (s == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2503 return std::string ("private");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2504 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2505
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2506 return tw.evaluate (expr);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2507 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2508 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2509 return octave_value (true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2510 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2511
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
2512 template <typename T>
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2513 static std::string
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
2514 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
2515 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2516 if (v.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2517 return v.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2518 else if (t->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2519 return t->expression ()->original_text ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2520 else
23829
01899bdd2a3a Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents: 23826
diff changeset
2521 return "true";
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2522 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2523
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2524 cdef_class
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2525 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
2526 octave::tree_classdef *t, bool is_at_folder)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2527 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2528 cdef_class retval;
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2529 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
2530
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2531 // Class creation
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2532
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2533 class_name = full_class_name = t->ident ()->name ();
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2534 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
2535 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
2536
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2537 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2538 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
2539 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2540
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2541 std::list<cdef_class> slist;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2542
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2543 if (t->superclass_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2544 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2545 for (auto& scls : (*t->superclass_list ()))
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2546 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2547 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
2548
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2549 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2550 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
2551 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2552
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2553 cdef_class sclass = lookup_class (sclass_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2554
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2555 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
2556 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
2557 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
2558
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2559 slist.push_back (sclass);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2560 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2561 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2562
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2563 cdef_manager& cdm
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2564 = octave::__get_cdef_manager__ ("cdef_class::make_meta_class");
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2565
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2566 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
2567
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2568 // Package owning this class
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2569
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2570 if (! t->package_name ().empty ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2571 {
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
2572 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
2573
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2574 if (pack.ok ())
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2575 retval.put ("ContainingPackage", to_ov (pack));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2576 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2577
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2578 // Class attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2579
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2580 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
2581
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2582 if (t->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2583 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2584 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
2585 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2586 std::string aname = attr->ident ()->name ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2587 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
2588
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2589 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2590 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
2591 << 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
2592 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2593
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2594 retval.put (aname, avalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2595 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2596 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2597
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
2598 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
2599
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2600 if (b)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2601 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
2602 // 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
2603 // later on when creating properties.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2604
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2605 std::map<std::string, octave_value> get_methods;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2606 std::map<std::string, octave_value> set_methods;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2607
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2608 // Method blocks
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2609
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
2610 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
2611
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2612 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
2613
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2614 for (auto& mb_p : mb_list)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2615 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2616 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
2617
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2618 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2619 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
2620 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2621
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2622 // Method attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2623
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2624 if (mb_p->attribute_list ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2625 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2626 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
2627 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2628 std::string aname = attr_p->ident ()->name ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2629 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
2630
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2631 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2632 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
2633 << 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
2634 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2635 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2636
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2637 amap[aname] = avalue;
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 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2640
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2641 // Methods
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2642
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2643 if (mb_p->element_list ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2644 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2645 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
2646 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2647 std::string mname = mtd.function_value ()->name ();
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2648 std::string mprefix = mname.substr (0, 4);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2649
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2650 if (mprefix == "get.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2651 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
2652 make_fcn_handle (mtd, full_class_name + '>' + mname);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2653 else if (mprefix == "set.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2654 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
2655 make_fcn_handle (mtd, full_class_name + '>' + mname);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2656 else
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2657 {
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2658 cdef_method meth = cdm.make_method (retval, mname, mtd);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2659
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2660 #if DEBUG_TRACE
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2661 std::cerr << (mname == class_name ? "constructor"
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2662 : "method")
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2663 << ": " << mname << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2664 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2665
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2666 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
2667 meth.put (attrnm_val.first, attrnm_val.second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2668
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2669 retval.install_method (meth);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2670 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2671 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2672 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2673 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2674
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2675 if (is_at_folder)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2676 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2677 // 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
2678 // 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
2679 //
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2680 // 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
2681 // 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
2682 // 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
2683
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
2684 std::list<std::string> external_methods
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
2685 = 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
2686
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2687 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
2688 {
21578
683a1beee538 maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents: 21574
diff changeset
2689 // 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
2690 // defined in the classdef file?
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2691
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2692 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
2693 && ! 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
2694 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2695 // 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
2696 // method is loaded.
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2697 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
2698
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2699 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
2700
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2701 cdef_method meth
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2702 = 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
2703
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2704 retval.install_method (meth);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2705 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2706 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2707 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2708
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2709 // Property blocks
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2710
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2711 // 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
2712 // 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
2713 // 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
2714 // value expressions.
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2715
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
2716 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
2717 = b->properties_list ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2718
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 for (auto& pb_p : pb_list)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2720 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2721 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
2722
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2723 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2724 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
2725 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2726
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2727 // Property attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2728
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2729 if (pb_p->attribute_list ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2730 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2731 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
2732 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2733 std::string aname = attr_p->ident ()->name ();
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2734 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
2735
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2736 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2737 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
2738 << 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
2739 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2740 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2741
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2742 if (aname == "Access")
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 amap["GetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2745 amap["SetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2746 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2747 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2748 amap[aname] = avalue;
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 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2751
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2752 // Properties
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 if (pb_p->element_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 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
2757 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2758 std::string prop_name = prop_p->ident ()->name ();
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2759
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2760 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
2761
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2762 #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
2763 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
2764 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2765 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2766
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2767 octave::tree_expression *expr = prop_p->expression ();
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23345
diff changeset
2768 if (expr)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2769 {
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
2770 octave_value pvalue = tw.evaluate (expr);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2771
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2772 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2773 std::cerr << "property default: "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2774 << 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
2775 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2776 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2777
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2778 prop.put ("DefaultValue", pvalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2779 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2780
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2781 // 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
2782 // 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
2783 // cdef_property methods.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2784
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
2785 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
2786 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
2787
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
2788 // 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
2789 // 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
2790 // 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
2791 // defined property.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2792
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2793 std::map<std::string, octave_value>::iterator git =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2794 get_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2795
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2796 if (git != get_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2797 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
2798 make_function_of_class (retval, git->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2799 prop.put ("GetMethod", git->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2800 get_methods.erase (git);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2801 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2802
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2803 std::map<std::string, octave_value>::iterator sit =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2804 set_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2805
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2806 if (sit != set_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2807 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
2808 make_function_of_class (retval, sit->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2809 prop.put ("SetMethod", sit->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2810 set_methods.erase (sit);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2811 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2812
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2813 retval.install_property (prop);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2814 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2815 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2816 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2817 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2818
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2819 return retval;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2820 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2821
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2822 octave_function*
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2823 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
2824 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
2825 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
2826
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2827 return p;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2828 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2829
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2830 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
2831 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
2832 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
2833 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2834 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2835 octave_value retval;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2836
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2837 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
2838 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
2839
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2840 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2841 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2842 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
2843
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2844 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
2845 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
2846 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2847 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2848
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2849 octave_value get_fcn = get ("GetMethod");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2850
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2851 // 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
2852
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
2853 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
2854 retval = obj.get (get ("Name").string_value ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2855 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2856 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2857 octave_value_list args;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2858
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2859 args(0) = to_ov (obj);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2860
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
2861 args = octave::feval (get_fcn, args, 1);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2862
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2863 retval = args(0);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2864 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2865
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2866 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2867 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2868
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2869 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
2870 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
2871 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
2872 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2873 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
2874 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
2875
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2876 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
2877 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2878
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2879 bool
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2880 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
2881 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2882 // FIXME: implement
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2883 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2884 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2885
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2886 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2887 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
2888 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
2889 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
2890 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2891 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2892 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
2893 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
2894
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2895 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2896 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2897 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
2898
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2899 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
2900 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
2901 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2902 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2903
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2904 octave_value set_fcn = get ("SetMethod");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2905
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
2906 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
2907 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
2908 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2909 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2910 octave_value_list args;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2911
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2912 args(0) = to_ov (obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2913 args(1) = val;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2914
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
2915 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
2916
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2917 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
2918 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2919 if (args (0).is_classdef_object ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2920 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2921 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
2922
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2923 obj = new_obj;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2924 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2925 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2926 ::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
2927 get_name ().c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2928 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2929 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2930 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2931
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2932 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
2933 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
2934 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2935 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2936
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
2937 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
2938 get_name (), false);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2939
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2940 return false;
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 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
2944 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
2945 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2946 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2947
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
2948 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
2949 get_name (), true);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2950
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2951 return false;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2952 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2953
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2954 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2955 cdef_method::cdef_method_rep::check_method (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2956 {
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2957 if (is_external ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2958 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2959 if (is_dummy_method (function))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2960 {
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
2961 octave::load_path& lp
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
2962 = 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
2963
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2964 std::string name = get_name ();
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2965 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
2966 std::string pack_name;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2967
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2968 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
2969
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2970 if (pos != std::string::npos)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2971 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2972 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
2973 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
2974 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2975
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2976 std::string dir_name;
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
2977 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
2978 dir_name, pack_name);
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2979
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2980 if (! file_name.empty ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2981 {
23653
3bb0a937c071 avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents: 23652
diff changeset
2982 octave_value ov_fcn
3bb0a937c071 avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents: 23652
diff changeset
2983 = 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
2984 dispatch_type, pack_name);
3bb0a937c071 avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents: 23652
diff changeset
2985
3bb0a937c071 avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents: 23652
diff changeset
2986 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
2987 {
23653
3bb0a937c071 avoid possible memory errors when parsing function files
John W. Eaton <jwe@octave.org>
parents: 23652
diff changeset
2988 function = ov_fcn;
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2989
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2990 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
2991 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2992 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2993 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2994 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2995 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2996 // 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
2997 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2998
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2999 if (is_dummy_method (function))
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
3000 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
3001 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
3002 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3003 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3004
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3005 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3006 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
3007 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
3008 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3009 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3010 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3011
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3012 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
3013 err_method_access (who, wrap ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3014
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3015 if (get ("Abstract").bool_value ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3016 error ("%s: cannot execute abstract method",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3017 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3018
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3019 check_method ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3020
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3021 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
3022 retval = octave::feval (function, args, nargout);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3023
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3024 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3025 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3026
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3027 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3028 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
3029 const octave_value_list& args,
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3030 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
3031 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3032 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3033 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3034
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3035 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
3036 err_method_access (who, wrap ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3037
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3038 if (get ("Abstract").bool_value ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3039 error ("%s: cannot execute abstract method",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3040 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3041
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3042 check_method ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3043
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3044 if (function.is_defined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3045 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3046 octave_value_list new_args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3047
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3048 new_args.resize (args.length () + 1);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3049
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3050 new_args(0) = to_ov (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3051 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
3052 new_args(i+1) = args(i);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3053
23532
084245f9bd03 pass reference to evaluator to octave_function call methods
John W. Eaton <jwe@octave.org>
parents: 23503
diff changeset
3054 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
3055 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3056
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3057 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3058 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3059
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3060 bool
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3061 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
3062 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3063 if (function.is_function())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3064 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
3065
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3066 return false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3067 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3068
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
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_method::cdef_method_rep::check_access (void) const
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3071 {
15869
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
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3074 return ::check_access (cls, get ("Access"), get_name ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3075 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3076
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3077 octave_value_list
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3078 cdef_method::cdef_method_rep::meta_subsref
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3079 (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
3080 int nargout)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3081 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3082 octave_value_list retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3083
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3084 switch (type[0])
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3085 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3086 case '(':
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
3087 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
3088 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3089
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3090 default:
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3091 error ("invalid meta.method indexing");
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3092 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3093 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3094
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3095 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
3096 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
3097
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3098 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3099 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3100
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3101 static cdef_package
24100
4d9ceaf17dda return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
3102 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
3103 bool load_if_not_found = true)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3104 {
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3105 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
3106
24100
4d9ceaf17dda return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
3107 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
3108 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3109
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3110 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3111 package_fromName (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3112 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3113 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3114
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3115 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3116 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3117
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3118 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
3119
24100
4d9ceaf17dda return empty matrix if meta.*.fromName fails (bug #52096)
Piotr Held <pjheld@gmail.com>
parents: 23865
diff changeset
3120 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
3121
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3122 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3123 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3124
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3125 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3126 package_get_classes (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3127 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3128 octave_value_list retval (1, Matrix ());
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 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3131 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3132 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3133 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3134
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3135 retval(0) = pack.get_classes ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3136 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3137
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3138 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3139 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3140
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3141 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3142 package_get_functions (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3143 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3144 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3145
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3146 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3147 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3148 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3149 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3150
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3151 retval(0) = pack.get_functions ();
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3154 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3155 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3156
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3157 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3158 package_get_packages (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3159 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3160 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3161
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3162 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3163 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3164 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3165 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3166
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3167 retval(0) = pack.get_packages ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3168 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3169
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3170 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3171 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3172
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3173 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
3174 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
3175 const octave_value_list& /* args */, int /* nargout */)
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3176 {
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3177 std::map<std::string, cdef_package> toplevel_packages;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3178
23533
8edbc923a7dc begin refactoring use of interpreter/evaluator in classdef objects
John W. Eaton <jwe@octave.org>
parents: 23532
diff changeset
3179 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
3180
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
3181 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
3182
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3183 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
3184
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3185 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
3186
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
3187 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
3188 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
3189
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3190 Cell c (toplevel_packages.size (), 1);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3191
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3192 int i = 0;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3193
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22868
diff changeset
3194 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
3195 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
3196
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3197 return octave_value_list (octave_value (c));
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3198 }
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3199
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3200 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3201 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
3202 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3203 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3204 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
3205
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3206 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3207 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3208
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3209 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3210 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
3211 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3212 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3213 function_map[nm] = fcn;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3214 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3215
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3216 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3217 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
3218 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3219 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3220 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
3221
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3222 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3223 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3224
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
3225 template <typename T1, typename T2>
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3226 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3227 map2Cell (const std::map<T1, T2>& m)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3228 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3229 Cell retval (1, m.size ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3230 int i = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3231
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3232 for (typename std::map<T1, T2>::const_iterator it = m.begin ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3233 it != m.end (); ++it, ++i)
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 retval(i) = to_ov (it->second);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3236 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3237
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3238 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3239 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3240
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3241 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3242 cdef_package::cdef_package_rep::get_classes (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3243 { return map2Cell (class_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3244
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3245 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3246 cdef_package::cdef_package_rep::get_functions (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3247 { return map2Cell (function_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3248
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3249 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3250 cdef_package::cdef_package_rep::get_packages (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3251 { return map2Cell (package_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3252
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3253 octave_value
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3254 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
3255 {
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23693
diff changeset
3256 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
3257
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
3258 octave::symbol_table& symtab
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3259 = octave::__get_symbol_table__ ("cdef_package::cdef_package_rep::find");
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3260
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3261 return symtab.find (symbol_name, octave_value_list (), true, false);
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3262 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3263
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3264 octave_value_list
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3265 cdef_package::cdef_package_rep::meta_subsref
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3266 (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
3267 int nargout)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3268 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3269 octave_value_list retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3270
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3271 switch (type[0])
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3272 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3273 case '.':
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3274 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3275 if (idx.front ().length () != 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3276 error ("invalid meta.package indexing");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3277
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3278 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
3279
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3280 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3281 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
3282 #endif
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3283
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3284 octave_value o = find (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3285
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3286 if (! o.is_defined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3287 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
3288 nm.c_str (), get_name ().c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3289
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3290 if (o.is_function ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3291 {
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23445
diff changeset
3292 octave_function *fcn = o.function_value ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3293
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3294 // 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
3295 // 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
3296 // 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
3297 // "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
3298 // function call at this stage.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3299
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3300 if (type.size () > 1
23503
6a2fed2d39ac improve some function names
John W. Eaton <jwe@octave.org>
parents: 23502
diff changeset
3301 && ! fcn->accepts_postfix_index (type[1]))
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3302 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3303 octave_value_list tmp_args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3304
23501
1ee4b394a687 use feval instead of do_multi_index_op
John W. Eaton <jwe@octave.org>
parents: 23476
diff changeset
3305 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
3306 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3307 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3308 retval(0) = o;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3309
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3310 if (type.size () > 1 && idx.size () > 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3311 retval = retval(0).next_subsref (nargout, type,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3312 idx, 1);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3313 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3314 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
3315 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
3316 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3317 retval(0) = o;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3318 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3319 break;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3320
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3321 default:
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3322 error ("invalid meta.package indexing");
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3323 break;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3324 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3325
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3326 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3327 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3328
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3329 void
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3330 cdef_package::cdef_package_rep::meta_release (void)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3331 {
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3332 // 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
3333 // could still be referenced by classes or sub-packages?
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3334 // 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
3335 // match the one already referenced by those classes or
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3336 // sub-packages.
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3337
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3338 cdef_manager& cdm
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3339 = 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
3340
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3341 cdm.unregister_package (wrap ());
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3342 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3343
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3344 //----------------------------------------------------------------------------
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3345
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24539
diff changeset
3346 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
3347 : 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
3348 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
3349 m_meta_package (), m_meta ()
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3350 {
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24539
diff changeset
3351 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
3352
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24539
diff changeset
3353 octave_classdef::register_type (ti);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3354
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3355 // bootstrap
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3356 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
3357
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3358 m_meta_class = make_meta_class ("meta.class", tmp_handle);
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3359
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3360 tmp_handle.set_class (m_meta_class);
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3361 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
3362
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3363 // meta classes
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3364 m_meta_property = make_meta_class ("meta.property", tmp_handle);
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3365
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3366 m_meta_method = make_meta_class ("meta.method", tmp_handle);
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3367
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3368 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
3369
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3370 cdef_class tmp_meta_event
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3371 = 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
3372
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3373 cdef_class tmp_meta_dynproperty
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3374 = make_meta_class ("meta.dynamicproperty", tmp_handle);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3375
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3376 // meta.class properties
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3377 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3378 (make_attribute (m_meta_class, "Abstract"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3379
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3380 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3381 (make_attribute (m_meta_class, "ConstructOnLoad"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3382
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3383 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3384 (make_property (m_meta_class, "ContainingPackage"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3385
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3386 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3387 (make_property (m_meta_class, "Description"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3388
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3389 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3390 (make_property (m_meta_class, "DetailedDescription"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3391
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3392 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3393 (make_property (m_meta_class, "Events"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3394
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3395 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3396 (make_attribute (m_meta_class, "HandleCompatible"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3397
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3398 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3399 (make_attribute (m_meta_class, "Hidden"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3400
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3401 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3402 (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
3403 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
3404 "meta.class>get.InferiorClasses"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3405 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3406
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3407 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3408 (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
3409 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
3410 "meta.class>get.Methods"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3411 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3412
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3413 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3414 (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
3415 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
3416 "meta.class>get.MethodList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3417 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3418
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3419 m_meta_class.install_property (make_attribute (m_meta_class, "Name"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3420
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3421 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3422 (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
3423 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
3424 "meta.class>get.Properties"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3425 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3426
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3427 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3428 (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
3429 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
3430 "meta.class>get.PropertyList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3431 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3432
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3433 m_meta_class.install_property (make_attribute (m_meta_class, "Sealed"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3434
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3435 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3436 (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
3437 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
3438 "meta.class>get.SuperClasses"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3439 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3440
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3441 m_meta_class.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3442 (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
3443 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
3444 "meta.class>get.SuperClassList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3445 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3446
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3447 // meta.class methods
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3448 m_meta_class.install_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3449 (make_method (m_meta_class, "fromName", class_fromName, "public", true));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3450
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3451 m_meta_class.install_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3452 (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
3453 false));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3454
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3455 m_meta_class.install_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3456 (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
3457 false));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3458
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3459 m_meta_class.install_method (make_method (m_meta_class, "eq", class_eq));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3460 m_meta_class.install_method (make_method (m_meta_class, "ne", class_ne));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3461 m_meta_class.install_method (make_method (m_meta_class, "lt", class_lt));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3462 m_meta_class.install_method (make_method (m_meta_class, "le", class_le));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3463 m_meta_class.install_method (make_method (m_meta_class, "gt", class_gt));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3464 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
3465
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3466 // meta.method properties
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3467 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3468 (make_attribute (m_meta_method, "Abstract"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3469
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3470 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3471 (make_attribute (m_meta_method, "Access"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3472
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3473 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3474 (make_attribute (m_meta_method, "DefiningClass"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3475
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3476 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3477 (make_attribute (m_meta_method, "Description"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3478
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3479 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3480 (make_attribute (m_meta_method, "DetailedDescription"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3481
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3482 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3483 (make_attribute (m_meta_method, "Hidden"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3484
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3485 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3486 (make_attribute (m_meta_method, "Name"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3487
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3488 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3489 (make_attribute (m_meta_method, "Sealed"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3490
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3491 m_meta_method.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3492 (make_attribute (m_meta_method, "Static"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3493
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3494 // meta.property properties
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3495 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3496 (make_attribute (m_meta_property, "Name"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3497
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3498 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3499 (make_attribute (m_meta_property, "Description"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3500
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3501 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3502 (make_attribute (m_meta_property, "DetailedDescription"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3503
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3504 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3505 (make_attribute (m_meta_property, "Abstract"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3506
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3507 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3508 (make_attribute (m_meta_property, "Constant"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3509
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3510 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3511 (make_attribute (m_meta_property, "GetAccess"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3512
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3513 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3514 (make_attribute (m_meta_property, "SetAccess"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3515
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3516 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3517 (make_attribute (m_meta_property, "Dependent"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3518
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3519 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3520 (make_attribute (m_meta_property, "Transient"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3521
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3522 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3523 (make_attribute (m_meta_property, "Hidden"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3524
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3525 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3526 (make_attribute (m_meta_property, "GetObservable"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3527
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3528 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3529 (make_attribute (m_meta_property, "SetObservable"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3530
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3531 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3532 (make_attribute (m_meta_property, "GetMethod"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3533
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3534 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3535 (make_attribute (m_meta_property, "SetMethod"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3536
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3537 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3538 (make_attribute (m_meta_property, "DefiningClass"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3540 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3541 (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
3542 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
3543 "meta.property>get.DefaultValue"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3544 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3545
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3546 m_meta_property.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3547 (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
3548
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3549 // meta.property events
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3550 // FIXME: add events
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3551
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3552 // handle methods
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3553
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3554 tmp_handle.install_method
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3555 (make_method (tmp_handle, "delete", handle_delete));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3556
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3557 // meta.package properties
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3558
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3559 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3560 (make_attribute (m_meta_package, "Name"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3561
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3562 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3563 (make_property (m_meta_package, "ContainingPackage"));
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3564
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3565 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3566 (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
3567 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
3568 "meta.package>get.ClassList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3569 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3570
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3571 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3572 (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
3573 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
3574 "meta.package>get.Classes"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3575 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3576
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3577 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3578 (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
3579 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
3580 "meta.package>get.FunctionList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3581 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3582
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3583 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3584 (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
3585 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
3586 "meta.package>get.Functions"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3587 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3588
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3589 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3590 (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
3591 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
3592 "meta.package>get.PackageList"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3593 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3594
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3595 m_meta_package.install_property
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3596 (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
3597 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
3598 "meta.package>get.Packages"),
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3599 "public", Matrix (), "private"));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3600
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3601 m_meta_package.install_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3602 (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
3603 "public", true));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3604
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3605 m_meta_package.install_method
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3606 (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
3607 "public", true));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3608
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3609 // create "meta" package
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3610 cdef_package package_meta
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3611 = m_meta
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3612 = make_package ("meta");
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3613
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3614 package_meta.install_class (m_meta_class, "class");
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3615 package_meta.install_class (m_meta_property, "property");
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3616 package_meta.install_class (m_meta_method, "method");
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3617 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
3618 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
3619 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
3620
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
3621 octave::symbol_table& symtab = m_interpreter.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3622
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3623 // 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
3624 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
3625 ("meta.class",
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3626 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
3627
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3628 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
3629 ("meta.method",
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3630 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
3631
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3632 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
3633 ("meta.property",
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3634 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
3635
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3636 symtab.install_built_in_function
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3637 ("meta.package",
24539
4e2ca22b3cf9 refactor cdef_manager
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
3638 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
3639
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3640 symtab.install_built_in_function
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3641 ("meta.event",
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3642 octave_value (tmp_meta_event.get_constructor_function ()));
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3643
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3644 symtab.install_built_in_function
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3645 ("meta.dynproperty",
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3646 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
3647 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3648
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3649 cdef_class
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3650 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
3651 bool load_if_not_found)
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3652 {
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3653 std::map<std::string, cdef_class>::iterator it = m_all_classes.find (name);
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3654
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3655 if (it == m_all_classes.end ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3656 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3657 if (load_if_not_found)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3658 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3659 octave_value ov_cls;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3660
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3661 size_t pos = name.rfind ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3662
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3663 if (pos == std::string::npos)
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3664 {
23693
b9378eff6d13 move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23683
diff changeset
3665 octave::symbol_table& symtab
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3666 = octave::__get_symbol_table__ ("cdef_manager::find_class");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3667
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3668 ov_cls = symtab.find (name);
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23577
diff changeset
3669 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3670 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3671 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3672 std::string pack_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3673
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3674 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
3675
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3676 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3677 ov_cls = pack.find (name.substr (pos+1));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3678 }
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3679
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3680 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
3681 it = m_all_classes.find (name);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3682 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3683 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3684
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3685 if (it == m_all_classes.end ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3686 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3687 if (error_if_not_found)
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3688 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
3689 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3690 else
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3691 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3692 cdef_class cls = it->second;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3693
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3694 if (! cls.is_builtin ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3695 cls = lookup_class (cls);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3696
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3697 if (cls.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3698 return cls;
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3699 else
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3700 m_all_classes.erase (it);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3701 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3702
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3703 return cdef_class ();
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3704 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3705
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3706 octave_function *
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3707 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
3708 const std::string& class_name)
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3709 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
3710 octave_function *retval = nullptr;
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3711
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3712 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
3713
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3714 if (cls.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3715 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3716 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
3717
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3718 if (meth.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3719 retval = new octave_classdef_meta (meth);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3720 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3721
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3722 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3723 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3724
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3725 cdef_package
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3726 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
3727 bool load_if_not_found)
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3728 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3729 cdef_package retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3730
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3731 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
3732 = m_all_packages.find (name);
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3733
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3734 if (it != m_all_packages.end ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3735 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3736 retval = it->second;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3737
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3738 if (! retval.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3739 error ("invalid package `%s'", name.c_str ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3740 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3741 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3742 {
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
3743 octave::load_path& lp
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3744 = octave::__get_load_path__ ("cdef_manager::find_package");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
3745
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
3746 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
3747 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3748 size_t pos = name.find ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3749
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3750 if (pos == std::string::npos)
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
3751 retval = make_package (name, "");
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3752 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3753 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3754 std::string parent_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3755
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3756 retval = make_package (name, parent_name);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3757 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3758 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3759 else if (error_if_not_found)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3760 error ("unknown package `%s'", name.c_str ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3761 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3762
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3763 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3764 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3765
23651
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3766 octave_function *
5c6cceef132b don't use singleton for cdef_manager object
John W. Eaton <jwe@octave.org>
parents: 23611
diff changeset
3767 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
3768 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
3769 octave_function *retval = nullptr;
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3770
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
3771 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
3772
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3773 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3774 retval = new octave_classdef_meta (pack);
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 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3777 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3778
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3779 //----------------------------------------------------------------------------
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3780
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3781 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
3782 doc: /* -*- texinfo -*-
22299
9fc91bb2aec3 doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents: 22297
diff changeset
3783 @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
3784 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
3785 @end deftypefn */)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3786 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3787 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3788 print_usage ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3789
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3790 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
3791
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3792 return to_ov (lookup_package (cname));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3793 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3794
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3795 DEFUN (__superclass_reference__, 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
3796 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
3797 @deftypefn {} {} __superclass_reference__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3798 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
3799 @end deftypefn */)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3800 {
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
3801 return ovl (new octave_classdef_superclass_ref (args));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3802 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3803
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3804 DEFUN (__meta_class_query__, 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
3805 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
3806 @deftypefn {} {} __meta_class_query__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3807 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
3808 @end deftypefn */)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3809 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3810 #if DEBUG_TRACE
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3811 std::cerr << "__meta_class_query__ ("
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23693
diff changeset
3812 << args(0).string_value () << ')'
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3813 << std::endl;
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3814 #endif
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3815
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3816 if (args.length () != 1)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3817 print_usage ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3818
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3819 std::string cls = args(0).xstring_value ("CLASS_NAME must be a string");
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3820
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3821 return to_ov (lookup_class (cls));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3822 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3823
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3824 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
3825 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
3826 @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
3827 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
3828 @end deftypefn */)
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3829 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3830 if (args.length () != 1)
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3831 print_usage ();
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3832
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3833 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
3834
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3835 return to_ov (obj.get_class ());
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3836 }
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3837
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3838 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3839 ;;; Local Variables: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3840 ;;; mode: C++ ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3841 ;;; End: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3842 */