annotate libinterp/octave-value/ov-classdef.cc @ 22197:e43d83253e28

refill multi-line macro definitions Use the Emacs C++ mode style for line continuation markers in multi-line macro definitions. * make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc, bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h, defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h, jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h, mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h, psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h, utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc, ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h, op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc, MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h, Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc, idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc, lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h, oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc, mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h, lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc, oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Aug 2016 12:40:18 -0400
parents eb8667f2faac
children bc2a5db96754
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19641
diff changeset
3 Copyright (C) 2012-2015 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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
10 option) any later version.
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
11
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
15 for more details.
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
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"
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
31 #include "load-path.h"
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
32 #include "ov-builtin.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
33 #include "ov-classdef.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
34 #include "ov-fcn-handle.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
35 #include "ov-typeinfo.h"
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
36 #include "ov-usr-fcn.h"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
37 #include "pt-assign.h"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
38 #include "pt-classdef.h"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
39 #include "pt-funcall.h"
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
40 #include "pt-misc.h"
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
41 #include "pt-stmt.h"
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
42 #include "pt-walk.h"
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
43 #include "singleton-cleanup.h"
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
44 #include "symtab.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
45 #include "interpreter.h"
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
46
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
47 // 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
48 #define DEBUG_TRACE 0
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
49
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
50 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
51 void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21055
diff changeset
52 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
53 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
54 octave_value acc = meth.get ("Access");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
55 std::string acc_s;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
56
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
57 if (acc.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
58 acc_s = acc.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
59 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
60 acc_s = "class-restricted";
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
61
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
62 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
63 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
64 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
65
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
66 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21017
diff changeset
67 void
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21055
diff changeset
68 err_property_access (const std::string& from, const cdef_property& prop,
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
69 bool is_set = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
70 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
71 octave_value acc = prop.get (is_set ? "SetAccess" : "GetAccess");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
72 std::string acc_s;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
73
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
74 if (acc.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
75 acc_s = acc.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
76 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
77 acc_s = "class-restricted";
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
78
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
79 if (is_set)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
80 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
81 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
82 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
83 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
84 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
85 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
86
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
87 static std::string
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
88 get_base_name (const std::string& nm)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
89 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
90 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
91
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
92 if (pos != std::string::npos)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
93 return nm.substr (pos + 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
94
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
95 return nm;
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
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
98 static void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
99 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
100 const octave_value& fcn)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
101 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
102 octave_function *of = fcn.function_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
103
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
104 of->stash_dispatch_class (class_name);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
105
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
106 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
107
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
108 if (uf)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
109 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
110 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
111 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
112 uf->mark_as_class_constructor ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
113 uf->mark_as_classdef_constructor ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
114 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
115 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
116 uf->mark_as_class_method ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
117 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
118 }
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 static void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
121 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
122 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
123 make_function_of_class (cls.get_name (), fcn);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
124 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
125
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
126 static octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
127 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
128 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
129 octave_value fcn (new octave_builtin (ff, 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_handle (new octave_fcn_handle (fcn, 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 return fcn_handle;
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
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
136 static octave_value
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
137 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
138 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
139 octave_value retval;
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 if (fcn.is_defined ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
142 retval = octave_value (new octave_fcn_handle (fcn, nm));
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
143
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
144 return retval;
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
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
147 inline octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
148 execute_ov (octave_value val, const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
149 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
150 std::list<octave_value_list> idx (1, args);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
151
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
152 std::string type ("(");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
153
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
154 return val.subsref (type, idx, nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
155 }
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 static cdef_class
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
158 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
159 bool load_if_not_found = true)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
160 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
161 return cdef_manager::find_class (name, error_if_not_found,
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
162 load_if_not_found);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
163 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
164
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
165 static cdef_class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
166 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
167 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
168 // 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
169 // 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
170
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
171 return cls;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
172 }
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 static cdef_class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
175 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
176 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
177 if (ov.is_string())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
178 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
179 else
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 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
182
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
183 return lookup_class (cls);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
184 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
185
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
186 return cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
187 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
188
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
189 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
190 lookup_classes (const Cell& cls_list)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
191 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
192 std::list<cdef_class> retval;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
193
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
194 for (int i = 0; i < cls_list.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
195 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
196 cdef_class c = lookup_class (cls_list(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
197
20678
4b00afb5e9c3 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
198 retval.push_back (c);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
199 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
200
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
201 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
202 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
203
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
204 static octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
205 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
206 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
207 Cell cls (class_list.size (), 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
208 int i = 0;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
209
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
210 for (std::list<cdef_class>::const_iterator it = class_list.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
211 it != class_list.end (); ++it, ++i)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
212 cls(i) = to_ov (*it);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
213
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
214 return octave_value (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
215 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
216
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
217 static bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
218 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
219 bool allow_equal = true, int max_depth = -1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
220 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
221 bool retval = false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
222
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
223 if (allow_equal && clsa == clsb)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
224 retval = true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
225 else if (max_depth != 0)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
226 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
227 Cell c = clsb.get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
228
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
229 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
230 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
231 cdef_class cls = lookup_class (c(i));
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
232
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
233 retval = is_superclass (clsa, cls, true,
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
234 max_depth < 0 ? max_depth : max_depth-1);
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
235 }
15036
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
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
238 return retval;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
239 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
240
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
241 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
242 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
243 { return is_superclass (clsa, clsb, false); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
244
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
245 inline bool
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
246 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
247 { 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
248
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
249 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
250 class_get_properties (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
253
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
254 if (args.length () == 1 && args(0).type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
255 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
256 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
257
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
258 retval(0) = cls.get_properties ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
259 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
260
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
261 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
262 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
263
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
264 static cdef_class
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
265 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
266 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
267 cdef_class cls;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
268
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
269 octave_function* fcn = octave_call_stack::current ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
270
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
271 in_constructor = false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
272
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
273 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
274 || 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
275 || 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
276 || (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
277 && ! fcn->dispatch_class ().empty ())))
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
278 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
279 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
280
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
281 name = fcn->name ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
282 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
283 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
284
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
285 return cls;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
286 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
287
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
288 inline cdef_class
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
289 get_class_context (void)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
290 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
291 std::string dummy_string;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
292 bool dummy_bool;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
293
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
294 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
295 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
296
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
297 static bool
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
298 in_class_method (const cdef_class& cls)
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
299 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
300 cdef_class ctx = get_class_context ();
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
301
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
302 return (ctx.ok () && is_superclass (ctx, cls));
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
303 }
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
304
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
305 static bool
18305
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
306 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
307 const std::string& meth_name = "",
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
308 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
309 bool is_prop_set = false)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
310 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
311 if (acc.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
312 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
313 std::string acc_s = acc.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
314
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
315 if (acc_s == "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
316 return true;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
317
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
318 cdef_class ctx = get_class_context ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
319
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
320 // 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
321 // valid class context.
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
322
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
323 if (ctx.ok ())
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
324 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
325 if (acc_s == "private")
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
326 return (ctx == cls);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
327 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
328 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
329 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
330 // 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
331 return true;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
332 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
333 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
334 // 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
335 // 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
336 // 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
337
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
338 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
339 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
340 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
341
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
342 if (m.ok ())
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
343 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
344
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
345 return false;
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 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
348 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
349 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
350
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
351 if (p.ok ())
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
352 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
353 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
354 "SetAccess" :
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
355 "GetAccess");
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 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
358 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
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 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
363 else
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
364 panic_impossible ();
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
365 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
366
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
367 return false;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
368 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
369 else
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
370 panic_impossible ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
371 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
372 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
373 else if (acc.is_cell ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
374 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
375 Cell acc_c = acc.cell_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
376
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
377 cdef_class ctx = get_class_context ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
378
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
379 // 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
380
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
381 if (ctx.ok ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
382 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
383 if (ctx == cls)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
384 return true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
385
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
386 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
387 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
388 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
389
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
390 if (is_superclass (acc_cls, ctx))
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
391 return true;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
392 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
393 }
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 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
396 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
397 cls.get_name ().c_str ());
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
398
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
399 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
400 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
401
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
402 static bool
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
403 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
404 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
405 bool retval = false;
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 (fcn.is_defined ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
408 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
409 if (fcn.is_user_function ())
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 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
412
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
413 if (! uf || ! uf->body ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
414 retval = true;
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 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
417 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
418 retval = true;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
419
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
420 return retval;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
421 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
422
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
423 bool
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
424 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
425 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
426 octave_function* stack_fcn = octave_call_stack::current ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
427
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
428 octave_function* method_fcn = ov.function_value (true);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
429
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
430 // 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
431
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
432 if (stack_fcn && stack_fcn == method_fcn)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
433 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
434 octave_user_function* uf = method_fcn->user_function_value (true);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
435
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
436 // 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
437 // 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
438 // 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
439 // methods.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
440
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
441 if (uf)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
442 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
443 // 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
444 // 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
445 // 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
446 // is the first return value.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
447
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
448 tree_parameter_list* pl = uf->is_classdef_constructor ()
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
449 ? uf->return_list () : uf->parameter_list ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
450
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
451 if (pl && pl->size () > 0)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
452 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
453 octave_value arg0 = pl->front ()->lvalue ().value ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
454
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
455 if (arg0.is_defined () && arg0.type_name () == "object")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
456 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
457 cdef_object arg0_obj = to_cdef (arg0);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
458
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
459 return obj.is (arg0_obj);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
460 }
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 return false;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
466 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
467
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
468 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
469 class_get_methods (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
470 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
471 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
472
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
473 if (args.length () == 1 && args(0).type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
474 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
475 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
476
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
477 retval(0) = cls.get_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
478 }
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
481 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
482
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
483 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
484 class_get_superclasses (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
485 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
486 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
487
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
488 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
489 && args(0).class_name () == "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
490 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
491 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
492
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
493 Cell classes = cls.get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
494
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
495 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
496 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
497
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
498 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
499 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
500
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
501 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
502 class_get_inferiorclasses (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
503 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
504 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
505
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
506 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
507 && args(0).class_name () == "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
508 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
509 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
510
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
511 Cell classes = cls.get ("InferiorClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
512
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
513 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
514 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
515
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
516 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
517 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
518
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
519 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
520 class_fromName (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
521 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
522 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
523
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
524 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
525 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
527 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
528
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
529 retval(0) = to_ov (lookup_class (name));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
530
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
531 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
532 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
533
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
534 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
535 class_fevalStatic (const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
536 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
537 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
538 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
539
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
540 cdef_class cls (to_cdef (args(0)));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
541
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
542 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
543
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
544 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
545
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
546 if (! meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
547 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
548
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
549 if (! meth.is_static ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
550 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
551
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
552 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
553 }
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 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
556 class_getConstant (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
557 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
558 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
559
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
560 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
561 || args(0).class_name () != "meta.class")
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
562 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
563
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
564 cdef_class cls = to_cdef (args(0));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
565
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
566 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
567
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
568 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
569
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
570 if (! prop.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
571 error ("getConstant: property not found: %s",
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
572 prop_name.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
573
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
574 if (! prop.is_constant ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
575 error ("getConstant: property `%s' is not constant",
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
576 prop_name.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
577
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
578 retval(0) = prop.get_value (true, "getConstant");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
579
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
580 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
581 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
582
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
583 #define META_CLASS_CMP(OP, CLSA, CLSB, FUN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
584 static octave_value_list \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
585 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
586 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
587 octave_value_list retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
588 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
589 if (args.length () != 2 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
590 || args(0).type_name () != "object" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
591 || args(1).type_name () != "object" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
592 || args(0).class_name () != "meta.class" \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
593 || args(1).class_name () != "meta.class") \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
594 error (#OP ": invalid arguments"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
595 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
596 cdef_class clsa = to_cdef (args(0)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
597 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
598 cdef_class clsb = to_cdef (args(1)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
599 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
600 retval(0) = FUN (CLSA, CLSB); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
601 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
602 return retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22182
diff changeset
603 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
604
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
605 META_CLASS_CMP (lt, clsb, clsa, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
606 META_CLASS_CMP (le, clsb, clsa, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
607 META_CLASS_CMP (gt, clsa, clsb, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
608 META_CLASS_CMP (ge, clsa, clsb, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
609 META_CLASS_CMP (eq, clsa, clsb, operator==)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
610 META_CLASS_CMP (ne, clsa, clsb, operator!=)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
611
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
612 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
613 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
614 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
615 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
616
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
617 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
618 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
619 cdef_property prop (to_cdef (args(0)));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
620
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
621 retval(0) = prop.get ("DefaultValue");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
622
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
623 if (! retval(0).is_defined ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
624 error_with_id ("Octave:class:NotDefaultDefined",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
625 "no default value for property `%s'",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
626 prop.get_name ().c_str ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
627 }
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 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
630 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
631
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
632 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
633 handle_delete (const octave_value_list& /* args */, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
634 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
635 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
636
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
637 // FIXME: implement this
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
638
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
639 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
640 }
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 static cdef_class
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
643 make_class (const std::string& name,
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
644 const std::list<cdef_class>& super_list = std::list<cdef_class> ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
645 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
646 cdef_class cls (name, super_list);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
647
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
648 cls.set_class (cdef_class::meta_class ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
649 cls.put ("Abstract", false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
650 cls.put ("ConstructOnLoad", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
651 cls.put ("ContainingPackage", Matrix ());
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
652 cls.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
653 cls.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
654 cls.put ("Events", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
655 cls.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
656 cls.put ("InferiorClasses", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
657 cls.put ("Methods", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
658 cls.put ("Properties", Cell ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
659 cls.put ("Sealed", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
660
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
661 if (name == "handle")
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 cls.put ("HandleCompatible", true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
664 cls.mark_as_handle_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
665 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
666 else if (super_list.empty ())
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 cls.put ("HandleCompatible", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
669 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
670 else
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
671 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
672 bool all_handle_compatible = true;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
673 bool has_handle_class = false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
674
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
675 for (std::list<cdef_class>::const_iterator it = super_list.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
676 it != super_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
677 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
678 all_handle_compatible = all_handle_compatible
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
679 && it->get ("HandleCompatible").bool_value ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
680 has_handle_class = has_handle_class || it->is_handle_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
681 }
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 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
684 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
685 name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
686
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
687 cls.put ("HandleCompatible", all_handle_compatible);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
688 if (has_handle_class)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
689 cls.mark_as_handle_class ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
690 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
691
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
692 if (! name.empty ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
693 cdef_manager::register_class (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
694
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
695 return cls;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
696 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
697
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
698 static cdef_class
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
699 make_class (const std::string& name, const cdef_class& super)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
700 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
701 return make_class (name, std::list<cdef_class> (1, super));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
702 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
703
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
704 static cdef_class
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
705 make_meta_class (const std::string& name, const cdef_class& super)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
706 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
707 cdef_class cls = make_class (name, super);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
708
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
709 cls.put ("Sealed", true);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
710 cls.mark_as_meta_class ();
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 return cls;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
713 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
714
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
715 static cdef_property
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
716 make_property (const cdef_class& cls, const std::string& name,
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
717 const octave_value& get_method = Matrix (),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
718 const std::string& get_access = "public",
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
719 const octave_value& set_method = Matrix (),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
720 const std::string& set_access = "public")
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
721 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
722 cdef_property prop (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
723
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
724 prop.set_class (cdef_class::meta_property ());
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
725 prop.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
726 prop.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
727 prop.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
728 prop.put ("Constant", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
729 prop.put ("GetAccess", get_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
730 prop.put ("SetAccess", set_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
731 prop.put ("Dependent", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
732 prop.put ("Transient", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
733 prop.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
734 prop.put ("GetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
735 prop.put ("SetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
736 prop.put ("GetMethod", get_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
737 prop.put ("SetMethod", set_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
738 prop.put ("DefiningClass", to_ov (cls));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
739 prop.put ("DefaultValue", octave_value ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
740 prop.put ("HasDefault", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
741
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
742 std::string class_name = cls.get_name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
743
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
744 if (! get_method.is_empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
745 make_function_of_class (class_name, get_method);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
746 if (! set_method.is_empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
747 make_function_of_class (class_name, set_method);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
748
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
749 return prop;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
750 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
751
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
752 inline cdef_property
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
753 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
754 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
755 return make_property (cls, name, Matrix (), "public", Matrix (), "private");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
756 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
757
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
758 static cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
759 make_method (const cdef_class& cls, const std::string& name,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
760 const octave_value& fcn,const std::string& m_access = "public",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
761 bool is_static = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
762 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
763 cdef_method meth (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
764
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
765 meth.set_class (cdef_class::meta_method ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
766 meth.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
767 meth.put ("Access", m_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
768 meth.put ("DefiningClass", to_ov (cls));
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
769 meth.put ("Description", "");
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
770 meth.put ("DetailedDescription", "");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
771 meth.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
772 meth.put ("Sealed", true);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
773 meth.put ("Static", is_static);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
774
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
775 if (fcn.is_defined ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
776 make_function_of_class (cls, fcn);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
777
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
778 meth.set_function (fcn);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
779
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
780 if (is_dummy_method (fcn))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
781 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
782
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
783 return meth;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
785
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
786 inline cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
787 make_method (const cdef_class& cls, const std::string& name,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
788 octave_builtin::fcn ff, const std::string& m_access = "public",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
789 bool is_static = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
791 octave_value fcn (new octave_builtin (ff, name));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
792
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
793 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
794 }
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 static cdef_package
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
797 make_package (const std::string& nm,
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
798 const std::string& parent = "")
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
799 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
800 cdef_package pack (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
801
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
802 pack.set_class (cdef_class::meta_package ());
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
803 if (parent.empty ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
804 pack.put ("ContainingPackage", Matrix ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
805 else
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
806 pack.put ("ContainingPackage", to_ov (cdef_manager::find_package (parent)));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
807
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
808 if (! nm.empty ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
809 cdef_manager::register_package (pack);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
810
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
811 return pack;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
812 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
813
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
814 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
815
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
816 int octave_classdef::t_id (-1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
817
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
818 const std::string octave_classdef::t_name ("object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
819
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
820 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
821 octave_classdef::register_type (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
822 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
823 t_id = octave_value_typeinfo::register_type
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
824 (octave_classdef::t_name, "<unknown>",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
825 octave_value (new octave_classdef ()));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
826 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
827
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
828 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
829 octave_classdef::subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
830 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
831 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
832 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
833 size_t skip = 0;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
834 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
835
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
836 cdef_class cls = object.get_class ();
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
837
18316
ff311e5ff6d8 Don't call classdef-overloaded subsref from builtin calls.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18314
diff changeset
838 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
839 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
840 cdef_method meth = cls.find_method ("subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
841
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
842 if (meth.ok ())
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
843 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
844 octave_value_list args;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
845
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
846 args(1) = make_idx_args (type, idx, "subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
847
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
848 count++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
849 args(0) = octave_value (this);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
850
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
851 retval = meth.execute (args, nargout, true, "subsref");
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
852
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
853 return retval;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
854 }
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
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
857 // 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
858
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
859 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
860
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
861 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
862 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
863
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
864 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
865 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
866
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
867 octave_value
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
868 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
869 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
870 bool auto_add)
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
871 {
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
872 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
873 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
874
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
875 // 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
876 // 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
877 // 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
878 // 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
879
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
880 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
881
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
882 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
883 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
884
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
885 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
886 }
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
887
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
888 octave_value
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
889 octave_classdef::subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
890 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
891 const octave_value& rhs)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
892 {
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
893 octave_value retval;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
894
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
895 cdef_class cls = object.get_class ();
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
896
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
897 if (! in_class_method (cls) && ! called_from_builtin ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
898 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
899 cdef_method meth = cls.find_method ("subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
900
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
901 if (meth.ok ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
902 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
903 octave_value_list args;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
904
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
905 args(1) = make_idx_args (type, idx, "subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
906
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
907 count++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
908 args(0) = octave_value (this);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
909 args(2) = rhs;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
910
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
911 octave_value_list retlist;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
912
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
913 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
914
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21751
diff changeset
915 if (retlist.empty ())
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
916 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
917
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
918 retval = retlist(0);
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
919 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
920 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
921
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
922 if (! retval.is_defined ())
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
923 retval = object.subsasgn (type, idx, rhs);
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
924
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
925 return retval;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
926 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
927
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
928 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
929 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
930 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
931 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
932 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
933 if (type.length () == 1 && type[0] == '(')
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
934 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
935 object = object.make_array ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
936
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
937 return subsasgn (type, idx, rhs);
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
938 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
939 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
940 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
941
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
942 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
943 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
944
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
945 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
946 octave_classdef::print (std::ostream& os, bool)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
947 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
948 if (! called_from_builtin ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
949 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
950 cdef_method meth = object.get_class ().find_method ("disp");
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
951
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
952 if (meth.ok ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
953 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
954 octave_value_list args;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
955
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
956 count++;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
957 args(0) = octave_value (this);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
958
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
959 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
960 meth.execute (args, 0, true, "disp");
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 return;
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
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
966 print_raw (os);
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
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
969 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
970 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
971 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
972 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
973 os << "<object ";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
974 if (object.is_array ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
975 os << "array ";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
976 os << class_name () << ">";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
977 newline (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
978 }
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 bool
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
981 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
982 const std::string& name) const
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
983 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
984 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
985 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
986
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
987 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
988 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
989 bool print_padding)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
990 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
991 cdef_method meth = object.get_class ().find_method ("display");
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
992
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
993 if (meth.ok ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
994 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
995 octave_value_list args;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
996
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
997 count++;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
998 args(0) = octave_value (this);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
999
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1000 string_vector arg_names (1);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1001
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1002 arg_names[0] = name;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1003 args.stash_name_tags (arg_names);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1004
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1005 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1006 meth.execute (args, 0, true, "display");
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1007 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1008 else
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1009 octave_base_value::print_with_name (os, name, print_padding);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1010 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1011
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1012 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1013 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
1014 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1015 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
1016
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1017 if (cls.ok ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1018 return is_superclass (cls, object.get_class ());
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1019
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1020 return false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1021 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19031
diff changeset
1022
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1023 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1024
15986
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1025 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
1026 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1027 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
1028 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
1029 : 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
1030
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1031 ~octave_classdef_meta (void)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1032 { object.meta_release (); }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1033
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1034 octave_function* function_value (bool = false) { return this; }
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1035
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1036 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1037 subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1038 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1039 int nargout)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1040 { return object.meta_subsref (type, idx, nargout); }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1041
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1042 octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1043 subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1044 const std::list<octave_value_list>& idx)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1045 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1046 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1047
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1048 retval = subsref (type, idx, 1);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1049
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1050 return (retval.length () > 0 ? retval(0) : octave_value ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1051 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1052
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1053 octave_value_list
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1054 do_multi_index_op (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
1055 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1056 // Emulate ()-type meta subsref
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 std::list<octave_value_list> l (1, idx);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1059 std::string type ("(");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1060
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1061 return subsref (type, l, nargout);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1062 }
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1063
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1064 bool is_postfix_index_handled (char type) const
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1065 { return object.meta_is_postfix_index_handled (type); }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1066
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1067 bool
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
1068 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
1069 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1070 bool retval = false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1071
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1072 if (object.is_class ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1073 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1074 if (cname.empty ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1075 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1076 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1077 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1078 cdef_class cls (object);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1079
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1080 if (cls.get_name () == cname)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1081 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1082 }
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
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1085 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1086 }
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1087
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1088 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
1089 cdef_meta_object object;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1090 };
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1091
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1092 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1093
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1094 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
1095 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1096 public:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1097 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
1098 : octave_function (), args (a) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1099
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1100 ~octave_classdef_superclass_ref (void) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1101
18355
9ca314e79956 Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18316
diff changeset
1102 octave_function* function_value (bool = false) { return this; }
9ca314e79956 Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18316
diff changeset
1103
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1104 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1105 subsref (const std::string& type,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1106 const std::list<octave_value_list>& idx,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1107 int nargout)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1108 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1109 size_t skip = 0;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1110 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1111
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1112 switch (type[0])
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1113 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1114 case '(':
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1115 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1116 retval = do_multi_index_op (type.length () > 1 ? 1 : nargout,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1117 idx.front ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1118 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1119 default:
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1120 retval = do_multi_index_op (1, octave_value_list ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1121 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1122 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1123
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1124 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
1125 && retval.length () > 0)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1126 retval = retval(0).next_subsref (nargout, type, idx, skip);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1127
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1128 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1129 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1130
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1131 octave_value
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1132 subsref (const std::string& type,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1133 const std::list<octave_value_list>& idx)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1134 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1135 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1136
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1137 retval = subsref (type, idx, 1);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1138
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1139 return (retval.length () > 0 ? retval(0) : octave_value ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1140 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1141
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1142 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1143 do_multi_index_op (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
1144 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1145 octave_value_list retval;
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 std::string meth_name;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1148 bool in_constructor;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1149 cdef_class ctx;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1150
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1151 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
1152
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1153 if (! ctx.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1154 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
1155
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1156 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
1157 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
1158
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1159 cdef_class cls = lookup_class (cname);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1160
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1161 if (in_constructor)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1162 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1163 if (! is_direct_superclass (cls, ctx))
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1164 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
1165 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
1166
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1167 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
1168 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
1169 mname.c_str ());
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1170
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1171 octave_value sym = symbol_table::varval (mname);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1172
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1173 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
1174
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1175 retval(0) = sym;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1176 }
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1177 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1178 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1179 if (mname != meth_name)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1180 error ("method name mismatch (`%s' != `%s')",
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1181 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
1182
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1183 if (! is_strict_superclass (cls, ctx))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1184 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
1185 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
1186
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1187 // I see 2 possible implementations here:
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1188 // 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
1189 // context; this avoids duplicating code, but
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1190 // 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
1191 // 2) lookup the method manually and call
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1192 // cdef_method::execute; this duplicates part of
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1193 // 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
1194 // assumption of 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1195 // 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
1196 // 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
1197
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1198 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
1199
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1200 if (! meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1201 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
1202 meth_name.c_str (), cname.c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1203
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1204 retval = meth.execute (idx, nargout, true,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1205 meth_name);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1206 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1207
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1208 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1209 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1210
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1211 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1212 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
1213 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1214 octave_function *of = octave_call_stack::current ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1215
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1216 if (of->is_classdef_constructor ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1217 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1218 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
1219
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1220 if (uf)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1221 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1222 tree_parameter_list *ret_list = uf->return_list ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1223
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1224 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
1225 return (ret_list->front ()->name () == nm);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1226 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1227 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1228
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1229 return false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1230 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1231
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1232 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1233 octave_value_list args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1234 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1235
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1236 //----------------------------------------------------------------------------
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1237
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1238 octave_map
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1239 cdef_object::map_value (void) const
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1240 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1241 octave_map retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1242
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1243 warning_with_id ("Octave:classdef-to-struct",
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1244 "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
1245 "overrides the access restrictions defined for properties. "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1246 "All properties are returned, including private and "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1247 "protected ones.");
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1248
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1249 cdef_class cls = get_class ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1250
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1251 if (cls.ok ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1252 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1253 std::map<std::string, cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1254
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1255 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
1256
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1257 for (std::map<std::string, cdef_property>::iterator it = props.begin ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1258 it != props.end (); ++it)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1259 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1260 if (is_array ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1261 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1262 Array<cdef_object> a_obj = array_value ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1263
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1264 Cell cvalue (a_obj.dims ());
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1265
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1266 for (octave_idx_type i = 0; i < a_obj.numel (); i++)
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1267 cvalue (i) = it->second.get_value (a_obj(i), false);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1268
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1269 retval.setfield (it->first, cvalue);
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1270 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1271 else
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1272 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1273 Cell cvalue (dim_vector (1, 1),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1274 it->second.get_value (*this, false));
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1275
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1276 retval.setfield (it->first, cvalue);
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1277 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1278 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1279 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1280
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1281 return retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1282 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
1283
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1284 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1285 cdef_object_rep::map_keys (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1286 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1287 cdef_class cls = get_class ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1288
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1289 if (cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1290 return cls.get_names ();
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
1291
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1292 return string_vector ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1293 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1294
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1295 octave_value_list
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1296 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
1297 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
1298 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
1299 const cdef_class& context, bool auto_add)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1300 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1301 skip = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1302
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1303 cdef_class cls = (context.ok () ? context : get_class ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1304
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1305 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1306
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1307 if (! cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1308 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1309
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1310 switch (type[0])
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1311 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1312 case '.':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1313 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1314 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
1315
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1316 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
1317
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1318 if (meth.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1319 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1320 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
1321
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1322 octave_value_list args;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1323
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1324 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1325
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1326 if (type.length () > 1 && type[1] == '(')
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1327 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1328 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
1329
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1330 args = *++it;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1331
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1332 skip++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1333 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1334
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1335 if (meth.is_static ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1336 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
1337 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1338 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1339 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1340 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
1341 true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1342 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1343 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1344
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1345 if (skip == 0)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1346 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1347 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
1348
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1349 if (! prop.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1350 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
1351
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1352 if (prop.is_constant ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1353 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
1354 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1355 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1356 refcount++;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1357 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
1358 true, "subsref");
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1359 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1360
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1361 skip = 1;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1362 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1363 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1364 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1365
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1366 case '(':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1367 {
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1368 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
1369
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1370 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1371 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1372
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1373 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
1374 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1375 skip++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1376 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
1377 }
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1378 else
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1379 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1380 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
1381
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1382 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
1383
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1384 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
1385
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1386 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
1387 }
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1388 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1389 break;
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1390
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1391 default:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1392 error ("object cannot be indexed with `%c'", type[0]);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1393 break;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1394 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1395
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1396 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1397 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1398
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1399 octave_value
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1400 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
1401 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
1402 const octave_value& rhs)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1403 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1404 octave_value retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1405
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1406 cdef_class cls = get_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1407
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1408 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1409 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1410 case '.':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1411 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1412 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
1413
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1414 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
1415
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1416 if (! prop.ok ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1417 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
1418
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1419 if (prop.is_constant ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1420 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
1421 name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1422
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1423 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1424
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1425 cdef_object obj (this);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1426
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1427 if (type.length () == 1)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1428 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1429 prop.set_value (obj, rhs, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1430
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1431 retval = to_ov (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1432 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
1433 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1434 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1435 octave_value val =
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1436 prop.get_value (obj, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1437
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1438 std::list<octave_value_list> args (idx);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1439
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1440 args.erase (args.begin ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1441
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1442 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
1443 type.substr (1), args, rhs);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1444
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1445 if (val.class_name () != "object"
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1446 || ! to_cdef (val).is_handle_object ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1447 prop.set_value (obj, val, true, "subsasgn");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1448
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1449 retval = to_ov (obj);
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1450 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1451 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1452 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1453
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1454 case '(':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1455 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1456 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1457
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1458 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1459
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1460 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
1461
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1462 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
1463
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1464 new_obj.set_class (get_class ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1465
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1466 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
1467
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1468 retval = tmp;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1469 }
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1470 break;
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1471
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1472 default:
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1473 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
1474 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1475 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1476
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1477 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1478 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1479
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1480 void
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1481 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
1482 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1483 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
1484
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1485 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
1486
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1487 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
1488
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1489 ctor_list[cls] = supcls_list;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1490 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1491
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1492 octave_value_list
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1493 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
1494 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1495 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
1496 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
1497 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1498 octave_value_list retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1499
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1500 skip = 1;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1501
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1502 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1503 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1504 case '(':
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1505 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1506 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
1507
20125
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1508 if (ival.empty ())
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1509 {
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1510 refcount++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1511 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
1512 break;
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1513 }
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20052
diff changeset
1514
20189
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20125
diff changeset
1515 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
1516 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
1517
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1518 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
1519 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1520 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1521 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1522 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
1523 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1524 catch (index_exception& e)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1525 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1526 // 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
1527 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
1528 throw;
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1529 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1530
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1531 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
1532 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1533
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1534 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
1535
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1536 // 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
1537 // 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
1538 // invalid cdef_objects.
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1539
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1540 if (auto_add)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1541 fill_empty_values (ires);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1542
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1543 if (is_scalar)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1544 retval(0) = to_ov (ires(0));
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1545 else
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1546 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1547 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
1548
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1549 array_obj.set_class (get_class ());
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1550
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1551 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
1552 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1553 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1554 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1555
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1556 case '.':
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1557 if (type.size () == 1 && idx.size () == 1)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1558 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1559 Cell c (dims ());
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1560
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1561 octave_idx_type n = array.numel ();
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1562
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1563 // dummy variables
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1564 size_t dummy_skip;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1565 cdef_class dummy_cls;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1566
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1567 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
1568 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1569 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
1570 dummy_cls);
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1571
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1572 if (r.length () > 0)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1573 c(i) = r(0);
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1574 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1575
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1576 retval(0) = octave_value (c, true);
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1577
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1578 break;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1579 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1580 // fall through "default"
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1581
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1582 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
1583 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
1584 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1585 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1586 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1587
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1588 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1589 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1590
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1591 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1592 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
1593 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1594 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1595 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1596 octave_value retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1597
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1598 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1599 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1600 case '(':
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1601 if (type.length () == 1)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1602 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1603 cdef_object rhs_obj = to_cdef (rhs);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1604
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1605 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
1606 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
1607 rhs_obj.class_name ().c_str (),
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1608 class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1609
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1610 const octave_value_list& ival = idx.front ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1611 bool is_scalar = true;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1612 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
1613
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1614 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
1615 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1616 try
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1617 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1618 iv(i) = ival(i).index_vector ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1619 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1620 catch (index_exception& e)
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1621 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1622 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
1623 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
1624 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1625
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1626 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
1627 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1628
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1629 Array<cdef_object> rhs_mat;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1630
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1631 if (! rhs_obj.is_array ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1632 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1633 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
1634 rhs_mat(0) = rhs_obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1635 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1636 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1637 rhs_mat = rhs_obj.array_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1638
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1639 octave_idx_type n = array.numel ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1640
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1641 array.assign (iv, rhs_mat, cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1642
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1643 if (array.numel () > n)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1644 fill_empty_values ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1645
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1646 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1647 retval = to_ov (cdef_object (this));
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1648 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1649 else
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1650 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1651 const octave_value_list& ival = idx.front ();
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1652
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1653 bool is_scalar = true;
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1654
22182
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1655 Array<idx_vector> iv (dim_vector (1, std::max (ival.length (), 2)));
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1656
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1657 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
1658 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1659 try
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1660 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1661 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
1662 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1663 catch (index_exception& e)
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1664 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20488
diff changeset
1665 // 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
1666 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
1667 throw;
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1668 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1669
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1670 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
1671
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1672 if (! is_scalar)
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21040
diff changeset
1673 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
1674 ", 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
1675 "array.");
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1676 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1677
22182
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1678 // Fill in trailing singleton dimensions so that
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1679 // array.index doesn't create a new blank entry (bug #46660).
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1680 for (int i = ival.length (); i < 2; i++)
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1681 iv(i) = 1;
eb8667f2faac Fix assignment to an property of an element of classdef array (bug #46660)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 22094
diff changeset
1682
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1683 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
1684
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1685 if (a.numel () != 1)
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21040
diff changeset
1686 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
1687
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1688 cdef_object obj = a(0);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1689
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1690 int ignore_copies = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1691
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1692 // 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
1693 // 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
1694
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1695 if (! obj.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1696 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
1697 else
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1698 // 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
1699 // that we can safely ignore:
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1700 // - 1 in "array"
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1701 // - 1 in "a"
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1702 ignore_copies = 2;
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 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
1705
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1706 next_idx.erase (next_idx.begin ());
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1707
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1708 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
1709 rhs, ignore_copies);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1710
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1711 cdef_object robj = to_cdef (tmp);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1712
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1713 if (! robj.ok ()
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1714 || robj.is_array ()
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1715 || 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
1716 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
1717 class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1718
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1719 // Small optimization, when dealing with handle
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1720 // 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
1721 // of subsasgn back into the array.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1722
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1723 if (! robj.is (a(0)))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1724 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1725 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
1726 robj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1727
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1728 octave_idx_type n = array.numel ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1729
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1730 array.assign (iv, rhs_a);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1731
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1732 if (array.numel () > n)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1733 fill_empty_values ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1734 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1735
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1736 refcount++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1737
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1738 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
1739 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1740 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1741
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1742 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
1743 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
1744 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1745 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1746 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1747
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1748 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1749 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1750
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1751 void
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1752 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
1753 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1754 cdef_class cls = get_class ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1755
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1756 cdef_object obj;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1757
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1758 int n = arr.numel ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1759
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1760 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
1761 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1762 if (! arr.xelem (i).ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1763 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1764 if (! obj.ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1765 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1766 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
1767
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1768 arr.xelem (i) = obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1769 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1770 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1771 arr.xelem (i) = obj.copy ();
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1772 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1773 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1774 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
1775
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1776 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1777 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
1778 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1779 return (is_constructed ()
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1780 || 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
1781 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1782
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1783 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1784 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
1785 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1786 std::map< cdef_class, std::list<cdef_class> >::const_iterator it;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1787
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1788 if (is_constructed ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1789 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1790 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
1791 || it->second.empty ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1792 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1793
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1794 for (std::list<cdef_class>::const_iterator lit = it->second.begin ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1795 lit != it->second.end (); ++lit)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1796 if (! is_constructed_for (*lit))
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1797 return false;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1798
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1799 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1800 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1801
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20912
diff changeset
1802 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
1803 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
1804 {
9851a296cf87 Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20181
diff changeset
1805 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
1806 }
9851a296cf87 Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20181
diff changeset
1807
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1808 handle_cdef_object::~handle_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1809 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1810 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1811 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
1812 << " object (handle)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1813 #endif
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1814 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1815
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1816 value_cdef_object::~value_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1817 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1818 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1819 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
1820 << " object (value)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
1821 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1822 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1823
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1824 cdef_class::cdef_class_rep::cdef_class_rep (const std::list<cdef_class>&
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1825 superclasses)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1826 : cdef_meta_object_rep (), member_count (0), handle_class (false),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1827 object_count (0), meta (false)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1828 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1829 put ("SuperClasses", to_ov (superclasses));
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1830 implicit_ctor_list = superclasses;
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1831 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1832
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1833 cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1834 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
1835 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1836 method_iterator it = method_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1837
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1838 if (it == method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1839 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1840 // FIXME: look into class directory
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1841 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1842 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1843 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1844 cdef_method& meth = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1845
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1846 // FIXME: check if method reload needed
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1847
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1848 if (meth.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
1849 return meth;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1850 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1851
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1852 if (! local)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1853 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1854 // Look into superclasses
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1855
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1856 Cell super_classes = get ("SuperClasses").cell_value ();
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1857
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1858 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
1859 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1860 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1861
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1862 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
1863
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1864 if (meth.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1865 return meth;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1866 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1867 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1868
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1869 return cdef_method ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1870 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1871
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1872 class ctor_analyzer : public tree_walker
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1873 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1874 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1875 ctor_analyzer (const std::string& ctor, const std::string& obj)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1876 : tree_walker (), who (ctor), obj_name (obj) { }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1877
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1878 void visit_statement_list (tree_statement_list& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1879 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1880 for (tree_statement_list::const_iterator it = t.begin ();
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1881 it != t.end (); ++it)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1882 (*it)->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1883 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1884
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1885 void visit_statement (tree_statement& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1886 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1887 if (t.is_expression ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1888 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1889 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1890
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1891 void visit_simple_assignment (tree_simple_assignment& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1892 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1893 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1894 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1895
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1896 void visit_multi_assignment (tree_multi_assignment& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1897 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1898 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1899 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1900
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1901 void visit_index_expression (tree_index_expression& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1902 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1903 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1904 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1905
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1906 void visit_funcall (tree_funcall& t)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1907 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1908 octave_value fcn = t.function ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1909
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1910 if (fcn.is_function ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1911 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1912 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
1913
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1914 if (of)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1915 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1916 if (of->name () == "__superclass_reference__")
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1917 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1918 octave_value_list args = t.arguments ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1919
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1920 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
1921 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1922 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
1923
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1924 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
1925
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1926 if (cls.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1927 ctor_list.push_back (cls);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1928 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1929 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1930 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1931 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1932 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1933
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1934 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
1935 { return ctor_list; }
15896
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 // NO-OP
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1938 void visit_anon_fcn_handle (tree_anon_fcn_handle&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1939 void visit_argument_list (tree_argument_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1940 void visit_binary_expression (tree_binary_expression&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1941 void visit_break_command (tree_break_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1942 void visit_colon_expression (tree_colon_expression&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1943 void visit_continue_command (tree_continue_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1944 void visit_global_command (tree_global_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1945 void visit_persistent_command (tree_persistent_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1946 void visit_decl_elt (tree_decl_elt&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1947 void visit_decl_init_list (tree_decl_init_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1948 void visit_simple_for_command (tree_simple_for_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1949 void visit_complex_for_command (tree_complex_for_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1950 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
1951 void visit_octave_user_function (octave_user_function&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1952 void visit_function_def (tree_function_def&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1953 void visit_identifier (tree_identifier&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1954 void visit_if_clause (tree_if_clause&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1955 void visit_if_command (tree_if_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1956 void visit_if_command_list (tree_if_command_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1957 void visit_switch_case (tree_switch_case&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1958 void visit_switch_case_list (tree_switch_case_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1959 void visit_switch_command (tree_switch_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1960 void visit_matrix (tree_matrix&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1961 void visit_cell (tree_cell&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1962 void visit_no_op_command (tree_no_op_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1963 void visit_constant (tree_constant&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1964 void visit_fcn_handle (tree_fcn_handle&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1965 void visit_parameter_list (tree_parameter_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1966 void visit_postfix_expression (tree_postfix_expression&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1967 void visit_prefix_expression (tree_prefix_expression&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1968 void visit_return_command (tree_return_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1969 void visit_return_list (tree_return_list&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1970 void visit_try_catch_command (tree_try_catch_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1971 void visit_unwind_protect_command (tree_unwind_protect_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1972 void visit_while_command (tree_while_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1973 void visit_do_until_command (tree_do_until_command&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1974
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1975 private:
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1976 // 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
1977 std::string who;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1978
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1979 // 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
1980 std::string obj_name;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1981
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
1982 // 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
1983 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
1984 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1985
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1986 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1987 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
1988 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1989 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
1990
15911
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
1991 member_count++;
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
1992
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1993 if (meth.is_constructor ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1994 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1995 // 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
1996 // constructors are called explicitly.
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1997
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1998 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
1999
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2000 if (of)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2001 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2002 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
2003
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2004 if (uf)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2005 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2006 tree_parameter_list *ret_list = uf->return_list ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2007 tree_statement_list *body = uf->body ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2008
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2009 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
2010 error ("%s: invalid constructor output arguments",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
2011 meth.get_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2012
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2013 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
2014 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
2015
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2016 body->accept (a);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2017
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2018 std::list<cdef_class> explicit_ctor_list
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2019 = a.get_constructor_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2020
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2021 for (std::list<cdef_class>::const_iterator
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2022 it = explicit_ctor_list.begin ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2023 it != explicit_ctor_list.end ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2024 ++it)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2025 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2026 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2027 std::cerr << "explicit superclass constructor: "
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2028 << it->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
2029 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2030
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2031 implicit_ctor_list.remove (*it);
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2032 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2033 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2034 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2035 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2036 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2037
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2038 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2039 cdef_class::cdef_class_rep::load_all_methods (void)
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 // FIXME: re-scan class directory
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2044 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2045 cdef_class::cdef_class_rep::get_methods (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2046 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2047 std::map<std::string,cdef_method> meths;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2048
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2049 find_methods (meths, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2050
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2051 Cell c (meths.size (), 1);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2052
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2053 int idx = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2054
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2055 for (std::map<std::string,cdef_method>::const_iterator
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2056 it = meths.begin (); it != meths.end (); ++it, ++idx)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2057 c (idx, 0) = to_ov (it->second);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2058
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2059 return c;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2060 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2061
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2062 void
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2063 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
2064 cdef_method>& meths,
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2065 bool only_inherited)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2066 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2067 load_all_methods ();
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 method_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2070
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2071 for (it = method_map.begin (); it != method_map.end (); ++it)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2072 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2073 if (! it->second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2074 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2075 std::string nm = it->second.get_name ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2076
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2077 if (meths.find (nm) == meths.end ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2078 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2079 if (only_inherited)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2080 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2081 octave_value acc = it->second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2082
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2083 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2084 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2085 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2086 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2087
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2088 meths[nm] = it->second;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2089 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2090 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2091 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2092
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2093 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2094
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2095 Cell super_classes = get ("SuperClasses").cell_value ();
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 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2098 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2099 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2100
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2101 cls.get_rep ()->find_methods (meths, true);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2102 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2103 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2104
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2105 cdef_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2106 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
2107 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2108 property_iterator it = property_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2109
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2110 if (it != property_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2111 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2112 cdef_property& prop = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2113
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2114 if (prop.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2115 return prop;
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2118 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2119
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2120 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2121
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2122 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2123 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2124 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2125
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2126 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
2127
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2128 if (prop.ok ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2129 return prop;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2130 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2131
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2132 return cdef_property ();
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2135 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2136 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
2137 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2138 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
2139
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
2140 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2141 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2142
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2143 Cell
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2144 cdef_class::cdef_class_rep::get_properties (int mode)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2145 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2146 std::map<std::string,cdef_property> props;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2147
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2148 props = get_property_map (mode);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2149
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2150 Cell c (props.size (), 1);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2151
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2152 int idx = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2153
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2154 for (std::map<std::string,cdef_property>::const_iterator
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2155 it = props.begin (); it != props.end (); ++it, ++idx)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2156 c (idx, 0) = to_ov (it->second);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2157
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2158 return c;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2159 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2160
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2161 std::map<std::string, cdef_property>
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2162 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
2163 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2164 std::map<std::string,cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2165
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2166 find_properties (props, mode);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2167
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2168 return props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2169 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2170
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2171 void
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2172 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
2173 cdef_property>& props,
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2174 int mode)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2175 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2176 property_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2177
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2178 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
2179 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2180 std::string nm = it->second.get_name ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2181
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2182 if (props.find (nm) == props.end ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2183 {
19184
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19103
diff changeset
2184 if (mode == property_inherited)
15869
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 octave_value acc = it->second.get ("GetAccess");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2187
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2188 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2189 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2190 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2191 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2192
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2193 props[nm] = it->second;
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2194 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2195 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2196
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2197 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2198
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2199 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2200
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2201 for (int i = 0; i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2202 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2203 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2204
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2205 cls.get_rep ()->find_properties (props,
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2206 (mode == property_all
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2207 ? property_all
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2208 : property_inherited));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2209 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2210 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2211
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2212 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2213 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
2214 bool all)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2215 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2216 load_all_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2217
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2218 for (method_const_iterator it = method_map.begin ();
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2219 it != method_map.end(); ++it)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2220 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2221 if (! it->second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2222 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2223 std::string nm = it->second.get_name ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2224
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2225 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2226 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2227 octave_value acc = it->second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2228
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2229 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2230 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2231 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2232 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2233
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2234 names.insert (nm);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2235 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2236 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2237
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2238 for (property_const_iterator it = property_map.begin ();
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2239 it != property_map.end (); ++it)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2240 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2241 std::string nm = it->second.get_name ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2242
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2243 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2244 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2245 octave_value acc = it->second.get ("GetAccess");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2246
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2247 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2248 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2249 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2250 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2251
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2252 names.insert (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2253 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2254
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2255 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2256
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2257 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2258
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2259 for (int i = 0; i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2260 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2261 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2262
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2263 cls.get_rep ()->find_names (names, all);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2264 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2265 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2266
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2267 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2268 cdef_class::cdef_class_rep::get_names (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2269 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2270 std::set<std::string> names;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2271
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2272 find_names (names, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2273
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2274 string_vector v (names.size ());
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2275
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2276 int idx = 0;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2277 for (std::set<std::string>::const_iterator it = names.begin ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2278 it != names.end (); ++it, ++idx)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2279 v[idx] = *it;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2280
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2281 return v.sort (true);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2282 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2283
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2284 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2285 cdef_class::cdef_class_rep::delete_object (cdef_object obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2286 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2287 method_iterator it = method_map.find ("delete");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2288
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2289 if (it != method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2290 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2291 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
2292
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2293 obj.set_class (wrap ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2294
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2295 it->second.execute (obj, octave_value_list (), 0, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2296
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2297 obj.set_class (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2298 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2299
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2300 // FIXME: should we destroy corresponding properties here?
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2301
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2302 // Call "delete" in super classes
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2303
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2304 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2305
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2306 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2307 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2308 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2309
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2310 cls.delete_object (obj);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2311 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2312 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2313
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2314 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
2315 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
2316 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2317 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2318 {
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2319 size_t skip = 1;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2320
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2321 octave_value_list 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 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2324 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2325 case '(':
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2326 // Constructor call
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2327
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2328 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2329 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
2330 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2331
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2332 retval(0) = construct (idx.front ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2333 break;
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2334
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2335 case '.':
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2336 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2337 // 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
2338
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2339 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2340 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
2341 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2342
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2343 if (idx.front ().length () != 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2344 error ("invalid meta.class indexing");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2345
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2346 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
2347
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2348 cdef_method meth = find_method (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2349
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2350 if (meth.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2351 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2352 if (! meth.is_static ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2353 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
2354
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2355 octave_value_list args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2356
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2357 if (type.length () > 1 && idx.size () > 1
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2358 && type[1] == '(')
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2359 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2360 args = *(++(idx.begin ()));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2361 skip++;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2362 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2363
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2364 retval = meth.execute (args, (type.length () > skip
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2365 ? 1 : nargout), true,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2366 "meta.class");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2367 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2368 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2369 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2370 cdef_property prop = find_property (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2371
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2372 if (! prop.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2373 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
2374
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2375 if (! prop.is_constant ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2376 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
2377
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2378 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
2379 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2380 }
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2381 break;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2382
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2383 default:
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
2384 error ("invalid meta.class indexing");
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2385 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2386 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2387
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2388 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
2389 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
2390
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2391 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2392 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2393
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2394 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
2395 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
2396 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
2397 cdef_manager::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
2398 }
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2399
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2400 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2401 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
2402 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2403 // Populate the object with default property values
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2404
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2405 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
2406 get ("SuperClasses").cell_value ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2407
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2408 for (std::list<cdef_class>::iterator it = super_classes.begin ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2409 it != super_classes.end (); ++it)
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2410 it->initialize_object (obj);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2411
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2412 for (property_const_iterator it = property_map.begin ();
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2413 it != property_map.end (); ++it)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2414 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2415 if (! it->second.get ("Dependent").bool_value ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2416 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2417 octave_value pvalue = it->second.get ("DefaultValue");
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2418
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2419 if (pvalue.is_defined ())
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2420 obj.put (it->first, pvalue);
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2421 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2422 obj.put (it->first, octave_value (Matrix ()));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2423 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2424 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2425
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2426 refcount++;
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2427 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
2428 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2429
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2430 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2431 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
2432 const octave_value_list& args)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2433 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2434 octave_value_list empty_args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2435
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2436 for (std::list<cdef_class>::const_iterator it = implicit_ctor_list.begin ();
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2437 it != implicit_ctor_list.end (); ++it)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2438 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2439 cdef_class supcls = lookup_class (*it);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2440
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2441 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
2442 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2443
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2444 std::string cls_name = get_name ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2445 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
2446
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2447 cdef_method ctor = find_method (ctor_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2448
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2449 if (ctor.ok ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2450 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2451 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
2452 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
2453
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2454 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
2455 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
2456
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2457 if (ctor_retval.length () != 1)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20946
diff changeset
2458 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
2459 ctor_name.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2460
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2461 obj = to_cdef (ctor_retval(0));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2462 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2463
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2464 obj.mark_as_constructed (wrap ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2465 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2466
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2467 octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2468 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
2469 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2470 cdef_object obj = construct_object (args);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2471
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2472 if (obj.ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2473 return to_ov (obj);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2474
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2475 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2476 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2477
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2478 cdef_object
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2479 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
2480 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2481 if (is_abstract ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2482 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
2483 get_name ().c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2484
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2485 cdef_object obj;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2486
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2487 if (is_meta_class ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2488 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2489 // 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
2490 // 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
2491
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2492 cdef_class this_cls = wrap ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2493
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2494 static cdef_object empty_class;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2495
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2496 if (this_cls == cdef_class::meta_class ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2497 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2498 if (! empty_class.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2499 empty_class = make_class ("", std::list<cdef_class> ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2500 obj = empty_class;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2501 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2502 else if (this_cls == cdef_class::meta_property ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2503 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2504 static cdef_property empty_property;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2505
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2506 if (! empty_class.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2507 empty_class = make_class ("", std::list<cdef_class> ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2508 if (! empty_property.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2509 empty_property = make_property (empty_class, "");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2510 obj = empty_property;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2511 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2512 else if (this_cls == cdef_class::meta_method ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2513 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2514 static cdef_method empty_method;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2515
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2516 if (! empty_class.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2517 empty_class = make_class ("", std::list<cdef_class> ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2518 if (! empty_method.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2519 empty_method = make_method (empty_class, "", octave_value ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2520 obj = empty_method;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2521 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2522 else if (this_cls == cdef_class::meta_package ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2523 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2524 static cdef_package empty_package;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2525
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2526 if (! empty_package.ok ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2527 empty_package = make_package ("");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2528 obj = empty_package;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2529 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2530 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2531 panic_impossible ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2532
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2533 return obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2534 }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
2535 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2536 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2537 if (is_handle_class ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2538 obj = cdef_object (new handle_cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2539 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2540 obj = cdef_object (new value_cdef_object ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2541 obj.set_class (wrap ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2542
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2543 initialize_object (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2544
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2545 run_constructor (obj, args);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2546
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2547 return obj;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2548 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2549
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2550 return cdef_object ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2551 }
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 static octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2554 compute_attribute_value (tree_classdef_attribute* t)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2555 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2556 if (t->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2557 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2558 if (t->expression ()->is_identifier ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2559 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2560 std::string s = t->expression ()->name ();
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 if (s == "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2563 return std::string ("public");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2564 else if (s == "protected")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2565 return std::string ("protected");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2566 else if (s == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2567 return std::string ("private");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2568 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2569
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2570 return t->expression ()->rvalue1 ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2571 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2572 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2573 return octave_value (true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2574 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2575
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
2576 template <typename T>
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2577 static std::string
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2578 attribute_value_to_string (T* t, octave_value v)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2579 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2580 if (v.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2581 return v.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2582 else if (t->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2583 return t->expression ()->original_text ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2584 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2585 return std::string ("true");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2586 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2587
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2588 cdef_class
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2589 cdef_class::make_meta_class (tree_classdef* t, bool is_at_folder)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2590 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2591 cdef_class retval;
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2592 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
2593
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2594 // Class creation
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2595
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2596 class_name = full_class_name = t->ident ()->name ();
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2597 if (! t->package_name ().empty ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2598 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
2599
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2600 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2601 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
2602 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2603
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2604 std::list<cdef_class> slist;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2605
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2606 if (t->superclass_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2607 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2608 for (tree_classdef_superclass_list::iterator it =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2609 t->superclass_list ()->begin ();
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2610 it != t->superclass_list ()->end (); ++it)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2611 {
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
2612 std::string sclass_name = (*it)->class_name ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2613
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2614 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2615 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
2616 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2617
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2618 cdef_class sclass = lookup_class (sclass_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2619
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2620 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
2621 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
2622 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
2623
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
2624 slist.push_back (sclass);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2625 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2626 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2627
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2628 retval = ::make_class (full_class_name, slist);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2629
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2630 // Package owning this class
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2631
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2632 if (! t->package_name ().empty ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2633 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2634 cdef_package pack = cdef_manager::find_package (t->package_name ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2635
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2636 if (pack.ok ())
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2637 retval.put ("ContainingPackage", to_ov (pack));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2638 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2639
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2640 // Class attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2641
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2642 if (t->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2643 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2644 for (tree_classdef_attribute_list::iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2645 it = t->attribute_list ()->begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2646 it != t->attribute_list ()->end ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2647 ++it)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2648 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2649 std::string aname = (*it)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2650 octave_value avalue = compute_attribute_value (*it);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2651
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2652 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2653 std::cerr << "class attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2654 << attribute_value_to_string (*it, avalue) << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2655 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2656
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2657 retval.put (aname, avalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2658 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2659 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2660
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2661 tree_classdef_body* b = t->body ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2662
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2663 if (b)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2664 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
2665 // 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
2666 // later on when creating properties.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2667
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2668 std::map<std::string, octave_value> get_methods;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2669 std::map<std::string, octave_value> set_methods;
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 // Method blocks
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 std::list<tree_classdef_methods_block *> mb_list = b->methods_list ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2674
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2675 for (tree_classdef_body::methods_list_iterator it = mb_list.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2676 it != mb_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2677 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2678 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
2679
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2680 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2681 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
2682 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2683
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2684 // Method attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2685
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2686 if ((*it)->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2687 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2688 for (tree_classdef_attribute_list::iterator ait =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2689 (*it)->attribute_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2690 ait != (*it)->attribute_list ()->end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2691 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2692 std::string aname = (*ait)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2693 octave_value avalue = compute_attribute_value (*ait);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2694
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2695 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2696 std::cerr << "method attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2697 << attribute_value_to_string (*ait, avalue)
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2698 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2699 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2700
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2701 amap[aname] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2702 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2703 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2704
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2705 // Methods
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2706
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2707 if ((*it)->element_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2708 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2709 for (tree_classdef_methods_list::iterator mit =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2710 (*it)->element_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2711 mit != (*it)->element_list ()->end (); ++mit)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2712 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2713 std::string mname = mit->function_value ()->name ();
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2714 std::string mprefix = mname.substr (0, 4);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2715
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2716 if (mprefix == "get.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2717 get_methods[mname.substr (4)] =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2718 make_fcn_handle (*mit, full_class_name + ">" + mname);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2719 else if (mprefix == "set.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2720 set_methods[mname.substr (4)] =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2721 make_fcn_handle (*mit, full_class_name + ">" + mname);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2722 else
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2723 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2724 cdef_method meth = make_method (retval, mname, *mit);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2725
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2726 #if DEBUG_TRACE
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2727 std::cerr << (mname == class_name ? "constructor"
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2728 : "method")
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2729 << ": " << mname << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2730 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2731
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2732 for (std::map<std::string, octave_value>::iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2733 ait = amap.begin (); ait != amap.end (); ++ait)
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2734 meth.put (ait->first, ait->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2735
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2736 retval.install_method (meth);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2737 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2738 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2739 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2740 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2741
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2742 if (is_at_folder)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2743 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2744 // 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
2745 // 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
2746 //
21578
683a1beee538 maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents: 21574
diff changeset
2747 // FIXME: This is an "extension" to Matlab behavior, which only
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2748 // looks in the @-folder containing the original classdef
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
2749 // file. However, this is easier to implement it that way at
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2750 // the moment.
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2751
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2752 std::list<std::string> external_methods =
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2753 load_path::methods (full_class_name);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2754
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2755 for (std::list<std::string>::const_iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2756 it = external_methods.begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2757 it != external_methods.end ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2758 ++it)
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2759 {
21578
683a1beee538 maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents: 21574
diff changeset
2760 // 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
2761 // defined in the classdef file?
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2762
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2763 if (*it != class_name
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2764 && ! retval.find_method (*it, true).ok ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2765 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2766 // 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
2767 // method is loaded.
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2768
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2769 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
2770
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2771 fcn->stash_function_name (*it);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2772
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2773 cdef_method meth = make_method (retval, *it,
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2774 octave_value (fcn));
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2775
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2776 retval.install_method (meth);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2777 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2778 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2779 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2780
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2781 // Property blocks
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2782
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2783 // 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
2784 // 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
2785 // 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
2786 // value expressions.
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2787
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2788 std::list<tree_classdef_properties_block *> pb_list
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2789 = b->properties_list ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2790
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2791 for (tree_classdef_body::properties_list_iterator it = pb_list.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2792 it != pb_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2793 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2794 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
2795
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2796 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2797 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
2798 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2799
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2800 // Property attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2801
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2802 if ((*it)->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2803 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2804 for (tree_classdef_attribute_list::iterator ait =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2805 (*it)->attribute_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2806 ait != (*it)->attribute_list ()->end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2807 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2808 std::string aname = (*ait)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2809 octave_value avalue = compute_attribute_value (*ait);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2810
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2811 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2812 std::cerr << "property attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2813 << attribute_value_to_string (*ait, avalue)
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2814 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2815 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2816
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2817 if (aname == "Access")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2818 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2819 amap["GetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2820 amap["SetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2821 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2822 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2823 amap[aname] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2824 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2825 }
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 // Properties
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 if ((*it)->element_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2830 {
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2831 for (tree_classdef_property_list::iterator pit =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2832 (*it)->element_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2833 pit != (*it)->element_list ()->end (); ++pit)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2834 {
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2835 std::string prop_name = (*pit)->ident ()->name ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2836
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2837 cdef_property prop = ::make_property (retval, prop_name);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2838
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2839 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2840 std::cerr << "property: " << (*pit)->ident ()->name ()
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2841 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2842 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2843
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2844 if ((*pit)->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2845 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2846 octave_value pvalue = (*pit)->expression ()->rvalue1 ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2847
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2848 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2849 std::cerr << "property default: "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2850 << 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
2851 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2852 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
2853
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2854 prop.put ("DefaultValue", pvalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2855 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2856
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2857 // Install property attributes. This is done before assigning
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2858 // the property accessors so we can do validationby using
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2859 // cdef_property methods.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2860
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2861 for (std::map<std::string, octave_value>::iterator ait = amap.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2862 ait != amap.end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2863 prop.put (ait->first, ait->second);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2864
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
2865 // 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
2866 // 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
2867 // 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
2868 // defined property.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2869
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2870 std::map<std::string, octave_value>::iterator git =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2871 get_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2872
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2873 if (git != get_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2874 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
2875 make_function_of_class (retval, git->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2876 prop.put ("GetMethod", git->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2877 get_methods.erase (git);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2878 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2879
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2880 std::map<std::string, octave_value>::iterator sit =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2881 set_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2882
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2883 if (sit != set_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2884 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
2885 make_function_of_class (retval, sit->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2886 prop.put ("SetMethod", sit->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2887 set_methods.erase (sit);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2888 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2889
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2890 retval.install_property (prop);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2891 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2892 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2893 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2894 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2895
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2896 return retval;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2897 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2898
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2899 octave_function*
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2900 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
2901 {
15986
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2902 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
2903
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2904 return p;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2905 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2906
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2907 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
2908 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
2909 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
2910 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2911 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2912 octave_value retval;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2913
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2914 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
2915 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
2916
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2917 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2918 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2919 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
2920
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2921 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
2922 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
2923 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2924 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2925
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2926 octave_value get_fcn = get ("GetMethod");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2927
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2928 // 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
2929
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2930 if (get_fcn.is_empty () || is_method_executing (get_fcn, obj))
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2931 retval = obj.get (get ("Name").string_value ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2932 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2933 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2934 octave_value_list args;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2935
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2936 args(0) = to_ov (obj);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2937
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2938 args = execute_ov (get_fcn, args, 1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2939
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2940 retval = args(0);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2941 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2942
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2943 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2944 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2945
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2946 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
2947 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
2948 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
2949 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2950 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
2951 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
2952
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2953 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
2954 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2955
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2956 bool
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2957 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
2958 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2959 // FIXME: implement
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2960 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2961 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2962
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2963 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2964 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
2965 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
2966 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
2967 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2968 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2969 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
2970 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
2971
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2972 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2973 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2974 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
2975
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2976 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
2977 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
2978 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2979 }
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19343
diff changeset
2980
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2981 octave_value set_fcn = get ("SetMethod");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2982
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2983 if (set_fcn.is_empty () || is_method_executing (set_fcn, obj))
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2984 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
2985 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2986 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2987 octave_value_list args;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2988
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2989 args(0) = to_ov (obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2990 args(1) = val;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2991
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2992 args = execute_ov (set_fcn, args, 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2993
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2994 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
2995 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2996 if (args (0).is_classdef_object ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2997 {
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2998 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
2999
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3000 obj = new_obj;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3001 }
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3002 else
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3003 ::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
3004 get_name ().c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3005 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3006 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3007 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3008
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3009 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
3010 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
3011 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3012 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3013
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
3014 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
3015 get_name (), false);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3016
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3017 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3018 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3019
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3020 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
3021 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
3022 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3023 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3024
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
3025 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
3026 get_name (), true);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3027
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3028 return false;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3029 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3030
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3031 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3032 cdef_method::cdef_method_rep::check_method (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3033 {
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3034 if (is_external ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3035 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3036 if (is_dummy_method (function))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3037 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3038 std::string name = get_name ();
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3039 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
3040 std::string pack_name;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3041
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3042 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
3043
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3044 if (pos != std::string::npos)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3045 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3046 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
3047 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
3048 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3049
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3050 std::string dir_name;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3051 std::string file_name = load_path::find_method (cls_name, name,
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3052 dir_name, pack_name);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3053
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3054 if (! file_name.empty ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3055 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3056 octave_function *fcn = load_fcn_from_file (file_name, dir_name,
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3057 dispatch_type,
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3058 pack_name);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3059
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3060 if (fcn)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3061 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3062 function = octave_value (fcn);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3063
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3064 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
3065 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3066 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3067 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3068 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3069 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3070 // 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
3071 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3072
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3073 if (is_dummy_method (function))
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20193
diff changeset
3074 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
3075 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
3076 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3077 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3078
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3079 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3080 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
3081 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
3082 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3083 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3084 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3085
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3086 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
3087 err_method_access (who, wrap ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3088
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3089 if (get ("Abstract").bool_value ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3090 error ("%s: cannot execute abstract method",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3091 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3092
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3093 check_method ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3094
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3095 if (function.is_defined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3096 retval = execute_ov (function, args, nargout);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3097
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3098 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3099 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3100
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3101 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3102 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
3103 const octave_value_list& args,
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3104 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
3105 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3106 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3107 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3108
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3109 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
3110 err_method_access (who, wrap ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3111
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3112 if (get ("Abstract").bool_value ())
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3113 error ("%s: cannot execute abstract method",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3114 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3115
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3116 check_method ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3117
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3118 if (function.is_defined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3119 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3120 octave_value_list new_args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3121
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3122 new_args.resize (args.length () + 1);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3123
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3124 new_args(0) = to_ov (obj);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3125 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
3126 new_args(i+1) = args(i);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3127
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3128 retval = execute_ov (function, new_args, nargout);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3129 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3130
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3131 return retval;
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3134 bool
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3135 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
3136 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3137 if (function.is_function())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3138 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
3139
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3140 return false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3141 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3142
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3143 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
3144 cdef_method::cdef_method_rep::check_access (void) const
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3145 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3146 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3147
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3148 return ::check_access (cls, get ("Access"), get_name ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3149 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3150
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3151 octave_value_list
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3152 cdef_method::cdef_method_rep::meta_subsref
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3153 (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
3154 int nargout)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3155 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3156 octave_value_list retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3157
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3158 switch (type[0])
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3159 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3160 case '(':
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3161 retval = execute (idx.front (), type.length () > 1 ? 1 : nargout, true);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3162 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3163
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3164 default:
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3165 error ("invalid meta.method indexing");
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3166 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3167 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3168
20563
c1a6c31ac29a eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3169 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
3170 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
3171
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3172 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3173 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3174
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3175 static cdef_package
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3176 lookup_package (const std::string& name)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3177 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3178 return cdef_manager::find_package (name);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3179 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3180
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3181 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3182 package_fromName (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3183 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3184 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3185
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3186 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3187 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3188
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3189 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
3190
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3191 retval(0) = to_ov (lookup_package (name));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3192
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3193 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3194 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3195
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3196 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3197 package_get_classes (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3198 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3199 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3200
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3201 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3202 && args(0).class_name () == "meta.package")
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 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3205
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3206 retval(0) = pack.get_classes ();
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3210 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3211
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3212 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3213 package_get_functions (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3216
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3217 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3218 && args(0).class_name () == "meta.package")
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 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3221
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3222 retval(0) = pack.get_functions ();
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3225 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3226 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3227
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3228 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3229 package_get_packages (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3230 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3231 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3232
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3233 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3234 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3235 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3236 cdef_package pack (to_cdef (args(0)));
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 retval(0) = pack.get_packages ();
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3242 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3243
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3244 static octave_value_list
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
3245 package_getAllPackages (const octave_value_list& /* args */, int /* nargout */)
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3246 {
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3247 std::map<std::string, cdef_package> toplevel_packages;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3248
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3249 std::list<std::string> names = load_path::get_all_package_names ();
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3250
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3251 toplevel_packages["meta"] = cdef_manager::find_package ("meta", false,
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3252 false);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3253
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3254 for (std::list<std::string>::const_iterator it = names.begin ();
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3255 it != names.end (); ++it)
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3256 toplevel_packages[*it] = cdef_manager::find_package (*it, false, true);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3257
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3258 Cell c (toplevel_packages.size (), 1);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3259
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3260 int i = 0;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3261
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
3262 for (std::map<std::string, cdef_package>::const_iterator it =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
3263 toplevel_packages.begin ();
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3264 it != toplevel_packages.end (); ++it)
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3265 c(i++,0) = to_ov (it->second);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3266
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3267 return octave_value_list (octave_value (c));
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3268 }
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3269
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3270 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3271 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
3272 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3273 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3274 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
3275
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3276 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3277 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3278
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3279 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3280 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
3281 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3282 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3283 function_map[nm] = fcn;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3284 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3285
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3286 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3287 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
3288 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3289 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3290 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
3291
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3292 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3293 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3294
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
3295 template <typename T1, typename T2>
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3296 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3297 map2Cell (const std::map<T1, T2>& m)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3298 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3299 Cell retval (1, m.size ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3300 int i = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3301
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3302 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
3303 it != m.end (); ++it, ++i)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3304 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3305 retval(i) = to_ov (it->second);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3306 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3307
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3308 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3309 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3310
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3311 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3312 cdef_package::cdef_package_rep::get_classes (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3313 { return map2Cell (class_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3314
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3315 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3316 cdef_package::cdef_package_rep::get_functions (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3317 { return map2Cell (function_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3318
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3319 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3320 cdef_package::cdef_package_rep::get_packages (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3321 { return map2Cell (package_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3322
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3323 octave_value
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3324 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
3325 {
16684
edbb123cbe3a Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16676
diff changeset
3326 std::string symbol_name = get_name () + "." + nm;
edbb123cbe3a Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16676
diff changeset
3327
edbb123cbe3a Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16676
diff changeset
3328 return symbol_table::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
3329 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3330
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3331 octave_value_list
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3332 cdef_package::cdef_package_rep::meta_subsref
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3333 (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
3334 int nargout)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3335 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3336 octave_value_list retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3337
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3338 switch (type[0])
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3339 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3340 case '.':
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3341 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3342 if (idx.front ().length () != 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3343 error ("invalid meta.package indexing");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3344
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3345 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
3346
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3347 #if DEBUG_TRACE
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3348 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
3349 #endif
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3350
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3351 octave_value o = find (nm);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3352
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3353 if (! o.is_defined ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3354 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
3355 nm.c_str (), get_name ().c_str ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3356
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3357 if (o.is_function ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3358 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3359 octave_function* fcn = o.function_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3360
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3361 // 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
3362 // 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
3363 // 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
3364 // "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
3365 // function call at this stage.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3366
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3367 if (type.size () > 1
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3368 && ! fcn->is_postfix_index_handled (type[1]))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3369 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3370 octave_value_list tmp_args;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3371
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3372 retval = o.do_multi_index_op (nargout,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3373 tmp_args);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3374 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3375 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3376 retval(0) = o;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3377
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3378 if (type.size () > 1 && idx.size () > 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3379 retval = retval(0).next_subsref (nargout, type,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3380 idx, 1);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3381 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3382 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
3383 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
3384 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3385 retval(0) = o;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
3386 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3387 break;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3388
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3389 default:
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3390 error ("invalid meta.package indexing");
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3391 break;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3392 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3393
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3394 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3395 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3396
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3397 void
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3398 cdef_package::cdef_package_rep::meta_release (void)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3399 {
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3400 // 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
3401 // could still be referenced by classes or sub-packages?
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3402 // 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
3403 // match the one already referenced by those classes or
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3404 // sub-packages.
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3405
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3406 //cdef_manager::unregister_package (wrap ());
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3407 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3408
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3409 cdef_class cdef_class::_meta_class = cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3410 cdef_class cdef_class::_meta_property = cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3411 cdef_class cdef_class::_meta_method = cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3412 cdef_class cdef_class::_meta_package = cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3413
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3414 cdef_package cdef_package::_meta = cdef_package ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3415
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3416 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3417 install_classdef (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3418 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3419 octave_classdef::register_type ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3420
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3421 // bootstrap
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3422 cdef_class handle = make_class ("handle");
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3423 cdef_class meta_class = cdef_class::_meta_class = make_meta_class ("meta.class", handle);
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3424 handle.set_class (meta_class);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3425 meta_class.set_class (meta_class);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3426
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3427 // meta classes
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3428 cdef_class meta_property = cdef_class::_meta_property = make_meta_class ("meta.property", handle);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3429 cdef_class meta_method = cdef_class::_meta_method = make_meta_class ("meta.method", handle);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3430 cdef_class meta_package = cdef_class::_meta_package = make_meta_class ("meta.package", handle);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3431
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3432 cdef_class meta_event = make_meta_class ("meta.event", handle);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3433 cdef_class meta_dynproperty = make_meta_class ("meta.dynamicproperty", handle);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3434
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3435 // meta.class properties
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3436 meta_class.install_property (make_attribute (meta_class, "Abstract"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3437 meta_class.install_property (make_attribute (meta_class, "ConstructOnLoad"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3438 meta_class.install_property (make_property (meta_class, "ContainingPackage"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3439 meta_class.install_property (make_property (meta_class, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3440 meta_class.install_property (make_property (meta_class, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3441 meta_class.install_property (make_property (meta_class, "Events"));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3442 meta_class.install_property (make_attribute (meta_class, "HandleCompatible"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3443 meta_class.install_property (make_attribute (meta_class, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3444 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3445 (make_property (meta_class, "InferiorClasses",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3446 make_fcn_handle (class_get_inferiorclasses, "meta.class>get.InferiorClasses"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3447 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3448 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3449 (make_property (meta_class, "Methods",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3450 make_fcn_handle (class_get_methods, "meta.class>get.Methods"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3451 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3452 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3453 (make_property (meta_class, "MethodList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3454 make_fcn_handle (class_get_methods, "meta.class>get.MethodList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3455 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3456 meta_class.install_property (make_attribute (meta_class, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3457 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3458 (make_property (meta_class, "Properties",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3459 make_fcn_handle (class_get_properties, "meta.class>get.Properties"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3460 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3461 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3462 (make_property (meta_class, "PropertyList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3463 make_fcn_handle (class_get_properties, "meta.class>get.PropertyList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3464 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3465 meta_class.install_property (make_attribute (meta_class, "Sealed"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3466 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3467 (make_property (meta_class, "SuperClasses",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3468 make_fcn_handle (class_get_superclasses, "meta.class>get.SuperClasses"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3469 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3470 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3471 (make_property (meta_class, "SuperClassList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3472 make_fcn_handle (class_get_superclasses, "meta.class>get.SuperClassList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3473 "public", Matrix (), "private"));
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3474 // meta.class methods
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3475 meta_class.install_method (make_method (meta_class, "fromName", class_fromName,
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3476 "public", true));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3477 meta_class.install_method (make_method (meta_class, "fevalStatic", class_fevalStatic,
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3478 "public", false));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3479 meta_class.install_method (make_method (meta_class, "getConstant", class_getConstant,
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3480 "public", false));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3481 meta_class.install_method (make_method (meta_class, "eq", class_eq));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3482 meta_class.install_method (make_method (meta_class, "ne", class_ne));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3483 meta_class.install_method (make_method (meta_class, "lt", class_lt));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3484 meta_class.install_method (make_method (meta_class, "le", class_le));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3485 meta_class.install_method (make_method (meta_class, "gt", class_gt));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3486 meta_class.install_method (make_method (meta_class, "ge", class_ge));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3487
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3488 // meta.method properties
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3489 meta_method.install_property (make_attribute (meta_method, "Abstract"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3490 meta_method.install_property (make_attribute (meta_method, "Access"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3491 meta_method.install_property (make_attribute (meta_method, "DefiningClass"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3492 meta_method.install_property (make_attribute (meta_method, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3493 meta_method.install_property (make_attribute (meta_method, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3494 meta_method.install_property (make_attribute (meta_method, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3495 meta_method.install_property (make_attribute (meta_method, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3496 meta_method.install_property (make_attribute (meta_method, "Sealed"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3497 meta_method.install_property (make_attribute (meta_method, "Static"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3498
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3499 // meta.property properties
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3500 meta_property.install_property (make_attribute (meta_property, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3501 meta_property.install_property (make_attribute (meta_property, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3502 meta_property.install_property (make_attribute (meta_property, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3503 meta_property.install_property (make_attribute (meta_property, "Abstract"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3504 meta_property.install_property (make_attribute (meta_property, "Constant"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3505 meta_property.install_property (make_attribute (meta_property, "GetAccess"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3506 meta_property.install_property (make_attribute (meta_property, "SetAccess"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3507 meta_property.install_property (make_attribute (meta_property, "Dependent"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3508 meta_property.install_property (make_attribute (meta_property, "Transient"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3509 meta_property.install_property (make_attribute (meta_property, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3510 meta_property.install_property (make_attribute (meta_property, "GetObservable"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3511 meta_property.install_property (make_attribute (meta_property, "SetObservable"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3512 meta_property.install_property (make_attribute (meta_property, "GetMethod"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3513 meta_property.install_property (make_attribute (meta_property, "SetMethod"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3514 meta_property.install_property (make_attribute (meta_property, "DefiningClass"));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3515 meta_property.install_property
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3516 (make_property (meta_property, "DefaultValue",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3517 make_fcn_handle (property_get_defaultvalue, "meta.property>get.DefaultValue"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3518 "public", Matrix (), "private"));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3519 meta_property.install_property (make_attribute (meta_property, "HasDefault"));
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3520 // meta.property events
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3521 // FIXME: add events
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3522
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3523 // handle methods
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3524 handle.install_method (make_method (handle, "delete", handle_delete));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3525
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3526 // meta.package properties
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3527 meta_package.install_property (make_attribute (meta_package, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3528 meta_package.install_property (make_property (meta_package, "ContainingPackage"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3529 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3530 (make_property (meta_package, "ClassList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3531 make_fcn_handle (package_get_classes, "meta.package>get.ClassList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3532 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3533 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3534 (make_property (meta_package, "Classes",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3535 make_fcn_handle (package_get_classes, "meta.package>get.Classes"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3536 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3537 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3538 (make_property (meta_package, "FunctionList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3539 make_fcn_handle (package_get_functions, "meta.package>get.FunctionList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3540 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3541 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3542 (make_property (meta_package, "Functions",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3543 make_fcn_handle (package_get_functions, "meta.package>get.Functions"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3544 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3545 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3546 (make_property (meta_package, "PackageList",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3547 make_fcn_handle (package_get_packages, "meta.package>get.PackageList"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3548 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3549 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3550 (make_property (meta_package, "Packages",
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3551 make_fcn_handle (package_get_packages, "meta.package>get.Packages"),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3552 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3553 meta_package.install_method (make_method (meta_package, "fromName", package_fromName,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3554 "public", true));
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3555 meta_package.install_method (make_method (meta_package, "getAllPackages", package_getAllPackages,
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3556 "public", true));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3557
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3558 // create "meta" package
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3559 cdef_package package_meta = cdef_package::_meta = make_package ("meta");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3560 package_meta.install_class (meta_class, "class");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3561 package_meta.install_class (meta_property, "property");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3562 package_meta.install_class (meta_method, "method");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3563 package_meta.install_class (meta_package, "package");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3564 package_meta.install_class (meta_event, "event");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3565 package_meta.install_class (meta_dynproperty, "dynproperty");
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3566
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3567 // install built-in classes into the symbol table
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3568 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3569 ("meta.class", octave_value (meta_class.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3570 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3571 ("meta.method", octave_value (meta_method.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3572 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3573 ("meta.property", octave_value (meta_property.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3574 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3575 ("meta.package", octave_value (meta_package.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3576 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3577 ("meta.event", octave_value (meta_event.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3578 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3579 ("meta.dynproperty", octave_value (meta_dynproperty.get_constructor_function ()));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3580 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3581
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3582 //----------------------------------------------------------------------------
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3583
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3584 cdef_manager* cdef_manager::instance = 0;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3585
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3586 void
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3587 cdef_manager::create_instance (void)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3588 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3589 instance = new cdef_manager ();
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3590
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3591 if (instance)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3592 singleton_cleanup_list::add (cleanup_instance);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3593 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3594
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3595 cdef_class
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3596 cdef_manager::do_find_class (const std::string& name,
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3597 bool error_if_not_found, bool load_if_not_found)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3598 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3599 std::map<std::string, cdef_class>::iterator it = all_classes.find (name);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3600
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3601 if (it == all_classes.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3602 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3603 if (load_if_not_found)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3604 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3605 octave_value ov_cls;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3606
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3607 size_t pos = name.rfind ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3608
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3609 if (pos == std::string::npos)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3610 ov_cls = symbol_table::find (name);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3611 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3612 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3613 std::string pack_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3614
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3615 cdef_package pack = do_find_package (pack_name, false, true);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3616
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3617 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3618 ov_cls = pack.find (name.substr (pos+1));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3619 }
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3620
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3621 if (ov_cls.is_defined ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3622 it = all_classes.find (name);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3623 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3624 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3625
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3626 if (it == all_classes.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3627 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3628 if (error_if_not_found)
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3629 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
3630 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3631 else
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3632 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3633 cdef_class cls = it->second;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3634
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3635 if (! cls.is_builtin ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3636 cls = lookup_class (cls);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3637
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3638 if (cls.ok ())
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3639 return cls;
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3640 else
18692
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3641 all_classes.erase (it);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3642 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3643
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3644 return cdef_class ();
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3645 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3646
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3647 octave_function*
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3648 cdef_manager::do_find_method_symbol (const std::string& method_name,
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3649 const std::string& class_name)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3650 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3651 octave_function *retval = 0;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3652
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3653 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
3654
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3655 if (cls.ok ())
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 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
3658
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3659 if (meth.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3660 retval = new octave_classdef_meta (meth);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3661 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3662
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3663 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3664 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3665
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3666 cdef_package
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3667 cdef_manager::do_find_package (const std::string& name,
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3668 bool error_if_not_found,
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3669 bool load_if_not_found)
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3670 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3671 cdef_package retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3672
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3673 std::map<std::string, cdef_package>::const_iterator it
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3674 = all_packages.find (name);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3675
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3676 if (it != all_packages.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3677 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3678 retval = it->second;
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 (! retval.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3681 error ("invalid package `%s'", name.c_str ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3682 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3683 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3684 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3685 if (load_if_not_found && load_path::find_package (name))
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3686 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3687 size_t pos = name.find ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3688
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3689 if (pos == std::string::npos)
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20979
diff changeset
3690 retval = make_package (name, "");
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3691 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3692 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3693 std::string parent_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3694
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3695 retval = make_package (name, parent_name);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3696 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3697 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3698 else if (error_if_not_found)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3699 error ("unknown package `%s'", name.c_str ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3700 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3701
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3702 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3703 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3704
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3705 octave_function*
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3706 cdef_manager::do_find_package_symbol (const std::string& pack_name)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3707 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3708 octave_function* retval = 0;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3709
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
3710 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
3711
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3712 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3713 retval = new octave_classdef_meta (pack);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3714
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3715 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3716 }
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 //----------------------------------------------------------------------------
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3719
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3720 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
3721 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
3722 @deftypefn {} {} __meta_get_package__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3723 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
3724 @end deftypefn */)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3725 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3726 if (args.length () != 1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3727 print_usage ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3728
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3729 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
3730
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3731 return to_ov (lookup_package (cname));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3732 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3733
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3734 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
3735 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
3736 @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
3737 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
3738 @end deftypefn */)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3739 {
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
3740 return ovl (new octave_classdef_superclass_ref (args));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3741 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3742
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3743 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
3744 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
3745 @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
3746 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
3747 @end deftypefn */)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3748 {
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3749 #if DEBUG_TRACE
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3750 std::cerr << "__meta_class_query__ ("
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
3751 << args(0).string_value () << ")"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3752 << std::endl;
19031
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18692
diff changeset
3753 #endif
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3754
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3755 if (args.length () != 1)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3756 print_usage ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3757
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3758 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
3759
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3760 return to_ov (lookup_class (cls));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3761 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3762
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
3763 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
3764 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
3765 @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
3766 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
3767 @end deftypefn */)
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3768 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3769 if (args.length () != 1)
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3770 print_usage ();
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3771
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3772 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
3773
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
3774 return to_ov (obj.get_class ());
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3775 }
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
3776
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3777 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3778 ;;; Local Variables: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3779 ;;; mode: C++ ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3780 ;;; End: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3781 */