annotate libinterp/octave-value/ov-classdef.cc @ 20523:a142b62527ef

Fix compilation of classdef with the clang compiler (bug #41178) * ov-classdef.cc, ov-classdef.h (cdef_object_scalar::mark_as_constructed): Move function definition out of header file to avoid dependency on incomplete type, compilation error with clang.
author akira noda <you.akira.noda@gmail.com>
date Fri, 21 Aug 2015 13:05:52 -0400
parents 7ac907da9fba
children dd6345fd8a97
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19675
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
24 #include <config.h>
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
29 #include "defun.h"
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
30 #include "load-path.h"
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
31 #include "ov-builtin.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
32 #include "ov-classdef.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
33 #include "ov-fcn-handle.h"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
34 #include "ov-typeinfo.h"
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
35 #include "ov-usr-fcn.h"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
36 #include "pt-assign.h"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
37 #include "pt-classdef.h"
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
38 #include "pt-funcall.h"
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
39 #include "pt-misc.h"
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
40 #include "pt-stmt.h"
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
41 #include "pt-walk.h"
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
42 #include "singleton-cleanup.h"
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
43 #include "symtab.h"
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
44 #include "toplev.h"
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
45
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
46 #include "Array.cc"
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
47
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
48 // Define to 1 to enable debugging statements.
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
49 #define DEBUG_TRACE 0
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
50
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
51 static void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
52 gripe_method_access (const std::string& from, const cdef_method& meth)
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",
18726
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
66 static void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
67 gripe_property_access (const std::string& from, const cdef_property& prop,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
68 bool is_set = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
69 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
70 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
71 std::string acc_s;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
72
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
73 if (acc.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
74 acc_s = acc.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
75 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
76 acc_s = "class-restricted";
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
77
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
78 if (is_set)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
79 error ("%s: property `%s' has %s access and cannot be set in this context",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
80 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
81 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
82 error ("%s: property `%s' has %s access and cannot be obtained in this context",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
83 from.c_str (), prop.get_name ().c_str (), acc_s.c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
84 }
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 static std::string
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
87 get_base_name (const std::string& nm)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
88 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
89 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
90
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
91 if (pos != std::string::npos)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
92 return nm.substr (pos + 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
93
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
94 return nm;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
95 }
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 static void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
98 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
99 const octave_value& fcn)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
100 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
101 octave_function *of = fcn.function_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
102
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
103 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
104 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
105 of->stash_dispatch_class (class_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
106
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
107 octave_user_function *uf = of->user_function_value (true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
108
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
109 if (! error_state && uf)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
110 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
111 if (get_base_name (class_name) == uf->name ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
112 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
113 uf->mark_as_class_constructor ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
114 uf->mark_as_classdef_constructor ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
115 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
116 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
117 uf->mark_as_class_method ();
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 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
121
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
122 static void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
123 make_function_of_class (const cdef_class& cls, const octave_value& fcn)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
124 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
125 make_function_of_class (cls.get_name (), fcn);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
126 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
127
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
128 static octave_value
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
129 make_fcn_handle (octave_builtin::fcn ff, const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
130 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
131 octave_value fcn (new octave_builtin (ff, nm));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
132
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
133 octave_value fcn_handle (new octave_fcn_handle (fcn, nm));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
134
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
135 return fcn_handle;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
136 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
137
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
138 static octave_value
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
139 make_fcn_handle (const octave_value& fcn, const std::string& nm)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
140 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
141 octave_value retval;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
142
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
143 if (fcn.is_defined ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
144 retval = octave_value (new octave_fcn_handle (fcn, nm));
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
145
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
146 return retval;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
147 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
148
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
149 inline octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
150 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
151 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
152 std::list<octave_value_list> idx (1, args);
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 std::string type ("(");
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 return val.subsref (type, idx, nargout);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
157 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
158
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
159 static cdef_class
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
160 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
161 bool load_if_not_found = true)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
162 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
163 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
164 load_if_not_found);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
165 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
166
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
167 static cdef_class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
168 lookup_class (const cdef_class& cls)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
169 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
170 // 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
171 // 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
172
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
173 return cls;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
174 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
175
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
176 static cdef_class
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
177 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
178 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
179 if (ov.is_string())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
180 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
181 else
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
182 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
183 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
184
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
185 if (! error_state)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
186 return lookup_class (cls);
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
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
189 return cdef_class ();
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
190 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
191
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
192 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
193 lookup_classes (const Cell& cls_list)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
194 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
195 std::list<cdef_class> retval;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
196
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
197 for (int i = 0; i < cls_list.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
198 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
199 cdef_class c = lookup_class (cls_list(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
200
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
201 if (! error_state)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
202 retval.push_back (c);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
203 else
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
204 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
205 retval.clear ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
206 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
207 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
208 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
209
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
210 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
211 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
212
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
213 static octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
214 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
215 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
216 Cell cls (class_list.size (), 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
217 int i = 0;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
218
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
219 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
220 it != class_list.end (); ++it, ++i)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
221 cls(i) = to_ov (*it);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
222
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
223 return octave_value (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
224 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
225
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
226 static bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
227 is_superclass (const cdef_class& clsa, const cdef_class& clsb,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
228 bool allow_equal = true, int max_depth = -1)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
229 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
230 bool retval = false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
231
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
232 if (allow_equal && clsa == clsb)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
233 retval = true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
234 else if (max_depth != 0)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
235 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
236 Cell c = clsb.get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
237
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
238 for (int i = 0; ! error_state && ! retval && i < c.numel (); i++)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
239 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
240 cdef_class cls = lookup_class (c(i));
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
241
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
242 if (! error_state)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
243 retval = is_superclass (clsa, cls, true,
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
244 max_depth < 0 ? max_depth : max_depth-1);
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
245 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
246 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
247
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
248 return retval;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
249 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
250
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
251 inline bool
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
252 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
253 { return is_superclass (clsa, clsb, false); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
254
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
255 inline bool
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
256 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
257 { 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
258
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
259 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
260 class_get_properties (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
261 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
262 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
263
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
264 if (args.length () == 1 && args(0).type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
265 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
266 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
267
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
268 retval(0) = cls.get_properties ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
269 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
270
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
271 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
272 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
273
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
274 static cdef_class
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
275 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
276 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
277 cdef_class cls;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
278
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
279 octave_function* fcn = octave_call_stack::current ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
280
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
281 in_constructor = false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
282
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
283 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: 19895
diff changeset
284 || fcn->is_classdef_constructor ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
285 || 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: 19895
diff changeset
286 || (fcn->is_private_function ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
287 && ! fcn->dispatch_class ().empty ())))
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
288 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
289 cls = lookup_class (fcn->dispatch_class ());
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
290 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
291 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
292 name = fcn->name ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
293 in_constructor = fcn->is_classdef_constructor ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
294 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
295 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
296
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
297 return cls;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
298 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
299
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
300 inline cdef_class
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
301 get_class_context (void)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
302 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
303 std::string dummy_string;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
304 bool dummy_bool;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
305
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
306 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
307 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
308
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
309 static bool
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
310 in_class_method (const cdef_class& cls)
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
311 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
312 cdef_class ctx = get_class_context ();
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
313
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
314 return (ctx.ok () && is_superclass (ctx, cls));
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
315 }
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
316
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
317 static bool
18305
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
318 check_access (const cdef_class& cls, const octave_value& acc,
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
319 const std::string& meth_name = std::string (),
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
320 const std::string& prop_name = std::string (),
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
321 bool is_prop_set = false)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
322 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
323 if (acc.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
324 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
325 std::string acc_s = acc.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
326
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
327 if (acc_s == "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
328 return true;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
329
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
330 cdef_class ctx = get_class_context ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
331
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
332 // 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
333 // valid class context.
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
334
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
335 if (! error_state && ctx.ok ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
336 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
337 if (acc_s == "private")
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
338 return (ctx == cls);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
339 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
340 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
341 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
342 // 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
343 return true;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
344 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
345 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
346 // 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
347 // 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
348 // 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
349
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
350 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
351 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
352 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
353
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
354 if (m.ok ())
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
355 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
356
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
357 return false;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
358 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
359 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
360 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
361 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
362
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
363 if (p.ok ())
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
364 {
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
365 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
366 "SetAccess" :
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
367 "GetAccess");
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
368
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
369 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
370 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
371 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
372
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
373 return false;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
374 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
375 else
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
376 panic_impossible ();
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
377 }
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
378
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
379 return false;
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
380 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
381 else
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
382 panic_impossible ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
383 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
384 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
385 else if (acc.is_cell ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
386 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
387 Cell acc_c = acc.cell_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
388
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
389 cdef_class ctx = get_class_context ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
390
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
391 // 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
392
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
393 if (! error_state && ctx.ok ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
394 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
395 if (ctx == cls)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
396 return true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
397
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
398 for (int i = 0; ! error_state && i < acc.numel (); i++)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
399 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
400 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
401
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
402 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
403 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
404 if (is_superclass (acc_cls, ctx))
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
405 return true;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
406 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
407 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
408 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
409 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
410 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
411 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
412 cls.get_name ().c_str ());
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
413
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
414 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
415 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
416
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
417 static bool
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
418 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
419 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
420 bool retval = false;
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 if (fcn.is_defined ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
423 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
424 if (fcn.is_user_function ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
425 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
426 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
427
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
428 if (! uf || ! uf->body ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
429 retval = true;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
430 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
431 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
432 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
433 retval = true;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
434
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
435 return retval;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
436 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
437
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
438 bool
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
439 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
440 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
441 octave_function* stack_fcn = octave_call_stack::current ();
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 octave_function* method_fcn = ov.function_value (true);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
444
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
445 // Does the top of the call stack match our target function?
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
446
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
447 if (stack_fcn && stack_fcn == method_fcn)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
448 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
449 octave_user_function* uf = method_fcn->user_function_value (true);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
450
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
451 // We can only check the context object for user-function (not builtin),
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
452 // where we have access to the parameters (arguments and return values).
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
453 // That's ok as there's no need to call this function for builtin
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
454 // methods.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
455
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
456 if (uf)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
457 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
458 // At this point, the method is executing, but we still need to
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
459 // check the context object for which the method is executing. For
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
460 // methods, it's the first argument of the function; for ctors, it
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
461 // is the first return value.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
462
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
463 tree_parameter_list* pl = uf->is_classdef_constructor ()
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
464 ? uf->return_list () : uf->parameter_list ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
465
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
466 if (pl && pl->size () > 0)
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
467 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
468 octave_value arg0 = pl->front ()->lvalue ().value ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
469
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
470 if (arg0.is_defined () && arg0.type_name () == "object")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
471 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
472 cdef_object arg0_obj = to_cdef (arg0);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
473
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
474 return obj.is (arg0_obj);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
475 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
476 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
477 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
478 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
479
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
480 return false;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
481 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
482
15036
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_methods (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 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
490 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
491
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
492 retval(0) = cls.get_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
493 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
494
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
495 return retval;
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 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
499 class_get_superclasses (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
502
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
503 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
504 && args(0).class_name () == "meta.class")
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 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
507
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
508 Cell classes = cls.get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
509
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
510 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
511 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
512
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
513 return retval;
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 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
517 class_get_inferiorclasses (const octave_value_list& args, int /* nargout */)
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 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
520
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
521 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
522 && args(0).class_name () == "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
523 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
524 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
525
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
526 Cell classes = cls.get ("InferiorClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
527
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
528 retval(0) = to_ov (lookup_classes (classes));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
529 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
530
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_fromName (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
536 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
537 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
538
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
539 if (args.length () == 1)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
540 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
541 std::string name = args(0).string_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
542
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
543 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
544 retval(0) = to_ov (lookup_class (name));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
545 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
546 error ("fromName: invalid class name, expected a string value");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
547 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
548 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
549 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
550
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
551 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
552 }
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 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
555 class_fevalStatic (const octave_value_list& args, int nargout)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
556 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
557 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
558
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
559 if (args.length () > 1 && args(0).type_name () == "object")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
560 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
561 cdef_class cls (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
562
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
563 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
564 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
565 std::string meth_name = args(1).string_value ();
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
566
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
567 if (! error_state)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
568 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
569 cdef_method meth = cls.find_method (meth_name);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
570
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
571 if (meth.ok ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
572 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
573 if (meth.is_static ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
574 retval = meth.execute (args.splice (0, 2), nargout,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
575 true, "fevalStatic");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
576 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
577 error ("fevalStatic: method `%s' is not static",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
578 meth_name.c_str ());
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
579 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
580 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
581 error ("fevalStatic: method not found: %s", meth_name.c_str ());
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
582 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
583 else
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
584 error ("fevalStatic: invalid method name, expected a string value");
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
585 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
586 error ("fevalStatic: invalid object, expected a meta.class object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
587 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
588 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
589 error ("fevalStatic: invalid arguments");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
590
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
591 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
592 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
593
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
594 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
595 class_getConstant (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
596 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
597 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
598
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
599 if (args.length () == 2 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
600 && args(0).class_name () == "meta.class")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
601 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
602 cdef_class cls = to_cdef (args(0));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
603
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
604 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
605 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
606 std::string prop_name = args(1).string_value ();
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
607
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
608 if (! error_state)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
609 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
610 cdef_property prop = cls.find_property (prop_name);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
611
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
612 if (prop.ok ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
613 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
614 if (prop.is_constant ())
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
615 retval(0) = prop.get_value (true, "getConstant");
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
616 else
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
617 error ("getConstant: property `%s' is not constant",
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
618 prop_name.c_str ());
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
619 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
620 else
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
621 error ("getConstant: property not found: %s",
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
622 prop_name.c_str ());
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
623 }
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
624 else
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
625 error ("getConstant: invalid property name, expected a string value");
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
626 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
627 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
628 error ("getConstant: invalid object, expected a meta.class object");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
629 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
630 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
631 error ("getConstant: invalid arguments");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
632
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
633 return retval;
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
636 #define META_CLASS_CMP(OP, CLSA, CLSB, FUN) \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
637 static octave_value_list \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
638 class_ ## OP (const octave_value_list& args, int /* nargout */) \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
639 { \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
640 octave_value_list retval; \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
641 \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
642 if (args.length () == 2 \
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
643 && args(0).type_name () == "object" \
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
644 && args(1).type_name () == "object" \
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
645 && args(0).class_name () == "meta.class" \
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
646 && args(1).class_name () == "meta.class") \
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
647 { \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
648 cdef_class clsa = to_cdef (args(0)); \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
649 \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
650 cdef_class clsb = to_cdef (args(1)); \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
651 \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
652 if (! error_state) \
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
653 retval(0) = FUN (CLSA, CLSB); \
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
654 else \
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
655 error (#OP ": invalid objects, expected meta.class objects"); \
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
656 } \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
657 else \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
658 error (#OP ": invalid arguments"); \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
659 \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
660 return retval; \
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
661 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
662
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
663 META_CLASS_CMP (lt, clsb, clsa, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
664 META_CLASS_CMP (le, clsb, clsa, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
665 META_CLASS_CMP (gt, clsa, clsb, is_strict_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
666 META_CLASS_CMP (ge, clsa, clsb, is_superclass)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
667 META_CLASS_CMP (eq, clsa, clsb, operator==)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
668 META_CLASS_CMP (ne, clsa, clsb, operator!=)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
669
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
670 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
671 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
672 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
673 octave_value_list retval;
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 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
676 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
677 cdef_property prop (to_cdef (args(0)));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
678
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
679 retval(0) = prop.get ("DefaultValue");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
680
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
681 if (! retval(0).is_defined ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
682 error_with_id ("Octave:class:NotDefaultDefined",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
683 "no default value for property `%s'",
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
684 prop.get_name ().c_str ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
685 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
686
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
687 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
688 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
689
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
690 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
691 handle_delete (const octave_value_list& /* args */, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
692 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
693 octave_value_list retval;
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 // FIXME: implement this
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 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
698 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
699
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
700 static cdef_class
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
701 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
702 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
703 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
704 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
705
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
706 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
707 cls.put ("Abstract", false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
708 cls.put ("ConstructOnLoad", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
709 cls.put ("ContainingPackage", Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
710 cls.put ("Description", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
711 cls.put ("DetailedDescription", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
712 cls.put ("Events", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
713 cls.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
714 cls.put ("InferiorClasses", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
715 cls.put ("Methods", Cell ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
716 cls.put ("Properties", Cell ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
717 cls.put ("Sealed", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
718
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
719 if (name == "handle")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
720 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
721 cls.put ("HandleCompatible", true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
722 cls.mark_as_handle_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
723 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
724 else if (super_list.empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
725 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
726 cls.put ("HandleCompatible", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
727 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
728 else
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
729 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
730 bool all_handle_compatible = true;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
731 bool has_handle_class = false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
732
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
733 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
734 it != super_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
735 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
736 all_handle_compatible = all_handle_compatible
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
737 && it->get ("HandleCompatible").bool_value ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
738 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
739 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
740
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
741 if (has_handle_class && ! all_handle_compatible)
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
742 error ("%s: cannot mix handle and non-HandleCompatible classes",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
743 name.c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
744 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
745 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
746 cls.put ("HandleCompatible", all_handle_compatible);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
747 if (has_handle_class)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
748 cls.mark_as_handle_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
749 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
750 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
751
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
752 if (error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
753 return cdef_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
754
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
755 if (! name.empty ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
756 cdef_manager::register_class (cls);
15036
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 return cls;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
759 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
760
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
761 static cdef_class
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
762 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
763 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
764 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
765 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
766
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
767 static cdef_class
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
768 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
769 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
770 cdef_class cls = make_class (name, super);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
771
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
772 cls.put ("Sealed", true);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
773 cls.mark_as_meta_class ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
774
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
775 return cls;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
776 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
777
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
778 static cdef_property
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
779 make_property (const cdef_class& cls, const std::string& name,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
780 const octave_value& get_method = Matrix (),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
781 const std::string& get_access = "public",
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
782 const octave_value& set_method = Matrix (),
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
783 const std::string& set_access = "public")
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
784 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
785 cdef_property prop (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
786
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
787 prop.set_class (cdef_class::meta_property ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
788 prop.put ("Description", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
789 prop.put ("DetailedDescription", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
790 prop.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
791 prop.put ("Constant", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
792 prop.put ("GetAccess", get_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
793 prop.put ("SetAccess", set_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
794 prop.put ("Dependent", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
795 prop.put ("Transient", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
796 prop.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
797 prop.put ("GetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
798 prop.put ("SetObservable", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
799 prop.put ("GetMethod", get_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
800 prop.put ("SetMethod", set_method);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
801 prop.put ("DefiningClass", to_ov (cls));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
802 prop.put ("DefaultValue", octave_value ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
803 prop.put ("HasDefault", false);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
804
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
805 std::string class_name = cls.get_name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
806
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
807 if (! get_method.is_empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
808 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
809 if (! set_method.is_empty ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
810 make_function_of_class (class_name, set_method);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
811
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
812 return prop;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
813 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
814
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
815 inline cdef_property
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
816 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
817 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
818 return make_property (cls, name, Matrix (), "public", Matrix (), "private");
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
821 static cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
822 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
823 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
824 bool is_static = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
825 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
826 cdef_method meth (name);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
827
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
828 meth.set_class (cdef_class::meta_method ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
829 meth.put ("Abstract", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
830 meth.put ("Access", m_access);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
831 meth.put ("DefiningClass", to_ov (cls));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
832 meth.put ("Description", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
833 meth.put ("DetailedDescription", std::string ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
834 meth.put ("Hidden", false);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
835 meth.put ("Sealed", true);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
836 meth.put ("Static", is_static);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
837
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
838 if (fcn.is_defined ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
839 make_function_of_class (cls, fcn);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
840
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
841 meth.set_function (fcn);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
842
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
843 if (is_dummy_method (fcn))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
844 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
845
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
846 return meth;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
847 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
848
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
849 inline cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
850 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
851 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
852 bool is_static = false)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
853 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
854 octave_value fcn (new octave_builtin (ff, name));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
855
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
856 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
857 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
858
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
859 static cdef_package
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
860 make_package (const std::string& nm,
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
861 const std::string& parent = std::string ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
862 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
863 cdef_package pack (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
864
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
865 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
866 if (parent.empty ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
867 pack.put ("ContainingPackage", Matrix ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
868 else
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
869 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
870
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
871 if (! nm.empty ())
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
872 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
873
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
874 return pack;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
875 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
876
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
877 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
878
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
879
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
880 int octave_classdef::t_id (-1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
881
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
882 const std::string octave_classdef::t_name ("object");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
883
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
884 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
885 octave_classdef::register_type (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
886 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
887 t_id = octave_value_typeinfo::register_type
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
888 (octave_classdef::t_name, "<unknown>",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
889 octave_value (new octave_classdef ()));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
890 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
891
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
892 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
893 octave_classdef::subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
894 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
895 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
896 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
897 size_t skip = 0;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
898 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
899
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
900 cdef_class cls = object.get_class ();
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
901
18316
ff311e5ff6d8 Don't call classdef-overloaded subsref from builtin calls.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18314
diff changeset
902 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
903 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
904 cdef_method meth = cls.find_method ("subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
905
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
906 if (meth.ok ())
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
907 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
908 octave_value_list args;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
909
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
910 args(1) = make_idx_args (type, idx, "subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
911
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
912 if (! error_state)
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
913 {
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
914 count++;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
915 args(0) = octave_value (this);
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
916
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
917 retval = meth.execute (args, nargout, true, "subsref");
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
918 }
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
919
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
920 return retval;
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
921 }
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
922 }
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
923
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
924 // 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
925
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
926 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
927
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
928 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
929 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
930 if (type.length () > skip && idx.size () > skip)
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
931 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
932 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
933
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
934 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
935 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
936
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
937 octave_value
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
938 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
939 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
940 bool auto_add)
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
941 {
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
942 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
943 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
944
18314
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
945 // This variant of subsref is used to create temporary values when doing
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
946 // assignment with multi-level indexing. AFAIK this is only used for internal
06eb893b9db6 Implement subsref overloading in classdef.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18305
diff changeset
947 // 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
948 // 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
949
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
950 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
951
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
952 if (! error_state)
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
953 {
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
954 if (type.length () > skip && idx.size () > skip)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
955 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
956 }
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
957
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
958 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
959 }
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
960
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
961 octave_value
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
962 octave_classdef::subsasgn (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
963 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
964 const octave_value& rhs)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
965 {
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
966 octave_value retval;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
967
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
968 cdef_class cls = object.get_class ();
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
969
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
970 if (! in_class_method (cls) && ! called_from_builtin ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
971 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
972 cdef_method meth = cls.find_method ("subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
973
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
974 if (meth.ok ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
975 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
976 octave_value_list args;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
977
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
978 args(1) = make_idx_args (type, idx, "subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
979
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
980 if (! error_state)
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
981 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
982 count++;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
983 args(0) = octave_value (this);
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
984 args(2) = rhs;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
985
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
986 octave_value_list retlist;
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
987
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
988 retlist = meth.execute (args, 1, true, "subsasgn");
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
989
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
990 if (! error_state)
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
991 {
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
992 if (retlist.length () > 0)
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
993 retval = retlist(0);
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
994 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
995 error ("overloaded method `subsasgn' did not return any value");
18382
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
996 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
997 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
998 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
999 }
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
1000
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
1001 if (! error_state && ! retval.is_defined ())
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
1002 retval = object.subsasgn (type, idx, rhs);
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
1003
6e3344111522 Implement subsasgn overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18355
diff changeset
1004 return retval;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1005 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1006
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1007 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1008 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
1009 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1010 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1011 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1012 if (type.length () == 1 && type[0] == '(')
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1013 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1014 object = object.make_array ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1015
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1016 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1017 return subsasgn (type, idx, rhs);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1018 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1019 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1020 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
1021
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1022 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1023 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1024
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1025 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1026 octave_classdef::print (std::ostream& os, bool)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1027 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1028 if (! called_from_builtin ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1029 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1030 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
1031
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1032 if (meth.ok ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1033 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1034 octave_value_list args;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1035
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1036 count++;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1037 args(0) = octave_value (this);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1038
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1039 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1040 meth.execute (args, 0, true, "disp");
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1041
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1042 return;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1043 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1044 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1045
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1046 print_raw (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1047 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1048
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1049 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1050 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
1051 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1052 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1053 os << "<object ";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1054 if (object.is_array ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1055 os << "array ";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1056 os << class_name () << ">";
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1057 newline (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1058 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1059
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1060 bool
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1061 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
1062 const std::string& name) const
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1063 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1064 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
1065 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1066
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1067 void
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1068 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
1069 bool print_padding)
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1070 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1071 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
1072
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1073 if (meth.ok ())
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1074 {
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1075 octave_value_list args;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1076
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1077 count++;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1078 args(0) = octave_value (this);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1079
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1080 string_vector arg_names (1);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1081
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1082 arg_names[0] = name;
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1083 args.stash_name_tags (arg_names);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1084
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1085 indent (os);
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1086 meth.execute (args, 0, true, "display");
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1087 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1088 else
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1089 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
1090 }
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18397
diff changeset
1091
19137
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1092 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1093 octave_classdef::is_instance_of (const std::string& cls_name) const
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1094 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1095 cdef_class cls = lookup_class (cls_name, false, false);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1096
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1097 if (cls.ok ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1098 return is_superclass (cls, object.get_class ());
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1099
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1100 return false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1101 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19065
diff changeset
1102
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1103 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1104
15986
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1105 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
1106 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1107 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
1108 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
1109 : 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
1110
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
1111 ~octave_classdef_meta (void)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1112 { object.meta_release (); }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1113
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1114 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
1115
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1116 octave_value_list
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1117 subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1118 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1119 int nargout)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1120 { 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
1121
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1122 octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1123 subsref (const std::string& type,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1124 const std::list<octave_value_list>& idx)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1125 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1126 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1127
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1128 retval = subsref (type, idx, 1);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1129
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1130 return (retval.length () > 0 ? retval(0) : octave_value ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1131 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1132
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1133 octave_value_list
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1134 do_multi_index_op (int nargout, const octave_value_list& idx)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1135 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1136 // Emulate ()-type meta subsref
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1137
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1138 std::list<octave_value_list> l (1, idx);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1139 std::string type ("(");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1140
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1141 return subsref (type, l, nargout);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1142 }
15955
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1143
837a4a9b5049 Support constructor call with no indexing syntax.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15913
diff changeset
1144 bool is_postfix_index_handled (char type) const
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1145 { 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
1146
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1147 bool
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1148 is_classdef_constructor (const std::string& cname = std::string ()) const
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1149 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1150 bool retval = false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1151
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1152 if (object.is_class ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1153 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1154 if (cname.empty ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1155 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1156 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1157 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1158 cdef_class cls (object);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1159
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1160 if (cls.get_name () == cname)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1161 retval = true;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1162 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1163 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1164
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1165 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1166 }
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18439
diff changeset
1167
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1168 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
1169 cdef_meta_object object;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1170 };
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1171
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1172 //----------------------------------------------------------------------------
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1173
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1174 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
1175 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1176 public:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1177 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
1178 : octave_function (), args (a) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1179
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1180 ~octave_classdef_superclass_ref (void) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1181
18355
9ca314e79956 Allow to call superclass constructor without arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18316
diff changeset
1182 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
1183
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1184 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1185 subsref (const std::string& type,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1186 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
1187 int nargout)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1188 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1189 size_t skip = 0;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1190 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1191
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1192 switch (type[0])
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1193 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1194 case '(':
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1195 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1196 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: 19731
diff changeset
1197 idx.front ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1198 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1199 default:
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1200 retval = do_multi_index_op (1, octave_value_list ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1201 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1202 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1203
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1204 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1205 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1206 if (type.length () > skip && idx.size () > skip
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1207 && retval.length () > 0)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1208 retval = retval(0).next_subsref (nargout, type, idx, skip);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1209 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1210
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1211 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1212 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1213
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1214 octave_value
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1215 subsref (const std::string& type,
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1216 const std::list<octave_value_list>& idx)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1217 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1218 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1219
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1220 retval = subsref (type, idx, 1);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1221
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1222 return (retval.length () > 0 ? retval(0) : octave_value ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1223 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1224
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1225 octave_value_list
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1226 do_multi_index_op (int nargout, const octave_value_list& idx)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1227 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1228 octave_value_list retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1229
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1230 std::string meth_name;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1231 bool in_constructor;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1232 cdef_class ctx;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1233
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1234 ctx = get_class_context (meth_name, in_constructor);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1235
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1236 if (! error_state && ctx.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1237 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1238 std::string mname = args(0).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1239 std::string cname = args(1).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1240
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1241 cdef_class cls = lookup_class (cname);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1242
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1243 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1244 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1245 if (in_constructor)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1246 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1247 if (is_direct_superclass (cls, ctx))
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1248 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1249 if (is_constructed_object (mname))
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1250 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1251 octave_value sym = symbol_table::varval (mname);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1252
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1253 cls.run_constructor (to_cdef_ref (sym), idx);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1254
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1255 retval(0) = sym;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1256 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1257 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1258 error ("cannot call superclass constructor with "
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1259 "variable `%s'", mname.c_str ());
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1260 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1261 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1262 error ("`%s' is not a direct superclass of `%s'",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1263 cname.c_str (), ctx.get_name ().c_str ());
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1264 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1265 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1266 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1267 if (mname == meth_name)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1268 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1269 if (is_strict_superclass (cls, ctx))
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1270 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1271 // I see 2 possible implementations here:
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1272 // 1) use cdef_object::subsref with a different class
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1273 // context; this avoids duplicating code, but
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1274 // assumes the object is always the first argument
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1275 // 2) lookup the method manually and call
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1276 // cdef_method::execute; this duplicates part of
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1277 // logic in cdef_object::subsref, but avoid the
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1278 // assumption of 1)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1279 // Not being sure about the assumption of 1), I
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1280 // go with option 2) for the time being.
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1281
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1282 cdef_method meth = cls.find_method (meth_name, false);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1283
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1284 if (meth.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1285 retval = meth.execute (idx, nargout, true,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1286 meth_name);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1287 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1288 error ("no method `%s' found in superclass `%s'",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1289 meth_name.c_str (), cname.c_str ());
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1290 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1291 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1292 error ("`%s' is not a superclass of `%s'",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1293 cname.c_str (), ctx.get_name ().c_str ());
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1294 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1295 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1296 error ("method name mismatch (`%s' != `%s')",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1297 mname.c_str (), meth_name.c_str ());
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1298 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1299 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1300 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1301 else if (! error_state)
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1302 error ("superclass calls can only occur in methods or constructors");
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1303
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1304 return retval;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1305 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1306
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1307 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1308 bool is_constructed_object (const std::string nm)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1309 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1310 octave_function *of = octave_call_stack::current ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1311
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1312 if (of->is_classdef_constructor ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1313 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1314 octave_user_function *uf = of->user_function_value (true);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1315
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1316 if (uf)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1317 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1318 tree_parameter_list *ret_list = uf->return_list ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1319
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1320 if (ret_list && ret_list->length () == 1)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1321 return (ret_list->front ()->name () == nm);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1322 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1323 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1324
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1325 return false;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1326 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1327
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1328 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1329 octave_value_list args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1330 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1331
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1332 //----------------------------------------------------------------------------
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1333
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1334 octave_map
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1335 cdef_object::map_value (void) const
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1336 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1337 octave_map retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1338
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1339 warning_with_id ("Octave:classdef-to-struct",
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1340 "struct: converting a classdef object into a struct "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1341 "overrides the access restrictions defined for properties. "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1342 "All properties are returned, including private and "
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1343 "protected ones.");
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1344
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1345 cdef_class cls = get_class ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1346
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1347 if (cls.ok ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1348 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1349 std::map<std::string, cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1350
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1351 props = cls.get_property_map (cdef_class::property_all);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1352
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1353 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: 19137
diff changeset
1354 it != props.end (); ++it)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1355 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1356 octave_value pvalue;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1357
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1358 if (is_array ())
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1359 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1360 Array<cdef_object> a_obj = array_value ();
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1361
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1362 Cell cvalue (a_obj.dims ());
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1363
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1364 for (octave_idx_type i = 0; i < a_obj.numel (); i++)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1365 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1366 cvalue (i) = it->second.get_value (a_obj(i), false);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1367
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1368 if (error_state)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1369 break;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1370 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1371
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1372 if (! error_state)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1373 retval.setfield (it->first, cvalue);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1374 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1375 else
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1376 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1377 Cell cvalue (dim_vector (1, 1),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1378 it->second.get_value (*this, false));
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1379
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1380 if (! error_state)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1381 retval.setfield (it->first, cvalue);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1382 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1383
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1384 if (error_state)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1385 break;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1386 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1387 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1388
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1389 return retval;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1390 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
1391
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1392 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1393 cdef_object_rep::map_keys (void) const
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 cdef_class cls = get_class ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1396
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1397 if (cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1398 return cls.get_names ();
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
1399
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1400 return string_vector ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1401 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1402
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1403 octave_value_list
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1404 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
1405 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
1406 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
1407 const cdef_class& context, bool auto_add)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1408 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1409 skip = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1410
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1411 cdef_class cls = (context.ok () ? context : get_class ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1412
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1413 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1414
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1415 if (! cls.ok ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1416 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1417
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1418 switch (type[0])
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1419 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1420 case '.':
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1421 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1422 std::string name = (idx.front ())(0).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1423
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1424 cdef_method meth = cls.find_method (name);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1425
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1426 if (meth.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1427 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1428 int _nargout = (type.length () > 2 ? 1 : nargout);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1429
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1430 octave_value_list args;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1431
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1432 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1433
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1434 if (type.length () > 1 && type[1] == '(')
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1435 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1436 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: 19731
diff changeset
1437
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1438 args = *++it;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1439
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1440 skip++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1441 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1442
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1443 if (meth.is_static ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1444 retval = meth.execute (args, _nargout, true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1445 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1446 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1447 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1448 retval = meth.execute (cdef_object (this), args, _nargout,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1449 true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1450 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1451 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1452
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1453 if (skip == 0 && ! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1454 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1455 cdef_property prop = cls.find_property (name);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1456
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1457 if (prop.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1458 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1459 if (prop.is_constant ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1460 retval(0) = prop.get_value (true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1461 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1462 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1463 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1464 retval(0) = prop.get_value (cdef_object (this),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1465 true, "subsref");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1466 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1467
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1468 skip = 1;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1469 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1470 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1471 error ("subsref: unknown method or property: %s", name.c_str ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1472 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1473 break;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1474 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1475
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1476 case '(':
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1477 {
20224
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1478 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: 20160
diff changeset
1479
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1480 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1481 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1482
20224
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1483 if (ival.empty ())
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1484 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1485 skip++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1486 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: 20160
diff changeset
1487 }
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1488 else
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1489 {
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1490 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: 20160
diff changeset
1491
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1492 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: 20160
diff changeset
1493
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1494 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: 20160
diff changeset
1495
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1496 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: 20160
diff changeset
1497 }
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1498 }
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1499 break;
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1500
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1501 default:
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1502 error ("object cannot be indexed with `%c'", type[0]);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1503 break;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1504 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1505
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1506 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1507 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1508
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1509 octave_value
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1510 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
1511 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
1512 const octave_value& rhs)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1513 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1514 octave_value retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1515
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1516 cdef_class cls = get_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1517
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1518 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1519 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1520 case '.':
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1521 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1522 std::string name = (idx.front ())(0).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1523
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1524 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1525 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1526 cdef_property prop = cls.find_property (name);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1527
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1528 if (prop.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1529 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1530 if (prop.is_constant ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1531 error ("subsasgn: cannot assign constant property: %s",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1532 name.c_str ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1533 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1534 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1535 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1536
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1537 cdef_object obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1538
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1539 if (type.length () == 1)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1540 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1541 prop.set_value (obj, rhs, true, "subsasgn");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1542
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1543 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1544 retval = to_ov (obj);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1545 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1546 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1547 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1548 octave_value val =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1549 prop.get_value (obj, true, "subsasgn");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1550
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1551 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1552 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1553 std::list<octave_value_list> args (idx);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1554
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1555 args.erase (args.begin ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1556
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1557 val = val.assign (octave_value::op_asn_eq,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1558 type.substr (1), args, rhs);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1559
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1560 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1561 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1562 if (val.class_name () != "object"
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1563 || ! to_cdef (val).is_handle_object ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1564 prop.set_value (obj, val, true, "subsasgn");
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1565
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1566 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1567 retval = to_ov (obj);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1568 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1569 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1570 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1571 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1572 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1573 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1574 error ("subsasgn: unknown property: %s", name.c_str ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1575 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1576 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1577 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1578
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1579 case '(':
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1580 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1581 refcount++;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1582
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1583 cdef_object this_obj (this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1584
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1585 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: 19731
diff changeset
1586
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1587 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: 19731
diff changeset
1588
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1589 new_obj.set_class (get_class ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1590
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1591 octave_value tmp = new_obj.subsasgn (type, idx, rhs);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1592
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1593 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1594 retval = tmp;
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1595 }
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1596 break;
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1597
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1598 default:
16694
50b37deadb66 Promote scalar object to array for '(' idnex assignment.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16692
diff changeset
1599 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
1600 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1601 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1602
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1603 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1604 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1605
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1606 void
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1607 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
1608 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1609 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
1610
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1611 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
1612
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1613 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1614 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1615 std::list<cdef_class> supcls_list = lookup_classes (supcls);
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1616
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1617 if (! error_state)
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1618 ctor_list[cls] = supcls_list;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1619 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1620 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1621
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1622 octave_value_list
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1623 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
1624 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1625 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
1626 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
1627 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1628 octave_value_list retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1629
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1630 skip = 1;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1631
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1632 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1633 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1634 case '(':
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1635 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1636 const octave_value_list& ival = idx.front ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1637
20160
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20087
diff changeset
1638 if (ival.empty ())
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20087
diff changeset
1639 {
20224
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1640 refcount++;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1641 retval(0) = to_ov (cdef_object (this));
20160
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20087
diff changeset
1642 break;
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20087
diff changeset
1643 }
274b52724931 Stop segfault when using empty indexing of a classdef object.
Rik <rik@octave.org>
parents: 20087
diff changeset
1644
20224
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1645 bool is_scalar = true;
b2532deba721 Return copy of class object when using null indexing (bug #44940).
John W. Eaton <jwe@octave.org>
parents: 20160
diff changeset
1646 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: 20160
diff changeset
1647
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1648 for (int i = 0; ! error_state && i < ival.length (); i++)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1649 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1650 iv(i) = ival(i).index_vector ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1651 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1652 is_scalar = is_scalar && iv(i).is_scalar ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1653 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1654
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1655 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1656 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1657 Array<cdef_object> ires = array.index (iv, auto_add);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1658
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1659 if (! error_state)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1660 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1661 // If resizing is enabled (auto_add = true), it's possible
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1662 // indexing was out-of-bound and the result array contains
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1663 // invalid cdef_objects.
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1664
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1665 if (auto_add)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1666 fill_empty_values (ires);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1667
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1668 if (is_scalar)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1669 retval(0) = to_ov (ires(0));
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1670 else
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1671 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1672 cdef_object array_obj (new cdef_object_array (ires));
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1673
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1674 array_obj.set_class (get_class ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1675
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1676 retval(0) = to_ov (array_obj);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1677 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1678 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1679 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1680 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1681 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1682
16692
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1683 case '.':
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1684 if (type.size () == 1 && idx.size () == 1)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1685 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1686 Cell c (dims ());
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1687
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1688 octave_idx_type n = array.numel ();
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1689
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1690 // dummy variables
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1691 size_t dummy_skip;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1692 cdef_class dummy_cls;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1693
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1694 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
1695 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1696 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
1697 dummy_cls);
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1698
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1699 if (! error_state)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1700 {
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1701 if (r.length () > 0)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1702 c(i) = r(0);
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1703 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1704 else
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1705 break;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1706 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1707
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1708 if (! error_state)
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1709 retval(0) = octave_value (c, true);
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1710
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1711 break;
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1712 }
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1713 // fall through "default"
b9833510355d Add object array property indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16691
diff changeset
1714
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1715 default:
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1716 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: 20228
diff changeset
1717 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1718 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1719 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1720
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1721 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1722 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1723
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1724 octave_value
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1725 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
1726 const std::list<octave_value_list>& idx,
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1727 const octave_value& rhs)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1728 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1729 octave_value retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1730
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1731 switch (type[0])
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1732 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1733 case '(':
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1734 if (type.length () == 1)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1735 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1736 cdef_object rhs_obj = to_cdef (rhs);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1737
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1738 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1739 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1740 if (rhs_obj.get_class () == get_class ())
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 const octave_value_list& ival = idx.front ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1743 bool is_scalar = true;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1744 Array<idx_vector> iv (dim_vector (1, ival.length ()));
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1745
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1746 for (int i = 0; ! error_state && i < ival.length (); i++)
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 iv(i) = ival(i).index_vector ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1749 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1750 is_scalar = is_scalar && iv(i).is_scalar ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1751 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1752
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1753 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1754 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1755 Array<cdef_object> rhs_mat;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1756
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1757 if (! rhs_obj.is_array ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1758 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1759 rhs_mat = Array<cdef_object> (dim_vector (1, 1));
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1760 rhs_mat(0) = rhs_obj;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1761 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1762 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1763 rhs_mat = rhs_obj.array_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1764
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1765 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1766 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1767 octave_idx_type n = array.numel ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1768
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1769 array.assign (iv, rhs_mat, cdef_object ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1770
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1771 if (! error_state)
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 if (array.numel () > n)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1774 fill_empty_values ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1775
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1776 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1777 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1778 refcount++;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1779 retval = to_ov (cdef_object (this));
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1780 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1781 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1782 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1783 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1784 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1785 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1786 error ("can't assign %s object into array of %s objects.",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1787 rhs_obj.class_name ().c_str (),
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1788 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1789 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1790 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1791 else
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1792 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1793 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
1794
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1795 bool is_scalar = true;
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1796
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1797 Array<idx_vector> iv (dim_vector (1, ival.length ()));
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1798
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1799 for (int i = 0; ! error_state && i < ival.length (); i++)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1800 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1801 iv(i) = ival(i).index_vector ();
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1802
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1803 if (! error_state)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1804 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1805 is_scalar = is_scalar && iv(i).is_scalar ();
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1806
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1807 if (! is_scalar)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1808 error ("subsasgn: invalid indexing for object array "
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1809 "assignment, the index must reference a single "
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1810 "object in the array.");
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1811 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1812 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1813
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1814 if (! error_state)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1815 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1816 Array<cdef_object> a = array.index (iv, true);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1817
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1818 if (a.numel () != 1)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1819 error ("subsasgn: invalid indexing for object array "
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1820 "assignment");
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1821
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1822 if (! error_state)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1823 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1824 cdef_object obj = a(0);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1825
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1826 int ignore_copies = 0;
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1827
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1828 // If the object in 'a' is not valid, this means the index
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1829 // was out-of-bound and we need to create a new object.
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1830
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1831 if (! obj.ok ())
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1832 obj = get_class ().construct_object (octave_value_list ());
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1833 else
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1834 // Optimize the subsasgn call to come. There are 2 copies
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1835 // that we can safely ignore:
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1836 // - 1 in "array"
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1837 // - 1 in "a"
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1838 ignore_copies = 2;
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1839
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1840 std::list<octave_value_list> next_idx (idx);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1841
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1842 next_idx.erase (next_idx.begin ());
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1843
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1844 octave_value tmp = obj.subsasgn (type.substr (1), next_idx,
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1845 rhs, ignore_copies);
16695
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1846
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1847 if (! error_state)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1848 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1849 cdef_object robj = to_cdef (tmp);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1850
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1851 if (robj.ok ()
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1852 && ! robj.is_array ()
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1853 && robj.get_class () == get_class ())
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1854 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1855 // Small optimization, when dealing with handle
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1856 // objects, we don't need to re-assign the result
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1857 // of subsasgn back into the array.
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1858
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1859 if (! robj.is (a(0)))
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1860 {
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1861 Array<cdef_object> rhs_a (dim_vector (1, 1),
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1862 robj);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1863
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1864 octave_idx_type n = array.numel ();
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1865
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1866 array.assign (iv, rhs_a);
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1867
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1868 if (array.numel () > n)
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1869 fill_empty_values ();
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1870 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1871
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1872 refcount++;
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1873
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1874 retval = to_ov (cdef_object (this));
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1875 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1876 else
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1877 error ("subasgn: invalid assignment into array of %s "
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1878 "objects", class_name ().c_str ());
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1879 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1880 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1881 }
2823f8e3da77 Add multi-level index assignment for object array.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16694
diff changeset
1882 }
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1883 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1884
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1885 default:
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
1886 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: 20228
diff changeset
1887 class_name ().c_str ());
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1888 break;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1889 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1890
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1891 return retval;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1892 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1893
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1894 void
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1895 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
1896 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1897 cdef_class cls = get_class ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1898
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1899 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1900 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1901 cdef_object obj;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1902
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1903 int n = arr.numel ();
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1904
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1905 for (int i = 0; ! error_state && i < n; i++)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1906 {
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1907 if (! arr.xelem (i).ok ())
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1908 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1909 if (! obj.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1910 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1911 obj = cls.construct_object (octave_value_list ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1912
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1913 if (! error_state)
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1914 arr.xelem (i) = obj;
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1915 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1916 else
16696
665fa0f621cc Support combination of object array extension and multi-level indexing.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16695
diff changeset
1917 arr.xelem (i) = obj.copy ();
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1918 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1919 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1920 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
1921 }
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
1922
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1923 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1924 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
1925 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1926 return (is_constructed ()
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1927 || 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
1928 }
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1929
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1930 bool
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1931 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
1932 {
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1933 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
1934
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1935 if (is_constructed ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1936 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1937 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
1938 || it->second.empty ())
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1939 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1940
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1941 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
1942 lit != it->second.end (); ++lit)
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1943 if (! is_constructed_for (*lit))
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1944 return false;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1945
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1946 return true;
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1947 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1948
20523
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1949 void
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1950 cdef_object_scalar::mark_as_constructed (const cdef_class& cls)
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1951 {
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1952 ctor_list.erase (cls);
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1953 }
a142b62527ef Fix compilation of classdef with the clang compiler (bug #41178)
akira noda <you.akira.noda@gmail.com>
parents: 20463
diff changeset
1954
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1955 handle_cdef_object::~handle_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1956 {
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1957 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1958 std::cerr << "deleting " << get_class ().get_name ()
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1959 << " object (handle)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1960 #endif
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1961 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1962
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1963 value_cdef_object::~value_cdef_object (void)
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1964 {
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1965 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1966 std::cerr << "deleting " << get_class ().get_name ()
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1967 << " object (value)" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
1968 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1969 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1970
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1971 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: 19731
diff changeset
1972 superclasses)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1973 : 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: 19731
diff changeset
1974 object_count (0), meta (false)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
1975 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1976 put ("SuperClasses", to_ov (superclasses));
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
1977 implicit_ctor_list = superclasses;
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1978 }
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
1979
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1980 cdef_method
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1981 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
1982 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1983 method_iterator it = method_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1984
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1985 if (it == method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1986 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1987 // FIXME: look into class directory
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 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1990 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1991 cdef_method& meth = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1992
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1993 // FIXME: check if method reload needed
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1994
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1995 if (meth.ok ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
1996 return meth;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1997 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
1998
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
1999 if (! local)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2000 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2001 // Look into superclasses
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2002
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2003 Cell super_classes = get ("SuperClasses").cell_value ();
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2004
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2005 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
2006 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2007 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2008
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2009 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2010 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2011 cdef_method meth = cls.find_method (nm);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2012
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2013 if (meth.ok ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2014 return meth;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2015 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2016 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2017 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2018
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2019 return cdef_method ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2020 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2021
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2022 class ctor_analyzer : public tree_walker
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2023 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2024 public:
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2025 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
2026 : 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
2027
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2028 void visit_statement_list (tree_statement_list& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2029 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2030 for (tree_statement_list::const_iterator it = t.begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2031 ! error_state && it != t.end (); ++it)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2032 (*it)->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2033 }
15896
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 void visit_statement (tree_statement& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2036 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2037 if (t.is_expression ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2038 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2039 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2040
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2041 void visit_simple_assignment (tree_simple_assignment& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2042 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2043 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2044 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2045
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2046 void visit_multi_assignment (tree_multi_assignment& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2047 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2048 t.right_hand_side ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2049 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2050
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2051 void visit_index_expression (tree_index_expression& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2052 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2053 t.expression ()->accept (*this);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2054 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2055
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2056 void visit_funcall (tree_funcall& t)
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2057 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2058 octave_value fcn = t.function ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2059
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2060 if (fcn.is_function ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2061 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2062 octave_function *of = fcn.function_value (true);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2063
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2064 if (of)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2065 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2066 if (of->name () == "__superclass_reference__")
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2067 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2068 octave_value_list args = t.arguments ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2069
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2070 if (args(0).string_value () == obj_name)
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2071 {
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2072 std::string class_name = args(1).string_value ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2073
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2074 cdef_class cls = lookup_class (class_name, false);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2075
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2076 if (cls.ok ())
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2077 ctor_list.push_back (cls);
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2078 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2079 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2080 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2081 }
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2082 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2083
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2084 std::list<cdef_class> get_constructor_list (void) const
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2085 { return ctor_list; }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2086
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2087 // NO-OP
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2088 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
2089 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
2090 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
2091 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
2092 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
2093 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
2094 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
2095 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
2096 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
2097 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
2098 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
2099 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
2100 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
2101 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
2102 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
2103 void visit_identifier (tree_identifier&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2104 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
2105 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
2106 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
2107 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
2108 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
2109 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
2110 void visit_matrix (tree_matrix&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2111 void visit_cell (tree_cell&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2112 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
2113 void visit_constant (tree_constant&) { }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2114 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
2115 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
2116 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
2117 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
2118 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
2119 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
2120 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
2121 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
2122 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
2123 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
2124
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2125 private:
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2126 /* The name of the constructor being analyzed */
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2127 std::string who;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2128
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2129 /* The name of the first output argument of the constructor */
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2130 std::string obj_name;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2131
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2132 /* 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
2133 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
2134 };
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2135
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2136 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2137 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
2138 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2139 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
2140
15911
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
2141 member_count++;
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
2142
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2143 if (meth.is_constructor ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2144 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2145 // 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
2146 // constructors are called explicitly.
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2147
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2148 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
2149
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2150 if (of)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2151 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2152 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
2153
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2154 if (uf)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2155 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2156 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
2157 tree_statement_list *body = uf->body ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2158
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2159 if (ret_list && ret_list->size () == 1)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2160 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2161 std::string obj_name = ret_list->front ()->name ();
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2162 ctor_analyzer a (meth.get_name (), obj_name);
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2163
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2164 body->accept (a);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2165 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2166 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2167 std::list<cdef_class> explicit_ctor_list
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2168 = a.get_constructor_list ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2169
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2170 for (std::list<cdef_class>::const_iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2171 it = explicit_ctor_list.begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2172 ! error_state && it != explicit_ctor_list.end ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2173 ++it)
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2174 {
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2175 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2176 std::cerr << "explicit superclass constructor: "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2177 << it->get_name () << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2178 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2179
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2180 implicit_ctor_list.remove (*it);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2181 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2182 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2183 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2184 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2185 error ("%s: invalid constructor output arguments",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2186 meth.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2187 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2188 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2189 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2190 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2191
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2192 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2193 cdef_class::cdef_class_rep::load_all_methods (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2194 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2195 // FIXME: re-scan class directory
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
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2198 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2199 cdef_class::cdef_class_rep::get_methods (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2200 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2201 std::map<std::string,cdef_method> meths;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2202
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2203 find_methods (meths, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2204
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2205 if (! error_state)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2206 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2207 Cell c (meths.size (), 1);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2208
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2209 int idx = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2210
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2211 for (std::map<std::string,cdef_method>::const_iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2212 it = meths.begin (); it != meths.end (); ++it, ++idx)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2213 c (idx, 0) = to_ov (it->second);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2214
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2215 return c;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2216 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2217
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2218 return Cell ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2219 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2220
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2221 void
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2222 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: 19731
diff changeset
2223 cdef_method>& meths,
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2224 bool only_inherited)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2225 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2226 load_all_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2227
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2228 method_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2229
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2230 for (it = method_map.begin (); it != method_map.end (); ++it)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2231 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2232 if (! it->second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2233 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2234 std::string nm = it->second.get_name ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2235
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2236 if (meths.find (nm) == meths.end ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2237 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2238 if (only_inherited)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2239 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2240 octave_value acc = it->second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2241
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2242 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2243 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2244 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2245 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2246
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2247 meths[nm] = it->second;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2248 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2249 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2250 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2251
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2252 // Look into superclasses
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 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2255
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2256 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2257 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2258 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2259
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2260 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2261 cls.get_rep ()->find_methods (meths, true);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2262 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2263 break;
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 cdef_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2268 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
2269 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2270 property_iterator it = property_map.find (nm);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2271
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2272 if (it != property_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2273 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2274 cdef_property& prop = it->second;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2275
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2276 if (prop.ok ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2277 return prop;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2278 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2279
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2280 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2281
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2282 Cell super_classes = get ("SuperClasses").cell_value ();
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 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2285 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2286 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2287
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2288 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2289 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2290 cdef_property prop = cls.find_property (nm);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2291
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2292 if (prop.ok ())
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2293 return prop;
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2294 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2295 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2296
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2297 return cdef_property ();
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 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2301 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
2302 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2303 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
2304
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
2305 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2306 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2307
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2308 Cell
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2309 cdef_class::cdef_class_rep::get_properties (int mode)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2310 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2311 std::map<std::string,cdef_property> props;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2312
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2313 props = get_property_map (mode);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2314
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2315 if (! error_state)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2316 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2317 Cell c (props.size (), 1);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2318
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2319 int idx = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2320
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2321 for (std::map<std::string,cdef_property>::const_iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2322 it = props.begin (); it != props.end (); ++it, ++idx)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2323 c (idx, 0) = to_ov (it->second);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2324
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2325 return c;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2326 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2327
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2328 return Cell ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2329 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2330
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2331 std::map<std::string, cdef_property>
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2332 cdef_class::cdef_class_rep::get_property_map (int mode)
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2333 {
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2334 std::map<std::string,cdef_property> props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2335
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2336 find_properties (props, mode);
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2337
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2338 return props;
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2339 }
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2340
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2341 void
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2342 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: 19731
diff changeset
2343 cdef_property>& props,
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2344 int mode)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2345 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2346 property_const_iterator it;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2347
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2348 for (it = property_map.begin (); ! error_state && it != property_map.end ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2349 ++it)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2350 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2351 std::string nm = it->second.get_name ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2352
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2353 if (props.find (nm) == props.end ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2354 {
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2355 if (mode == property_inherited)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2356 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2357 octave_value acc = it->second.get ("GetAccess");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2358
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2359 if (! acc.is_string ()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2360 || acc.string_value () == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2361 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2362 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2363
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2364 props[nm] = it->second;
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2365 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2366 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2367
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2368 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2369
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2370 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2371
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2372 for (int i = 0; ! error_state && i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2373 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2374 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2375
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2376 if (! error_state)
19218
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2377 cls.get_rep ()->find_properties (props,
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2378 (mode == property_all ?
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2379 property_all :
e0a7718ac085 Implement calling "struct" on classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19137
diff changeset
2380 property_inherited));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2381 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2382 break;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2383 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2384 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2385
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2386 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2387 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
2388 bool all)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2389 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2390 load_all_methods ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2391
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2392 for (method_const_iterator it = method_map.begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2393 ! error_state && it != method_map.end(); ++it)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2394 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2395 if (! it->second.is_constructor ())
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2396 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2397 std::string nm = it->second.get_name ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2398
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2399 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2400 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2401 octave_value acc = it->second.get ("Access");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2402
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2403 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2404 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2405 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2406 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2407
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2408 names.insert (nm);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2409 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2410 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2411
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2412 for (property_const_iterator it = property_map.begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2413 ! error_state && it != property_map.end (); ++it)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2414 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2415 std::string nm = it->second.get_name ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2416
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2417 if (! all)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2418 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2419 octave_value acc = it->second.get ("GetAccess");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2420
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2421 if (! acc.is_string()
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2422 || acc.string_value () != "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2423 continue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2424 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2425
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2426 names.insert (nm);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2427 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2428
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2429 // Look into superclasses
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2430
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2431 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2432
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2433 for (int i = 0; ! error_state && i < super_classes.numel (); i++)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2434 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2435 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2436
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2437 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2438 cls.get_rep ()->find_names (names, all);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2439 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2440 break;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2441 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2442 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2443
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2444 string_vector
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2445 cdef_class::cdef_class_rep::get_names (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2446 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2447 std::set<std::string> names;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2448
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2449 find_names (names, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2450
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2451 if (! error_state)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2452 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2453 string_vector v (names.size ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2454
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2455 int idx = 0;
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2456 for (std::set<std::string>::const_iterator it = names.begin ();
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2457 it != names.end (); ++it, ++idx)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2458 v[idx] = *it;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2459
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2460 return v.sort (true);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2461 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2462
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2463 return string_vector ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2464 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2465
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2466 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2467 cdef_class::cdef_class_rep::delete_object (cdef_object obj)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2468 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2469 method_iterator it = method_map.find ("delete");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2470
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2471 if (it != method_map.end ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2472 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2473 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
2474
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2475 obj.set_class (wrap ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2476
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2477 it->second.execute (obj, octave_value_list (), 0, false);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2478
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2479 obj.set_class (cls);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2480 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2481
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2482 // FIXME: should we destroy corresponding properties here?
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2483
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2484 // Call "delete" in super classes
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2485
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2486 Cell super_classes = get ("SuperClasses").cell_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2487
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2488 for (int i = 0; i < super_classes.numel (); i++)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2489 {
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2490 cdef_class cls = lookup_class (super_classes(i));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2491
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2492 if (!error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2493 cls.delete_object (obj);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2494 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2495 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
2496
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2497 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
2498 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
2499 const std::list<octave_value_list>& idx,
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2500 int nargout)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2501 {
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2502 size_t skip = 1;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2503
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2504 octave_value_list retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2505
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2506 switch (type[0])
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2507 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2508 case '(':
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2509 // Constructor call
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2510
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2511 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2512 std::cerr << "constructor" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2513 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2514
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2515 retval(0) = construct (idx.front ());
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2516 break;
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2517
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2518 case '.':
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2519 // Static method, constant (or property?)
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2520
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2521 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2522 std::cerr << "static method/property" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2523 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2524
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2525 if (idx.front ().length () == 1)
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2526 {
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2527 std::string nm = idx.front ()(0).string_value ();
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2528
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2529 if (! error_state)
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2530 {
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2531 cdef_method meth = find_method (nm);
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2532
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2533 if (meth.ok ())
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2534 {
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2535 if (meth.is_static ())
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2536 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2537 octave_value_list args;
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2538
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2539 if (type.length () > 1 && idx.size () > 1
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2540 && type[1] == '(')
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2541 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2542 args = *(++(idx.begin ()));
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2543 skip++;
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2544 }
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2545
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2546 retval = meth.execute (args, (type.length () > skip
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2547 ? 1 : nargout), true,
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2548 "meta.class");
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2549 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2550 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2551 error ("method `%s' is not static", nm.c_str ());
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2552 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2553 else
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2554 {
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2555 cdef_property prop = find_property (nm);
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2556
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2557 if (prop.ok ())
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2558 {
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2559 if (prop.is_constant ())
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2560 retval(0) = prop.get_value (true, "meta.class");
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2561 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2562 error ("property `%s' is not constant", nm.c_str ());
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2563 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2564 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2565 error ("no such method or property `%s'", nm.c_str ());
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2566 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2567 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2568 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2569 error ("invalid meta.class indexing, expected a method or property name");
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2570 }
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2571 else
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2572 error ("invalid meta.class indexing");
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2573 break;
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2574
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2575 default:
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2576 error ("invalid meta.class indexing");
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2577 break;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2578 }
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 (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2581 {
15956
d8553705f8f0 Support calling static methods and getting constant properties.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15955
diff changeset
2582 if (type.length () > skip && idx.size () > skip && ! retval.empty ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
2583 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
2584 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2585
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2586 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2587 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2588
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2589 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
2590 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
2591 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
2592 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
2593 }
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2594
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
2595 void
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2596 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
2597 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2598 // Populate the object with default property values
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2599
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2600 std::list<cdef_class> super_classes = lookup_classes (
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2601 get ("SuperClasses").cell_value ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2602
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2603 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2604 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2605 for (std::list<cdef_class>::iterator it = super_classes.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2606 ! error_state && it != super_classes.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2607 it->initialize_object (obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2608
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2609 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2610 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2611 for (property_const_iterator it = property_map.begin ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2612 ! error_state && it != property_map.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2613 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2614 if (! it->second.get ("Dependent").bool_value ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2615 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2616 octave_value pvalue = it->second.get ("DefaultValue");
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 if (pvalue.is_defined ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2619 obj.put (it->first, pvalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2620 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2621 obj.put (it->first, octave_value (Matrix ()));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2622 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2623 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2624
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2625 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2626 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2627 refcount++;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2628 obj.mark_for_construction (cdef_class (this));
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2629 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2630 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2631 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2632 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2633
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2634 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2635 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
2636 const octave_value_list& args)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2637 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2638 octave_value_list empty_args;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2639
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2640 for (std::list<cdef_class>::const_iterator it = implicit_ctor_list.begin ();
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2641 ! error_state && it != implicit_ctor_list.end (); ++it)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2642 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2643 cdef_class supcls = lookup_class (*it);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2644
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2645 if (! error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2646 supcls.run_constructor (obj, empty_args);
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2647 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2648
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2649 if (error_state)
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2650 return;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2651
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2652 std::string cls_name = get_name ();
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2653 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
2654
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2655 cdef_method ctor = find_method (ctor_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2656
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2657 if (ctor.ok ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2658 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2659 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
2660 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
2661
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2662 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
2663 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
2664
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2665 if (! error_state)
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
2666 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2667 if (ctor_retval.length () == 1)
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2668 obj = to_cdef (ctor_retval(0));
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2669 else
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2670 {
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2671 error ("%s: invalid number of output arguments for classdef constructor",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2672 ctor_name.c_str ());
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
2673 return;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2674 }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
2675 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2676 }
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2677
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
2678 obj.mark_as_constructed (wrap ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2679 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2680
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2681 octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2682 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
2683 {
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2684 cdef_object obj = construct_object (args);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2685
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2686 if (! error_state && obj.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2687 return to_ov (obj);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2688
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2689 return octave_value ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2690 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2691
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2692 cdef_object
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2693 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
2694 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2695 if (! is_abstract ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2696 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2697 cdef_object obj;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2698
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2699 if (is_meta_class ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2700 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2701 // This code path is only used to create empty meta objects
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2702 // as filler for the empty values within a meta object array.
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2703
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2704 cdef_class this_cls = wrap ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2705
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2706 static cdef_object empty_class;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2707
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2708 if (this_cls == cdef_class::meta_class ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2709 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2710 if (! empty_class.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2711 empty_class = make_class ("", std::list<cdef_class> ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2712 obj = empty_class;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2713 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2714 else if (this_cls == cdef_class::meta_property ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2715 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2716 static cdef_property empty_property;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2717
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2718 if (! empty_class.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2719 empty_class = make_class ("", std::list<cdef_class> ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2720 if (! empty_property.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2721 empty_property = make_property (empty_class, "");
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2722 obj = empty_property;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2723 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2724 else if (this_cls == cdef_class::meta_method ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2725 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2726 static cdef_method empty_method;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2727
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2728 if (! empty_class.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2729 empty_class = make_class ("", std::list<cdef_class> ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2730 if (! empty_method.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2731 empty_method = make_method (empty_class, "", octave_value ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2732 obj = empty_method;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2733 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2734 else if (this_cls == cdef_class::meta_package ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2735 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2736 static cdef_package empty_package;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2737
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2738 if (! empty_package.ok ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2739 empty_package = make_package ("");
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2740 obj = empty_package;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2741 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2742 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2743 panic_impossible ();
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2744
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2745 return obj;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2746 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2747 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2748 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2749 if (is_handle_class ())
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2750 obj = cdef_object (new handle_cdef_object ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2751 else
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2752 obj = cdef_object (new value_cdef_object ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2753 obj.set_class (wrap ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2754
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2755 initialize_object (obj);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2756
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2757 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2758 {
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2759 run_constructor (obj, args);
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2760
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2761 if (! error_state)
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2762 return obj;
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2763 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2764 }
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2765 }
15870
2b6fe094e615 Implement embryonic value-class semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15869
diff changeset
2766 else
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2767 error ("cannot instantiate object for abstract class `%s'",
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2768 get_name ().c_str ());
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2769
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
2770 return cdef_object ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2771 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2772
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2773 static octave_value
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2774 compute_attribute_value (tree_classdef_attribute* t)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2775 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2776 if (t->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2777 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2778 if (t->expression ()->is_identifier ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2779 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2780 std::string s = t->expression ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2781
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2782 if (s == "public")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2783 return std::string ("public");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2784 else if (s == "protected")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2785 return std::string ("protected");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2786 else if (s == "private")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2787 return std::string ("private");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2788 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2789
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2790 return t->expression ()->rvalue1 ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2791 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2792 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2793 return octave_value (true);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2794 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2795
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2796 template<class T>
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2797 static std::string
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2798 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
2799 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2800 if (v.is_string ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2801 return v.string_value ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2802 else if (t->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2803 return t->expression ()->original_text ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2804 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2805 return std::string ("true");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2806 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2807
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2808 cdef_class
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2809 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
2810 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
2811 cdef_class retval;
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2812 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
2813
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2814 // Class creation
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2815
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2816 class_name = full_class_name = t->ident ()->name ();
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2817 if (! t->package_name ().empty ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2818 full_class_name = t->package_name () + "." + full_class_name;
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2819
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2820 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2821 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: 18726
diff changeset
2822 #endif
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2823
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2824 std::list<cdef_class> slist;
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 if (t->superclass_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2827 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2828 for (tree_classdef_superclass_list::iterator it =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2829 t->superclass_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2830 ! error_state && it != t->superclass_list ()->end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2831 {
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
2832 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
2833
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2834 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2835 std::cerr << "superclass: " << sclass_name << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2836 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2837
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2838 cdef_class sclass = lookup_class (sclass_name);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2839
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2840 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2841 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2842 if (! sclass.get ("Sealed").bool_value ())
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
2843 slist.push_back (sclass);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2844 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2845 {
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2846 error ("`%s' cannot inherit from `%s', because it is sealed",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
2847 full_class_name.c_str (), sclass_name.c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2848 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2849 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2850 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2851 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2852 return retval;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2853
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2854 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2855 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2856
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2857 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
2858
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2859 if (error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2860 return cdef_class ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2861
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2862 // Package owning this class
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2863
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2864 if (! t->package_name ().empty ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2865 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2866 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
2867
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2868 if (! error_state && pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2869 retval.put ("ContainingPackage", to_ov (pack));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2870 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
2871
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2872 // Class attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2873
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2874 if (t->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2875 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2876 for (tree_classdef_attribute_list::iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2877 it = t->attribute_list ()->begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2878 it != t->attribute_list ()->end ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2879 ++it)
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2880 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2881 std::string aname = (*it)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2882 octave_value avalue = compute_attribute_value (*it);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2883
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2884 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2885 std::cerr << "class attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2886 << 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: 18726
diff changeset
2887 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2888
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2889 retval.put (aname, avalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2890 }
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 tree_classdef_body* b = t->body ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2894
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2895 if (b)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2896 {
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2897 // Keep track of the get/set accessor methods. They will be used
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2898 // later on when creating properties.
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2899
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2900 std::map<std::string, octave_value> get_methods;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2901 std::map<std::string, octave_value> set_methods;
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2902
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2903 // Method blocks
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2904
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2905 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
2906
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2907 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
2908 it != mb_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2909 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2910 std::map<std::string, octave_value> amap;
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2911
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2912 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2913 std::cerr << "method block" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2914 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2915
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2916 // Method attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2917
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2918 if ((*it)->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2919 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2920 for (tree_classdef_attribute_list::iterator ait =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2921 (*it)->attribute_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2922 ait != (*it)->attribute_list ()->end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2923 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2924 std::string aname = (*ait)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2925 octave_value avalue = compute_attribute_value (*ait);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2926
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2927 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2928 std::cerr << "method attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2929 << attribute_value_to_string (*ait, avalue)
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2930 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2931 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2932
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2933 amap[aname] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2934 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2935 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2936
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2937 // Methods
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2938
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2939 if ((*it)->element_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2940 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2941 for (tree_classdef_methods_list::iterator mit =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2942 (*it)->element_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2943 mit != (*it)->element_list ()->end (); ++mit)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2944 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2945 std::string mname = mit->function_value ()->name ();
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2946 std::string mprefix = mname.substr (0, 4);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2947
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2948 if (mprefix == "get.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2949 get_methods[mname.substr (4)] =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2950 make_fcn_handle (*mit, full_class_name + ">" + mname);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2951 else if (mprefix == "set.")
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2952 set_methods[mname.substr (4)] =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2953 make_fcn_handle (*mit, full_class_name + ">" + mname);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2954 else
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2955 {
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2956 cdef_method meth = make_method (retval, mname, *mit);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2957
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2958 #if DEBUG_TRACE
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2959 std::cerr << (mname == class_name ? "constructor"
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2960 : "method")
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2961 << ": " << mname << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2962 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
2963
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2964 for (std::map<std::string, octave_value>::iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2965 ait = amap.begin (); ait != amap.end (); ++ait)
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2966 meth.put (ait->first, ait->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2967
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2968 retval.install_method (meth);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
2969 }
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2970 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2971 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2972 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
2973
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2974 if (is_at_folder)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2975 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2976 // 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
2977 // 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
2978 //
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2979 // TODO: This is an "extension" to Matlab behavior, which only
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2980 // looks in the @-folder containing the original classdef
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2981 // file. However, this is easier to implement it that way at
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2982 // the moment.
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2983
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2984 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
2985 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
2986
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2987 for (std::list<std::string>::const_iterator
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2988 it = external_methods.begin ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2989 it != external_methods.end ();
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
2990 ++it)
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2991 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2992 // TODO: should we issue a warning if the method is already
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2993 // defined in the classdef file?
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2994
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2995 if (*it != class_name
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2996 && ! 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
2997 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
2998 // 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
2999 // method is loaded.
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3000
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3001 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
3002
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3003 fcn->stash_function_name (*it);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3004
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3005 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
3006 octave_value (fcn));
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3007
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3008 retval.install_method (meth);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3009 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3010 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3011 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3012
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3013 // Property blocks
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3014
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3015 // FIXME: default property expression should be able to call static
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3016 // methods of the class being constructed. A restricted CLASSNAME
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3017 // 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
3018 // value expressions.
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3019
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3020 std::list<tree_classdef_properties_block *> pb_list
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3021 = b->properties_list ();
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 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
3024 it != pb_list.end (); ++it)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3025 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3026 std::map<std::string, octave_value> amap;
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3027
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3028 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3029 std::cerr << "property block" << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3030 #endif
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3031
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3032 // Property attributes
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3033
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3034 if ((*it)->attribute_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3035 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3036 for (tree_classdef_attribute_list::iterator ait =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3037 (*it)->attribute_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3038 ait != (*it)->attribute_list ()->end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3039 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3040 std::string aname = (*ait)->ident ()->name ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3041 octave_value avalue = compute_attribute_value (*ait);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3042
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3043 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3044 std::cerr << "property attribute: " << aname << " = "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3045 << attribute_value_to_string (*ait, avalue)
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3046 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3047 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3048
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3049 if (aname == "Access")
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3050 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3051 amap["GetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3052 amap["SetAccess"] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3053 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3054 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3055 amap[aname] = avalue;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3056 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3057 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3058
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3059 // Properties
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3060
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3061 if ((*it)->element_list ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3062 {
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3063 for (tree_classdef_property_list::iterator pit =
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3064 (*it)->element_list ()->begin ();
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3065 pit != (*it)->element_list ()->end (); ++pit)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3066 {
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3067 std::string prop_name = (*pit)->ident ()->name ();
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3068
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3069 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
3070
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3071 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3072 std::cerr << "property: " << (*pit)->ident ()->name ()
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3073 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3074 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3075
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3076 if ((*pit)->expression ())
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3077 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3078 octave_value pvalue = (*pit)->expression ()->rvalue1 ();
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3079
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3080 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3081 std::cerr << "property default: "
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3082 << attribute_value_to_string (*pit, pvalue)
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3083 << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3084 #endif
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3085
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3086 prop.put ("DefaultValue", pvalue);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3087 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3088
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3089 // Install property attributes. This is done before assigning
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3090 // the property accessors so we can do validationby using
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3091 // cdef_property methods.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3092
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3093 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
3094 ait != amap.end (); ++ait)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3095 prop.put (ait->first, ait->second);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3096
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3097 // Install property access methods, if any. Remove the
20216
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20160
diff changeset
3098 // accessor methods from the temporary storage map, so we can
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3099 // 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: 19731
diff changeset
3100 // defined property.
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3101
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3102 std::map<std::string, octave_value>::iterator git =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3103 get_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3104
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3105 if (git != get_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3106 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
3107 make_function_of_class (retval, git->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3108 prop.put ("GetMethod", git->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3109 get_methods.erase (git);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3110 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3111
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3112 std::map<std::string, octave_value>::iterator sit =
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3113 set_methods.find (prop_name);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3114
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3115 if (sit != set_methods.end ())
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3116 {
18462
00ba456b9aa8 Fix dispatch class of property accessor methods.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18441
diff changeset
3117 make_function_of_class (retval, sit->second);
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3118 prop.put ("SetMethod", sit->second);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3119 set_methods.erase (sit);
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3120 }
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3121
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3122 retval.install_property (prop);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3123 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3124 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3125 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3126 }
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3127
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3128 return retval;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3129 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
3130
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3131 octave_function*
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3132 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
3133 {
15986
14aa0b5a980c Abstract the meta-protocol layer to use it for other meta objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15968
diff changeset
3134 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
3135
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3136 return p;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3137 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3138
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3139 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
3140 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
3141 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
3142 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3143 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3144 octave_value retval;
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3145
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3146 if (do_check_access && ! check_get_access ())
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3147 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3148 gripe_property_access (who, wrap (), false);
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3149
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3150 return retval;
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3151 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3152
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3153 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3154 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3155 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
3156
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3157 if (! obj.is_partially_constructed_for (cls))
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3158 {
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3159 error ("cannot reference properties of class `%s' for non-constructed object",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3160 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3161 return retval;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3162 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3163 }
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
3164
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3165 octave_value get_fcn = get ("GetMethod");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3166
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3167 // 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
3168
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3169 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
3170 retval = obj.get (get ("Name").string_value ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3171 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3172 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3173 octave_value_list args;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3174
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3175 args(0) = to_ov (obj);
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
3176
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3177 args = execute_ov (get_fcn, args, 1);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3178
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3179 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3180 retval = args(0);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3181 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3182
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3183 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3184 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3185
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3186 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
3187 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
3188 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
3189 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3190 if (do_check_access && ! check_get_access ())
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3191 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3192 gripe_property_access (who, wrap (), false);
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3193
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3194 return 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
3195 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3196
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3197 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
3198 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3199
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3200 bool
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3201 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
3202 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3203 // FIXME: implement
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3204 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3205 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3206
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3207 void
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3208 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
3209 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
3210 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
3211 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3212 {
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3213 if (do_check_access && ! check_set_access ())
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3214 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3215 gripe_property_access (who, wrap (), true);
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3216
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3217 return;
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3218 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3219
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3220 if (! obj.is_constructed ())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3221 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3222 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
3223
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3224 if (! obj.is_partially_constructed_for (cls))
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3225 {
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3226 error ("cannot reference properties of class `%s' for non-constructed object",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3227 cls.get_name ().c_str ());
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3228 return;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3229 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3230 }
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19377
diff changeset
3231
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3232 octave_value set_fcn = get ("SetMethod");
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3233
16698
13b3b92ea99c Implement property accessors.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16696
diff changeset
3234 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
3235 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
3236 else
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3237 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3238 octave_value_list args;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3239
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3240 args(0) = to_ov (obj);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3241 args(1) = val;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3242
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3243 args = execute_ov (set_fcn, args, 1);
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3244
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3245 if (! error_state)
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3246 {
19377
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3247 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
3248 {
19377
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3249 if (args (0).is_classdef_object ())
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3250 {
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3251 cdef_object new_obj = to_cdef (args(0));
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3252
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3253 if (! error_state)
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3254 obj = new_obj;
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3255 }
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3256 else
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3257 ::warning ("set-method of property `%s' returned a non-classdef object",
eb90f921bbc0 Check return value of classdef set-method's (bug #43598)
Michael Goffioul <michael.goffioul@gmail.com>
parents: 19218
diff changeset
3258 get_name ().c_str ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3259 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3260 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3261 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3262 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3263
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3264 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
3265 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
3266 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3267 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3268
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3269 if (! error_state)
18305
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
3270 return ::check_access (cls, get ("GetAccess"), std::string (),
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
3271 get_name (), false);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3272
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3273 return false;
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3274 }
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3275
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3276 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
3277 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
3278 {
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3279 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3280
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3281 if (! error_state)
18305
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
3282 return ::check_access (cls, get ("SetAccess"), std::string (),
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
3283 get_name (), true);
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3284
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3285 return false;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3286 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3287
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3288 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3289 cdef_method::cdef_method_rep::check_method (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3290 {
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3291 if (is_external ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3292 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3293 if (is_dummy_method (function))
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3294 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3295 std::string name = get_name ();
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3296 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
3297 std::string pack_name;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3298
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3299 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
3300
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3301 if (pos != std::string::npos)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3302 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3303 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
3304 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
3305 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3306
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3307 std::string dir_name;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3308 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
3309 dir_name, pack_name);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3310
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3311 if (! file_name.empty ())
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3312 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3313 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
3314 dispatch_type,
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3315 pack_name);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3316
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3317 if (fcn)
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3318 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3319 function = octave_value (fcn);
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3320
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3321 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
3322 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3323 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3324 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3325 else
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3326 {
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3327 // 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
3328 }
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3329
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3330 if (is_dummy_method (function))
20463
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3331 error ("no definition found for method `%s' of class `%s'",
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20228
diff changeset
3332 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
3333 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3334 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3335
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3336 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3337 cdef_method::cdef_method_rep::execute (const octave_value_list& args,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3338 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
3339 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3340 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3341 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3342
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3343 if (do_check_access && ! 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
3344 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3345 gripe_method_access (who, wrap ());
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3346
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3347 return retval;
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3348 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3349
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3350 if (! get ("Abstract").bool_value ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3351 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3352 check_method ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3353
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3354 if (! error_state && function.is_defined ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3355 {
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3356 retval = execute_ov (function, args, nargout);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3357 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3358 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3359 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3360 error ("%s: cannot execute abstract method",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3361 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3362
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3363 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3364 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3365
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3366 octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3367 cdef_method::cdef_method_rep::execute (const cdef_object& obj,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3368 const octave_value_list& args,
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3369 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
3370 const std::string& who)
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3371 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3372 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3373
15968
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3374 if (do_check_access && ! 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
3375 {
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3376 gripe_method_access (who, wrap ());
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3377
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3378 return retval;
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3379 }
cdeb6eb656be Move property/method access check down to cdef_property/cdef_method classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15958
diff changeset
3380
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3381 if (! get ("Abstract").bool_value ())
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3382 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3383 check_method ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3384
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3385 if (! error_state && function.is_defined ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3386 {
18263
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3387 octave_value_list new_args;
b5be1a2aa5ab Initial implementation for classdef methods in separate files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18262
diff changeset
3388
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3389 new_args.resize (args.length () + 1);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3390
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3391 new_args(0) = to_ov (obj);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3392 for (int i = 0; i < args.length (); i++)
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3393 new_args(i+1) = args(i);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3394
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3395 retval = execute_ov (function, new_args, nargout);
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3396 }
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3397 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3398 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3399 error ("%s: cannot execute abstract method",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3400 get ("Name").string_value ().c_str ());
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3401
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3402 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3403 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3404
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3405 bool
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3406 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
3407 {
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3408 if (function.is_function())
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3409 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
3410
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3411 return false;
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3412 }
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3413
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
3414 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
3415 cdef_method::cdef_method_rep::check_access (void) const
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3416 {
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3417 cdef_class cls (to_cdef (get ("DefiningClass")));
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3418
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3419 if (! error_state)
18305
81c1edd70bfd Allow base classes to access protected members of derived classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18263
diff changeset
3420 return ::check_access (cls, get ("Access"), get_name ());
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3421
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3422 return false;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3423 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3424
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3425 octave_value_list
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3426 cdef_method::cdef_method_rep::meta_subsref
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3427 (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
3428 int nargout)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3429 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3430 octave_value_list retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3431
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3432 switch (type[0])
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3433 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3434 case '(':
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3435 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
3436 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3437
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3438 default:
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3439 error ("invalid meta.method indexing");
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3440 break;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3441 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3442
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3443 if (! error_state)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3444 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3445 if (type.length () > 1 && idx.size () > 1 && ! retval.empty ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3446 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
3447 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3448
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3449 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3450 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3451
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3452 static cdef_package
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3453 lookup_package (const std::string& name)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3454 {
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3455 return cdef_manager::find_package (name);
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3456 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3457
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3458 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3459 package_fromName (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3460 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3461 octave_value_list retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3462
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3463 if (args.length () == 1)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3464 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3465 std::string name = args(0).string_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3466
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3467 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3468 retval(0) = to_ov (lookup_package (name));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3469 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3470 error ("fromName: invalid package name, expected a string value");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3471 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3472 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3473 error ("fromName: invalid number of parameters");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3474
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3475 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3476 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3477
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3478 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3479 package_get_classes (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3480 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3481 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3482
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3483 if (args.length () == 1 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3484 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3485 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3486 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3487
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3488 retval(0) = pack.get_classes ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3489 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3490
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3491 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3492 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3493
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3494 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3495 package_get_functions (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3496 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3497 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3498
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3499 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3500 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3501 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3502 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3503
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3504 retval(0) = pack.get_functions ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3505 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3506
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3507 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3508 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3509
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3510 static octave_value_list
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3511 package_get_packages (const octave_value_list& args, int /* nargout */)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3512 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3513 octave_value_list retval (1, Matrix ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3514
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3515 if (args.length () == 0 && args(0).type_name () == "object"
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3516 && args(0).class_name () == "meta.package")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3517 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3518 cdef_package pack (to_cdef (args(0)));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3519
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3520 retval(0) = pack.get_packages ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3521 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3522
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3523 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3524 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3525
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3526 static octave_value_list
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3527 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
3528 {
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3529 std::map<std::string, cdef_package> toplevel_packages;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3530
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3531 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
3532
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3533 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
3534 false);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3535
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3536 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
3537 it != names.end (); ++it)
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3538 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
3539
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3540 Cell c (toplevel_packages.size (), 1);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3541
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3542 int i = 0;
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3543
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
3544 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: 19731
diff changeset
3545 toplevel_packages.begin ();
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3546 it != toplevel_packages.end (); ++it)
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3547 c(i++,0) = to_ov (it->second);
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3548
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3549 return octave_value_list (octave_value (c));
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3550 }
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3551
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3552 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3553 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
3554 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3555 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3556 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
3557
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3558 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3559 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3560
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3561 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3562 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
3563 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3564 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3565 function_map[nm] = fcn;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3566 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3567
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3568 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3569 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
3570 const std::string& nm)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3571 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3572 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
3573
b18b7e560236 More flexible refcount to account for owned back-references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15910
diff changeset
3574 member_count++;
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3575 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3576
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3577 template<class T1, class T2>
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3578 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3579 map2Cell (const std::map<T1, T2>& m)
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 Cell retval (1, m.size ());
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3582 int i = 0;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3583
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3584 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
3585 it != m.end (); ++it, ++i)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3586 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3587 retval(i) = to_ov (it->second);
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3588 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3589
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3590 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3591 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3592
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3593 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3594 cdef_package::cdef_package_rep::get_classes (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3595 { return map2Cell (class_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3596
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3597 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3598 cdef_package::cdef_package_rep::get_functions (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3599 { return map2Cell (function_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3600
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3601 Cell
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3602 cdef_package::cdef_package_rep::get_packages (void) const
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3603 { return map2Cell (package_map); }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3604
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3605 octave_value
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3606 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
3607 {
16684
edbb123cbe3a Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16676
diff changeset
3608 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
3609
edbb123cbe3a Correct handling of package context in symbol table.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16676
diff changeset
3610 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
3611 }
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 octave_value_list
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3614 cdef_package::cdef_package_rep::meta_subsref
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3615 (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
3616 int nargout)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3617 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3618 octave_value_list retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3619
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3620 switch (type[0])
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3621 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3622 case '.':
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3623 if (idx.front ().length () == 1)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3624 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3625 std::string nm = idx.front ()(0).string_value ();
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3626
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3627 if (! error_state)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3628 {
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3629 #if DEBUG_TRACE
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3630 std::cerr << "meta.package query: " << nm << std::endl;
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
3631 #endif
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3632
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3633 octave_value o = find (nm);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3634
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3635 if (o.is_defined ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3636 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3637 if (o.is_function ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3638 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3639 octave_function* fcn = o.function_value ();
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3640
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3641 if (! error_state)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3642 {
18439
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3643 // NOTE: the case where the package query is the last
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3644 // part of this subsref index is handled in the parse
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3645 // tree, because there is some logic to handle magic
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3646 // "end" that makes it impossible to execute the
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3647 // function call at this stage.
d5aa615dcf4c Fix package function call with magic "end" in arguments.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
3648
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
3649 if (type.size () > 1
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
3650 && ! fcn->is_postfix_index_handled (type[1]))
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3651 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3652 octave_value_list tmp_args;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3653
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3654 retval = o.do_multi_index_op (nargout,
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3655 tmp_args);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3656 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3657 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3658 retval(0) = o;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3659
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3660 if (type.size () > 1 && idx.size () > 1)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3661 retval = retval(0).next_subsref (nargout, type,
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3662 idx, 1);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3663 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3664 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3665 else if (type.size () > 1 && idx.size () > 1)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3666 retval = o.next_subsref (nargout, type, idx, 1);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3667 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3668 retval(0) = o;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3669 }
18262
69990d5edcc2 Allow to parse external methods declaration in classdef files.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17746
diff changeset
3670 else if (! error_state)
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3671 error ("member `%s' in package `%s' does not exist",
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3672 nm.c_str (), get_name ().c_str ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3673 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3674 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3675 error ("invalid meta.package indexing, expected a symbol name");
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3676 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3677 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3678 error ("invalid meta.package indexing");
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3679 break;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3680
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3681 default:
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3682 error ("invalid meta.package indexing");
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3683 break;
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
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3686 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3687 }
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 void
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3690 cdef_package::cdef_package_rep::meta_release (void)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3691 {
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3692 // 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
3693 // could still be referenced by classes or sub-packages?
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3694 // 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
3695 // match the one already referenced by those classes or
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3696 // sub-packages.
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3697
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3698 //cdef_manager::unregister_package (wrap ());
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3699 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3700
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3701 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
3702 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
3703 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
3704 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
3705
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3706 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
3707
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3708 void
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3709 install_classdef (void)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3710 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3711 octave_classdef::register_type ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3712
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3713 /* bootstrap */
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3714 cdef_class handle = make_class ("handle");
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3715 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
3716 handle.set_class (meta_class);
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3717 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
3718
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3719 /* meta classes */
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3720 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
3721 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
3722 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
3723
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3724 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
3725 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
3726
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3727 /* meta.class properties */
15913
8521321604df Initial support for object array semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15911
diff changeset
3728 meta_class.install_property (make_attribute (meta_class, "Abstract"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3729 meta_class.install_property (make_attribute (meta_class, "ConstructOnLoad"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3730 meta_class.install_property (make_property (meta_class, "ContainingPackage"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3731 meta_class.install_property (make_property (meta_class, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3732 meta_class.install_property (make_property (meta_class, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3733 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
3734 meta_class.install_property (make_attribute (meta_class, "HandleCompatible"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3735 meta_class.install_property (make_attribute (meta_class, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3736 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3737 (make_property (meta_class, "InferiorClasses",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3738 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
3739 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3740 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3741 (make_property (meta_class, "Methods",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3742 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
3743 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3744 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3745 (make_property (meta_class, "MethodList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3746 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
3747 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3748 meta_class.install_property (make_attribute (meta_class, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3749 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3750 (make_property (meta_class, "Properties",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3751 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
3752 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3753 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3754 (make_property (meta_class, "PropertyList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3755 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
3756 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3757 meta_class.install_property (make_attribute (meta_class, "Sealed"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3758 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3759 (make_property (meta_class, "SuperClasses",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3760 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
3761 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3762 meta_class.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3763 (make_property (meta_class, "SuperClassList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3764 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
3765 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3766 /* meta.class methods */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3767 meta_class.install_method (make_method (meta_class, "fromName", class_fromName,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3768 "public", true));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3769 meta_class.install_method (make_method (meta_class, "fevalStatic", class_fevalStatic,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3770 "public", false));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3771 meta_class.install_method (make_method (meta_class, "getConstant", class_getConstant,
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3772 "public", false));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3773 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
3774 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
3775 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
3776 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
3777 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
3778 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
3779
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3780 /* meta.method properties */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3781 meta_method.install_property (make_attribute (meta_method, "Abstract"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3782 meta_method.install_property (make_attribute (meta_method, "Access"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3783 meta_method.install_property (make_attribute (meta_method, "DefiningClass"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3784 meta_method.install_property (make_attribute (meta_method, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3785 meta_method.install_property (make_attribute (meta_method, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3786 meta_method.install_property (make_attribute (meta_method, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3787 meta_method.install_property (make_attribute (meta_method, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3788 meta_method.install_property (make_attribute (meta_method, "Sealed"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3789 meta_method.install_property (make_attribute (meta_method, "Static"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3790
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3791 /* meta.property properties */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3792 meta_property.install_property (make_attribute (meta_property, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3793 meta_property.install_property (make_attribute (meta_property, "Description"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3794 meta_property.install_property (make_attribute (meta_property, "DetailedDescription"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3795 meta_property.install_property (make_attribute (meta_property, "Abstract"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3796 meta_property.install_property (make_attribute (meta_property, "Constant"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3797 meta_property.install_property (make_attribute (meta_property, "GetAccess"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3798 meta_property.install_property (make_attribute (meta_property, "SetAccess"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3799 meta_property.install_property (make_attribute (meta_property, "Dependent"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3800 meta_property.install_property (make_attribute (meta_property, "Transient"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3801 meta_property.install_property (make_attribute (meta_property, "Hidden"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3802 meta_property.install_property (make_attribute (meta_property, "GetObservable"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3803 meta_property.install_property (make_attribute (meta_property, "SetObservable"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3804 meta_property.install_property (make_attribute (meta_property, "GetMethod"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3805 meta_property.install_property (make_attribute (meta_property, "SetMethod"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3806 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
3807 meta_property.install_property
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3808 (make_property (meta_property, "DefaultValue",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3809 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
3810 "public", Matrix (), "private"));
15869
5e5705b3e505 Implement some embryonic handle-classdef semantic.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15841
diff changeset
3811 meta_property.install_property (make_attribute (meta_property, "HasDefault"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3812 /* meta.property events */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3813 // FIXME: add events
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3814
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3815 /* handle methods */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3816 handle.install_method (make_method (handle, "delete", handle_delete));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3817
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3818 /* meta.package properties */
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3819 meta_package.install_property (make_attribute (meta_package, "Name"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3820 meta_package.install_property (make_property (meta_package, "ContainingPackage"));
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3821 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3822 (make_property (meta_package, "ClassList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3823 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
3824 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3825 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3826 (make_property (meta_package, "Classes",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3827 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
3828 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3829 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3830 (make_property (meta_package, "FunctionList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3831 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
3832 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3833 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3834 (make_property (meta_package, "Functions",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3835 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
3836 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3837 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3838 (make_property (meta_package, "PackageList",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3839 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
3840 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3841 meta_package.install_property
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3842 (make_property (meta_package, "Packages",
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3843 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
3844 "public", Matrix (), "private"));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3845 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
3846 "public", true));
16690
1c45e22fc444 Implement meta.package.getAllPackages() method.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16689
diff changeset
3847 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
3848 "public", true));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3849
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3850 /* create "meta" package */
15909
b8bff84022d6 Use strong reference between objects and their class.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15897
diff changeset
3851 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
3852 package_meta.install_class (meta_class, "class");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3853 package_meta.install_class (meta_property, "property");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3854 package_meta.install_class (meta_method, "method");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3855 package_meta.install_class (meta_package, "package");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3856 package_meta.install_class (meta_event, "event");
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3857 package_meta.install_class (meta_dynproperty, "dynproperty");
16689
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3858
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3859 /* install built-in classes into the symbol table */
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3860 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3861 ("meta.class", octave_value (meta_class.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3862 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3863 ("meta.method", octave_value (meta_method.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3864 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3865 ("meta.property", octave_value (meta_property.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3866 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3867 ("meta.package", octave_value (meta_package.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3868 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3869 ("meta.event", octave_value (meta_event.get_constructor_function ()));
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3870 symbol_table::install_built_in_function
04e110438873 Expose builtin meta.* classes.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16684
diff changeset
3871 ("meta.dynproperty", octave_value (meta_dynproperty.get_constructor_function ()));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3872 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
3873
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3874 //----------------------------------------------------------------------------
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3875
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3876 cdef_manager* cdef_manager::instance = 0;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3877
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3878 void
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3879 cdef_manager::create_instance (void)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3880 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3881 instance = new cdef_manager ();
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3882
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3883 if (instance)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3884 singleton_cleanup_list::add (cleanup_instance);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3885 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3886
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3887 cdef_class
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3888 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
3889 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
3890 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3891 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
3892
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3893 if (it == all_classes.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3894 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3895 if (load_if_not_found)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3896 {
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3897 octave_value ov_cls;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3898
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3899 size_t pos = name.rfind ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3900
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3901 if (pos == std::string::npos)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3902 ov_cls = symbol_table::find (name);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3903 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3904 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3905 std::string pack_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3906
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3907 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
3908
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3909 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3910 ov_cls = pack.find (name.substr (pos+1));
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3911 }
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3912
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3913 if (ov_cls.is_defined ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3914 it = all_classes.find (name);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3915 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3916 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3917
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3918 if (it == all_classes.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3919 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3920 if (error_if_not_found)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3921 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
3922 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3923 else
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3924 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3925 cdef_class cls = it->second;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3926
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3927 if (! cls.is_builtin ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3928 cls = lookup_class (cls);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3929
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3930 if (cls.ok ())
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3931 return cls;
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3932 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
3933 all_classes.erase (it);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3934 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3935
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3936 return cdef_class ();
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3937 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3938
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3939 octave_function*
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3940 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
3941 const std::string& class_name)
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3942 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3943 octave_function *retval = 0;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3944
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3945 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
3946
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3947 if (cls.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3948 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3949 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
3950
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3951 if (meth.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3952 retval = new octave_classdef_meta (meth);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3953 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3954
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3955 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3956 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3957
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3958 cdef_package
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3959 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
3960 bool error_if_not_found,
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3961 bool load_if_not_found)
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3962 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3963 cdef_package retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3964
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3965 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
3966 = all_packages.find (name);
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3967
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3968 if (it != all_packages.end ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3969 {
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3970 retval = it->second;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3971
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3972 if (! retval.ok ())
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3973 error ("invalid package `%s'", name.c_str ());
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
3974 }
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3975 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3976 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3977 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
3978 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3979 size_t pos = name.find ('.');
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3980
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3981 if (pos == std::string::npos)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3982 retval = make_package (name, std::string ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3983 else
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3984 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3985 std::string parent_name = name.substr (0, pos);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3986
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3987 retval = make_package (name, parent_name);
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3988 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3989 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3990 else if (error_if_not_found)
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3991 error ("unknown package `%s'", name.c_str ());
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3992 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3993
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3994 return retval;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3995 }
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3996
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3997 octave_function*
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
3998 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
3999 {
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
4000 octave_function* retval = 0;
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
4001
20087
8b501a0db1e9 only insert package names into loader map if package dir exists (bug #43769)
John W. Eaton <jwe@octave.org>
parents: 19898
diff changeset
4002 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
4003
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
4004 if (pack.ok ())
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16048
diff changeset
4005 retval = new octave_classdef_meta (pack);
16048
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4006
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4007 return retval;
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4008 }
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4009
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4010 //----------------------------------------------------------------------------
10142aad4b9f Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15986
diff changeset
4011
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4012 DEFUN (__meta_get_package__, args, , "")
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4013 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4014 octave_value retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4015
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4016 if (args.length () == 1)
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4017 {
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4018 std::string cname = args(0).string_value ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4019
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4020 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
4021 retval = to_ov (lookup_package (cname));
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4022 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
4023 error ("invalid package name, expected a string value");
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4024 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4025 else
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4026 print_usage ();
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4027
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4028 return retval;
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4029 }
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4030
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4031 DEFUN (__superclass_reference__, args, /* nargout */,
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
4032 "-*- texinfo -*-\n\
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4033 @deftypefn {Built-in Function} {} __superclass_reference__ ()\n\
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4034 Undocumented internal function.\n\
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4035 @end deftypefn")
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4036 {
15896
57be060d7672 Implement full object construction and superclass references.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15870
diff changeset
4037 return octave_value (new octave_classdef_superclass_ref (args));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4038 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4039
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4040 DEFUN (__meta_class_query__, args, /* nargout */,
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
4041 "-*- texinfo -*-\n\
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4042 @deftypefn {Built-in Function} {} __meta_class_query__ ()\n\
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4043 Undocumented internal function.\n\
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4044 @end deftypefn")
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4045 {
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4046 octave_value retval;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4047
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
4048 #if DEBUG_TRACE
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4049 std::cerr << "__meta_class_query__ ("
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
4050 << args(0).string_value () << ")"
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4051 << std::endl;
19065
1f36981ab323 allow debugging messages in classdef code to be disabled
John W. Eaton <jwe@octave.org>
parents: 18726
diff changeset
4052 #endif
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4053
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
4054 if (args.length () == 1)
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4055 {
18520
932aca9a7c57 Allow multi-level classdef package.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18462
diff changeset
4056 std::string cls = args(0).string_value ();
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4057
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4058 if (! error_state)
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
4059 retval = to_ov (lookup_class (cls));
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4060 else
18726
fe0e34be5576 maint: untabify recently added code files.
Rik <rik@octave.org>
parents: 18520
diff changeset
4061 error ("invalid class name, expected a string value");
15037
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4062 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4063 else
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4064 print_usage ();
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4065
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4066 return retval;
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4067 }
56b8eb7c9c04 improvements in parsing classdef
John W. Eaton <jwe@octave.org>
parents: 15036
diff changeset
4068
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4069 DEFUN (metaclass, args, /* nargout */,
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
4070 "-*- texinfo -*-\n\
15897
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4071 @deftypefn {Built-in Function} {} metaclass (obj)\n\
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4072 Returns the meta.class object corresponding to the class of @var{obj}.\n\
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4073 @end deftypefn")
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4074 {
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4075 octave_value retval;
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4076
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4077 if (args.length () == 1)
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4078 {
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4079 cdef_object obj = to_cdef (args(0));
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4080
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4081 if (! error_state)
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4082 retval = to_ov (obj.get_class ());
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4083 else
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4084 print_usage ();
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4085 }
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4086 else
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4087 print_usage ();
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4088
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4089 return retval;
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4090 }
a413c6fe1726 Add metaclass function.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 15896
diff changeset
4091
15036
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4092 /*
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4093 ;;; Local Variables: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4094 ;;; mode: C++ ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4095 ;;; End: ***
aa1f9e479c6e octave_value classdef objects
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff changeset
4096 */