Mercurial > octave-nkf
annotate libinterp/octave-value/ov-class.cc @ 17473:9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
* ov-class.cc (octave_class::reconstruct_exemplar): Don't throw error
if constructor execution fails.
(octave_class::load_ascii, octave_class::load_binary,
octave_class::load_hdf5): Attempt to handle exemplar and loadobj
method consistently.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 24 Sep 2013 16:41:20 -0400 |
parents | 94e95309710c |
children | d63878346099 |
rev | line source |
---|---|
7338 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13874
diff
changeset
|
3 Copyright (C) 2007-2012 John W. Eaton |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
7338 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7444 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
7338 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7444 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
7338 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <iostream> | |
29 | |
30 #include "Array-util.h" | |
31 #include "byte-swap.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8219
diff
changeset
|
32 #include "oct-locbuf.h" |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
33 #include "lo-mappers.h" |
7338 | 34 |
35 #include "Cell.h" | |
36 #include "defun.h" | |
37 #include "error.h" | |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
38 #include "file-ops.h" |
7338 | 39 #include "gripes.h" |
40 #include "load-path.h" | |
41 #include "ls-hdf5.h" | |
42 #include "ls-oct-ascii.h" | |
43 #include "ls-oct-binary.h" | |
44 #include "ls-utils.h" | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
45 #include "mxarray.h" |
7338 | 46 #include "oct-lvalue.h" |
47 #include "ov-class.h" | |
15812
83bf6fd9e46d
ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents:
15811
diff
changeset
|
48 #ifdef HAVE_JAVA |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
49 #include "ov-java.h" |
15812
83bf6fd9e46d
ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents:
15811
diff
changeset
|
50 #endif |
7338 | 51 #include "ov-fcn.h" |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
52 #include "ov-usr-fcn.h" |
7338 | 53 #include "pager.h" |
54 #include "parse.h" | |
55 #include "pr-output.h" | |
56 #include "toplev.h" | |
57 #include "unwind-prot.h" | |
58 #include "variables.h" | |
59 | |
60 DEFINE_OCTAVE_ALLOCATOR(octave_class); | |
61 | |
62 int octave_class::t_id (-1); | |
63 | |
64 const std::string octave_class::t_name ("class"); | |
65 | |
66 void | |
67 octave_class::register_type (void) | |
68 { | |
69 t_id = octave_value_typeinfo::register_type | |
70 (octave_class::t_name, "<unknown>", octave_value (new octave_class ())); | |
71 } | |
72 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
73 octave_class::octave_class (const octave_map& m, const std::string& id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
74 const octave_value_list& parents) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
75 : octave_base_value (), map (m), c_name (id), obsolete_copies (0) |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
76 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
77 octave_idx_type n = parents.length (); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
78 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
79 for (octave_idx_type idx = 0; idx < n; idx++) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
80 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
81 octave_value parent = parents(idx); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
82 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
83 if (! parent.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
84 error ("parents must be objects"); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
85 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
86 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
87 std::string pcnm = parent.class_name (); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
88 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
89 if (find_parent_class (pcnm)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
90 error ("duplicate class in parent tree"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
91 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
92 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
93 parent_list.push_back (pcnm); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
94 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
95 octave_idx_type nel = map.numel (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
96 octave_idx_type p_nel = parent.numel (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
97 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
98 if (nel == 0) |
13702
c7fac37a2afc
class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents:
13695
diff
changeset
|
99 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
100 if (p_nel == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
101 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
102 // No elements in MAP or the parent class object, |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
103 // so just add the field name. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
104 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
105 map.assign (pcnm, Cell (map.dims ())); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
106 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
107 else if (p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
108 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
109 if (map.nfields () == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
110 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
111 // No elements or fields in MAP, but the |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
112 // parent is class object with one element. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
113 // Resize to match size of parent class and |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
114 // make the parent a field in MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
115 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
116 map.resize (parent.dims ()); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
117 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
118 map.assign (pcnm, parent); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
119 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
120 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
121 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
122 // No elements in MAP, but we have at least |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
123 // one field. So don't resize, just add the |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
124 // field name. |
13702
c7fac37a2afc
class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents:
13695
diff
changeset
|
125 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
126 map.assign (pcnm, Cell (map.dims ())); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
127 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
128 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
129 else if (map.nfields () == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
130 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
131 // No elements or fields in MAP and more than one |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
132 // element in the parent class object, so we can |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
133 // resize MAP to match parent dimsenions, then |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
134 // distribute the elements of the parent object to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
135 // the elements of MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
136 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
137 dim_vector parent_dims = parent.dims (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
138 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
139 map.resize (parent_dims); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
140 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
141 Cell c (parent_dims); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
142 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
143 octave_map pmap = parent.map_value (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
144 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
145 std::list<std::string> plist |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
146 = parent.parent_class_name_list (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
147 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
148 for (octave_idx_type i = 0; i < p_nel; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
149 c(i) = octave_value (pmap.index (i), pcnm, plist); |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
150 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
151 map.assign (pcnm, c); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
152 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
153 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
154 error ("class: parent class dimension mismatch"); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
155 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
156 else if (nel == 1 && p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
157 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
158 // Simple assignment. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
159 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
160 map.assign (pcnm, parent); |
13702
c7fac37a2afc
class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents:
13695
diff
changeset
|
161 } |
c7fac37a2afc
class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents:
13695
diff
changeset
|
162 else |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
163 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
164 if (p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
165 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
166 // Broadcast the scalar parent class object to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
167 // each element of MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
168 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
169 Cell pcell (map.dims (), parent); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
170 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
171 map.assign (pcnm, pcell); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
172 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
173 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
174 else if (nel == p_nel) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
175 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
176 // FIXME -- is there a better way to do this? |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
177 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
178 // The parent class object has the same number of |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
179 // elements as the map we are using to create the |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
180 // new object, so distribute those elements to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
181 // each element of the new object by first |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
182 // splitting the elements of the parent class |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
183 // object into a cell array with one element per |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
184 // cell. Then do the assignment all at once. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
185 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
186 Cell c (parent.dims ()); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
187 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
188 octave_map pmap = parent.map_value (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
189 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
190 std::list<std::string> plist |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
191 = parent.parent_class_name_list (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
192 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
193 for (octave_idx_type i = 0; i < p_nel; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
194 c(i) = octave_value (pmap.index (i), pcnm, plist); |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
195 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
196 map.assign (pcnm, c); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
197 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
198 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
199 error ("class: parent class dimension mismatch"); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
200 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
201 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
202 } |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
203 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
204 |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
205 if (! error_state) |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9580
diff
changeset
|
206 symbol_table::add_to_parent_map (id, parent_list); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
207 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
208 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
209 octave_base_value * |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
210 octave_class::unique_clone (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
211 { |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
212 if (count == obsolete_copies) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
213 { |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
214 // All remaining copies are obsolete. We don't actually need to clone. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
215 count++; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
216 return this; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
217 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
218 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 { |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
220 // In theory, this shouldn't be happening, but it's here just in case. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
221 if (count < obsolete_copies) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
222 obsolete_copies = 0; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
223 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 return clone (); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
225 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
226 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
227 |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
228 std::string |
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
229 octave_class::get_current_method_class (void) |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
230 { |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
231 std::string retval = class_name (); |
9156
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
232 |
12620
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
233 if (nparents () > 0) |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
234 { |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
235 octave_function *fcn = octave_call_stack::current (); |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
236 |
12620
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
237 // Here we are just looking to see if FCN is a method or constructor |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
238 // for any class, not specifically this one. |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
239 if (fcn && (fcn->is_class_method () || fcn->is_class_constructor ())) |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
240 retval = fcn->dispatch_class (); |
6f3f18957851
ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents:
12483
diff
changeset
|
241 } |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
242 |
9156
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
243 return retval; |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
244 } |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
245 |
7338 | 246 static void |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
247 gripe_invalid_index1 (void) |
7338 | 248 { |
249 error ("invalid index for class"); | |
250 } | |
251 | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
252 static void |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
253 gripe_invalid_index_for_assignment (void) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
254 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
255 error ("invalid index for class assignment"); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
256 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
257 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
258 static void |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
259 gripe_invalid_index_type (const std::string& nm, char t) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
260 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
261 error ("%s cannot be indexed with %c", nm.c_str (), t); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
262 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
263 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
264 static void |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
265 gripe_failed_assignment (void) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
266 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
267 error ("assignment to class element failed"); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
268 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
269 |
7338 | 270 static inline octave_value_list |
271 sanitize (const octave_value_list& ovl) | |
272 { | |
273 octave_value_list retval = ovl; | |
274 | |
275 for (octave_idx_type i = 0; i < ovl.length (); i++) | |
276 { | |
277 if (retval(i).is_magic_colon ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
278 retval(i) = ":"; |
7338 | 279 } |
280 | |
281 return retval; | |
282 } | |
283 | |
284 static inline octave_value | |
285 make_idx_args (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
286 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
287 const std::string& who) |
7338 | 288 { |
289 octave_value retval; | |
290 | |
291 size_t len = type.length (); | |
292 | |
293 if (len == idx.size ()) | |
294 { | |
9774
fbf15a0f30f0
Call user-defined subsref/subsasgn with 1xN structs instead of Nx1
David Grundberg <davidg@cs.umu.se>
parents:
9767
diff
changeset
|
295 Cell type_field (1, len); |
fbf15a0f30f0
Call user-defined subsref/subsasgn with 1xN structs instead of Nx1
David Grundberg <davidg@cs.umu.se>
parents:
9767
diff
changeset
|
296 Cell subs_field (1, len); |
7338 | 297 |
298 std::list<octave_value_list>::const_iterator p = idx.begin (); | |
299 | |
300 for (size_t i = 0; i < len; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
301 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
302 char t = type[i]; |
7338 | 303 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
304 switch (t) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
305 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
306 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
307 type_field(i) = "()"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
308 subs_field(i) = Cell (sanitize (*p++)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
309 break; |
7338 | 310 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
311 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
312 type_field(i) = "{}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
313 subs_field(i) = Cell (sanitize (*p++)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
314 break; |
7338 | 315 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
316 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
317 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
318 type_field(i) = "."; |
7338 | 319 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
320 octave_value_list vlist = *p++; |
7338 | 321 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
322 if (vlist.length () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
323 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
324 octave_value val = vlist(0); |
7338 | 325 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
326 if (val.is_string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
327 subs_field(i) = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
328 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
329 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
330 error ("expecting character string argument for '.' index"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
331 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
332 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
333 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
334 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
335 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
336 error ("expecting single argument for '.' index"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
337 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
338 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
339 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
340 break; |
7338 | 341 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
342 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
343 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
344 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
345 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
346 } |
7338 | 347 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
348 octave_map m; |
7338 | 349 |
350 m.assign ("type", type_field); | |
351 m.assign ("subs", subs_field); | |
352 | |
353 retval = m; | |
354 } | |
355 else | |
356 error ("invalid index for %s", who.c_str ()); | |
357 | |
358 return retval; | |
359 } | |
360 | |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
361 Cell |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
362 octave_class::dotref (const octave_value_list& idx) |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
363 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
364 Cell retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
365 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
366 assert (idx.length () == 1); |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
367 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
368 std::string method_class = get_current_method_class (); |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
369 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
370 // Find the class in which this method resides before attempting to access |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
371 // the requested field. |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
372 |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
373 octave_base_value *obvp = find_parent_class (method_class); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
374 |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
375 if (obvp == 0) |
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
376 { |
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
377 error ("malformed class"); |
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
378 return retval; |
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
379 } |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
380 |
10932
3a778233e4fb
fix typo in 10926:f687bd17ce21
Jaroslav Hajek <highegg@gmail.com>
parents:
10926
diff
changeset
|
381 octave_map my_map = (obvp != this) ? obvp->map_value () : map; |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
382 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
383 std::string nm = idx(0).string_value (); |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
384 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
385 if (! error_state) |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
386 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
387 octave_map::const_iterator p = my_map.seek (nm); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
388 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
389 if (p != my_map.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
390 retval = my_map.contents (p); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
391 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
392 error ("class has no member '%s'", nm.c_str ()); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
393 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
394 else |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
395 gripe_invalid_index1 (); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
396 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
397 return retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
398 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
399 |
9156
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
400 static bool |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
401 called_from_builtin (void) |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
402 { |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
403 octave_function *fcn = octave_call_stack::caller (); |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
404 |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
405 // FIXME -- we probably need a better check here, or some other |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
406 // mechanism to avoid overloaded functions when builtin is used. |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
407 // For example, what if someone overloads the builtin function? |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
408 // Also, are there other places where using builtin is not properly |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
409 // avoiding dispatch? |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
410 |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
411 return (fcn && fcn->name () == "builtin"); |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
412 } |
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
413 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
414 Matrix |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
415 octave_class::size (void) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
416 { |
9792
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
417 if (in_class_method () || called_from_builtin ()) |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
418 return octave_base_value::size (); |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
419 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
420 Matrix retval (1, 2, 1.0); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
421 octave_value meth = symbol_table::find_method ("size", class_name ()); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
422 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
423 if (meth.is_defined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
424 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
425 count++; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
426 octave_value_list args (1, octave_value (this)); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
427 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
428 octave_value_list lv = feval (meth.function_value (), args, 1); |
9775
9d9f858849c7
Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents:
9774
diff
changeset
|
429 if (lv.length () > 0 && lv(0).is_matrix_type () && lv(0).dims ().is_vector ()) |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
430 retval = lv(0).matrix_value (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
431 else |
9775
9d9f858849c7
Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents:
9774
diff
changeset
|
432 error ("@%s/size: invalid return value", class_name ().c_str ()); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
433 } |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
434 else |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
435 { |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
436 dim_vector dv = dims (); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
437 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
438 int nd = dv.length (); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
439 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
440 retval.resize (1, nd); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
441 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
442 for (int i = 0; i < nd; i++) |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
443 retval(i) = dv(i); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
444 } |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
445 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
446 return retval; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
447 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
448 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
449 octave_idx_type |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
450 octave_class::numel (const octave_value_list& idx) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
451 { |
9792
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
452 if (in_class_method () || called_from_builtin ()) |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
453 return octave_base_value::numel (idx); |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
454 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
455 octave_idx_type retval = -1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
456 const std::string cn = class_name (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
457 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
458 octave_value meth = symbol_table::find_method ("numel", cn); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
459 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
460 if (meth.is_defined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
461 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
462 octave_value_list args (idx.length () + 1, octave_value ()); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
463 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
464 count++; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
465 args(0) = octave_value (this); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
466 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
467 for (octave_idx_type i = 0; i < idx.length (); i++) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
468 args(i+1) = idx(i); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
469 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
470 octave_value_list lv = feval (meth.function_value (), args, 1); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
471 if (lv.length () == 1 && lv(0).is_scalar_type ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
472 retval = lv(0).idx_type_value (true); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
473 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
474 error ("@%s/numel: invalid return value", cn.c_str ()); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
475 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
476 else |
10106
edbe47bc0f88
make numel query more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
477 retval = octave_base_value::numel (idx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
478 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
479 return retval; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
480 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
481 |
7338 | 482 octave_value_list |
483 octave_class::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
484 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
485 int nargout) |
7338 | 486 { |
487 octave_value_list retval; | |
488 | |
9156
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
489 if (in_class_method () || called_from_builtin ()) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
490 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
491 // FIXME -- this block of code is the same as the body of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
492 // octave_struct::subsref. Maybe it could be shared instead of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
493 // duplicated. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
494 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
495 int skip = 1; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
496 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
497 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
498 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
499 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
500 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
501 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
503 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
504 octave_value_list key_idx = *++p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
505 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
506 Cell tmp = dotref (key_idx); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
507 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
508 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
509 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
510 Cell t = tmp.index (idx.front ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
511 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
512 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
513 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
514 // We handled two index elements, so tell |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
515 // next_subsref to skip both of them. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
516 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
517 skip++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
518 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
520 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
521 retval(0) = octave_value (map.index (idx.front ()), |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
522 c_name, parent_list); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
523 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
524 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
525 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
526 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
527 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
528 if (map.numel () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
529 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
530 Cell t = dotref (idx.front ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
531 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
532 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
533 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
534 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
535 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
536 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
537 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
538 gripe_invalid_index_type (type_name (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
539 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
540 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
541 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
542 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
543 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
544 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
545 // FIXME -- perhaps there should be an |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
546 // octave_value_list::next_subsref member function? See also |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
547 // octave_user_function::subsref. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
548 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
549 if (idx.size () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
550 retval = retval(0).next_subsref (nargout, type, idx, skip); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
551 } |
7338 | 552 else |
553 { | |
554 octave_value meth = symbol_table::find_method ("subsref", class_name ()); | |
555 | |
556 if (meth.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
557 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
558 octave_value_list args; |
7338 | 559 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
560 args(1) = make_idx_args (type, idx, "subsref"); |
7338 | 561 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
562 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
563 return octave_value_list (); |
7338 | 564 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
565 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
566 args(0) = octave_value (this); |
7338 | 567 |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
568 // FIXME: for Matlab compatibility, let us attempt to set up a proper |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
569 // value for nargout at least in the simple case where the |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
570 // cs-list-type expression - i.e., {} or ().x, is the leading one. |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
571 // Note that Octave does not actually need this, since it will |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
572 // be able to properly react to varargout a posteriori. |
9331
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
573 bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{' |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
574 || (type.length () > 1 && type[0] == '(' |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
575 && type[1] == '.')); |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
576 |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
577 int true_nargout = nargout; |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
578 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
579 if (maybe_cs_list_query) |
9331
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
580 { |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
581 // Set up a proper nargout for the subsref call by calling numel. |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
582 octave_value_list tmp; |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
583 if (type[0] != '.') tmp = idx.front (); |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
584 true_nargout = numel (tmp); |
9331
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
585 } |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
586 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
587 retval = feval (meth.function_value (), args, true_nargout); |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
588 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
589 // Since we're handling subsref, return the list in the first value |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
590 // if it has more than one element, to be able to pass through |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
591 // rvalue1 calls. |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
592 if (retval.length () > 1) |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
593 retval = octave_value (retval, true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
594 } |
7338 | 595 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
596 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
597 if (type.length () == 1 && type[0] == '(') |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
598 retval(0) = octave_value (map.index (idx.front ()), c_name, |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
599 parent_list); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
600 else |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
601 gripe_invalid_index1 (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
602 } |
7338 | 603 } |
604 | |
605 return retval; | |
606 } | |
607 | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
608 octave_value |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
609 octave_class::numeric_conv (const Cell& val, const std::string& type) |
7338 | 610 { |
611 octave_value retval; | |
612 | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
613 if (val.length () == 1) |
7338 | 614 { |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
615 retval = val(0); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
616 |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
617 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
618 retval = octave_map (); |
7338 | 619 } |
620 else | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
621 gripe_invalid_index_for_assignment (); |
7338 | 622 |
623 return retval; | |
624 } | |
625 | |
626 octave_value | |
627 octave_class::subsasgn (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
628 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
629 const octave_value& rhs) |
7338 | 630 { |
12171
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
631 count++; |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
632 return subsasgn_common (octave_value (this), type, idx, rhs); |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
633 } |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
634 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
635 octave_value |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
636 octave_class::undef_subsasgn (const std::string& type, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
637 const std::list<octave_value_list>& idx, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
638 const octave_value& rhs) |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
639 { |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
640 // For compatibility with Matlab, pass [] as the first argument to the |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
641 // the subsasgn function when the LHS of an indexed assignment is |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
642 // undefined. |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
643 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
644 return subsasgn_common (Matrix (), type, idx, rhs); |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
645 } |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
646 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
647 octave_value |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
648 octave_class::subsasgn_common (const octave_value& obj, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
649 const std::string& type, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
650 const std::list<octave_value_list>& idx, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
651 const octave_value& rhs) |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
652 { |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
653 octave_value retval; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
654 |
9156
b2b8ed43b922
ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents:
9151
diff
changeset
|
655 if (! (in_class_method () || called_from_builtin ())) |
7338 | 656 { |
657 octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); | |
658 | |
659 if (meth.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
660 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
661 octave_value_list args; |
7338 | 662 |
9333
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
663 if (rhs.is_cs_list ()) |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
664 { |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
665 octave_value_list lrhs = rhs.list_value (); |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
666 args.resize (2 + lrhs.length ()); |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
667 for (octave_idx_type i = 0; i < lrhs.length (); i++) |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
668 args(2+i) = lrhs(i); |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
669 } |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
670 else |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
671 args(2) = rhs; |
7338 | 672 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
673 args(1) = make_idx_args (type, idx, "subsasgn"); |
7338 | 674 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
675 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
676 return octave_value_list (); |
7338 | 677 |
12171
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
678 args(0) = obj; |
7338 | 679 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
680 // Now comes the magic. Count copies with me: |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
681 // 1. myself (obsolete) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
682 // 2. the copy inside args (obsolete) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
683 // 3. the copy in method's symbol table (working) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
684 // ... possibly more (not obsolete). |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
685 // |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
686 // So we mark 2 copies as obsolete and hold our fingers crossed. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
687 // But prior to doing that, check whether the routine is amenable |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
688 // to the optimization. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
689 // It is essential that the handling function doesn't store extra |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
690 // copies anywhere. If it does, things will not break but the |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
691 // optimization won't work. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
692 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
693 octave_value_list tmp; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
694 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
695 if (obsolete_copies == 0 && meth.is_user_function () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
696 && meth.user_function_value ()->subsasgn_optimization_ok ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
697 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
698 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
699 frame.protect_var (obsolete_copies); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
700 obsolete_copies = 2; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
701 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
702 tmp = feval (meth.function_value (), args); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
703 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
704 else |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
705 tmp = feval (meth.function_value (), args); |
7338 | 706 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
707 // FIXME -- should the subsasgn method be able to return |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
708 // more than one value? |
7338 | 709 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
710 if (tmp.length () > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
711 error ("expecting single return value from @%s/subsasgn", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
712 class_name ().c_str ()); |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8782
diff
changeset
|
713 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
714 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
715 retval = tmp(0); |
7338 | 716 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
717 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
718 } |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8782
diff
changeset
|
719 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8782
diff
changeset
|
720 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
721 // Find the class in which this method resides before |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
722 // attempting to do the indexed assignment. |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
723 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
724 std::string method_class = get_current_method_class (); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
725 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
726 octave_base_value *obvp = unique_parent_class (method_class); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
727 if (obvp != this) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
728 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
729 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
730 if (obvp) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
731 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
732 obvp->subsasgn (type, idx, rhs); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
733 if (! error_state) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
734 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
735 count++; |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
736 retval = octave_value (this); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
737 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
738 else |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
739 gripe_failed_assignment (); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
740 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
741 else |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
742 error ("malformed class"); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
743 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
744 return retval; |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
745 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
746 |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
747 // FIXME -- this block of code is the same as the body of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
748 // octave_struct::subsasgn. Maybe it could be shared instead of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
749 // duplicated. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
750 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
751 int n = type.length (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
752 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
753 octave_value t_rhs = rhs; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
754 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
755 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
756 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
757 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
759 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
760 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
761 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
762 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
763 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
764 octave_value_list t_idx = *p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
765 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
766 octave_value_list key_idx = *++p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
767 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
768 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
769 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
770 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
771 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
772 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
773 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
774 octave_value u; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
775 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
776 if (! map.contains (key)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
777 u = octave_value::empty_conv (type.substr (2), rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
778 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
779 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
780 Cell map_val = map.contents (key); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
781 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
782 Cell map_elt = map_val.index (idx.front (), true); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
783 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
784 u = numeric_conv (map_elt, type.substr (2)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
785 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
786 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
787 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
789 std::list<octave_value_list> next_idx (idx); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
790 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
791 // We handled two index elements, so subsasgn to |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
792 // needs to skip both of them. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
793 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
794 next_idx.erase (next_idx.begin ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
795 next_idx.erase (next_idx.begin ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
796 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
797 u.make_unique (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
798 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
799 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
800 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
801 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
802 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
803 gripe_invalid_index_for_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
804 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
805 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
806 gripe_invalid_index_for_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
807 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
808 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
809 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
810 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
812 octave_value_list key_idx = idx.front (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
813 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
814 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
815 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
816 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
817 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
818 std::list<octave_value_list> next_idx (idx); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
819 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
820 next_idx.erase (next_idx.begin ()); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
821 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
822 std::string next_type = type.substr (1); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
823 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
824 Cell tmpc (1, 1); |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
825 octave_map::iterator pkey = map.seek (key); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
826 if (pkey != map.end ()) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
827 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
828 map.contents (pkey).make_unique (); |
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
829 tmpc = map.contents (pkey); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
830 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
831 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
832 // FIXME: better code reuse? |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
833 if (! error_state) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
834 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
835 if (tmpc.numel () == 1) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
836 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
837 octave_value& tmp = tmpc(0); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
838 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
839 if (! tmp.is_defined () || tmp.is_zero_by_zero ()) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
840 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
841 tmp = octave_value::empty_conv (next_type, rhs); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
842 tmp.make_unique (); // probably a no-op. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
843 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
844 else |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
845 // optimization: ignore the copy still stored inside our map. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
846 tmp.make_unique (1); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
847 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
848 if (! error_state) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
849 t_rhs = tmp.subsasgn (next_type, next_idx, rhs); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
850 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
851 else |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
852 gripe_indexed_cs_list (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
853 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
854 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
855 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
856 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
857 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
858 gripe_invalid_index_type (type_name (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
859 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
860 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
861 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
862 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
863 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
864 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
865 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
866 if (! error_state) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
867 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
868 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
869 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
870 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
871 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
872 if (n > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
873 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
874 std::list<octave_value_list>::const_iterator p = idx.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
875 octave_value_list key_idx = *++p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
876 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
877 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
878 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
879 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
880 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
881 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
883 map.assign (idx.front (), key, t_rhs); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
885 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
886 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
887 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
888 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
889 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
890 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
891 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
892 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
893 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
894 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
895 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
896 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
897 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
898 if (t_rhs.is_object () || t_rhs.is_map ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
899 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
900 octave_map rhs_map = t_rhs.map_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
901 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
902 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
903 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
904 map.assign (idx.front (), rhs_map); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
905 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
906 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
907 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
908 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
909 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
910 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
911 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
912 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
914 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
915 error ("invalid class assignment"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
916 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
917 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
918 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
919 if (t_rhs.is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
920 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
921 map.delete_elements (idx.front ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
922 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
923 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
924 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
925 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
926 retval = octave_value (this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
927 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
928 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
929 gripe_failed_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
930 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
931 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
932 error ("invalid class assignment"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
933 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
934 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
935 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
936 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
937 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
938 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
939 { |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
940 octave_value_list key_idx = idx.front (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
941 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
942 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
943 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
944 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
945 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
946 if (t_rhs.is_cs_list ()) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
947 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
948 Cell tmp_cell = Cell (t_rhs.list_value ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
949 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
950 // The shape of the RHS is irrelevant, we just want |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
951 // the number of elements to agree and to preserve the |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
952 // shape of the left hand side of the assignment. |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
953 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
954 if (numel () == tmp_cell.numel ()) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
955 tmp_cell = tmp_cell.reshape (dims ()); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
956 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
957 map.setfield (key, tmp_cell); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
958 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
959 else |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
960 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
961 Cell tmp_cell(1, 1); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
962 tmp_cell(0) = t_rhs.storable_value (); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
963 map.setfield (key, tmp_cell); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
964 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
965 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
966 if (! error_state) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
967 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
968 count++; |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
969 retval = octave_value (this); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
970 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
971 else |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
972 gripe_failed_assignment (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
973 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
974 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
975 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
976 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
977 gripe_invalid_index_type (type_name (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
978 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
979 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
980 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
981 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
982 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
983 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
984 else |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
985 gripe_failed_assignment (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
986 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
987 return retval; |
7338 | 988 } |
989 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
990 idx_vector |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
991 octave_class::index_vector (void) const |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
992 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
993 idx_vector retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
994 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
995 octave_value meth = symbol_table::find_method ("subsindex", class_name ()); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
996 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
997 if (meth.is_defined ()) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
998 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
999 octave_value_list args; |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
1000 args(0) = octave_value (new octave_class (map, c_name, parent_list)); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1001 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1002 octave_value_list tmp = feval (meth.function_value (), args, 1); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1003 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1004 if (!error_state && tmp.length () >= 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1005 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1006 if (tmp(0).is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1007 error ("subsindex function must return a valid index vector"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1008 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1009 // Index vector returned by subsindex is zero based |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1010 // (why this inconsistency Mathworks?), and so we must |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1011 // add one to the value returned as the index_vector method |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1012 // expects it to be one based. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1013 retval = do_binary_op (octave_value::op_add, tmp (0), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1014 octave_value (1.0)).index_vector (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1015 } |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1016 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1017 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1018 error ("no subsindex method defined for class %s", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1019 class_name ().c_str ()); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1020 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1021 return retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1022 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1023 |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1024 size_t |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1025 octave_class::byte_size (void) const |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1026 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1027 // Neglect the size of the fieldnames. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1028 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1029 size_t retval = 0; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1030 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1031 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1032 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1033 std::string key = map.key (p); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1034 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1035 octave_value val = octave_value (map.contents (p)); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1036 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1037 retval += val.byte_size (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1038 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1039 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1040 return retval; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1041 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
1042 |
7338 | 1043 string_vector |
1044 octave_class::map_keys (void) const | |
1045 { | |
1046 string_vector retval; | |
1047 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ()); | |
1048 return retval; | |
1049 } | |
1050 | |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1051 octave_base_value * |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1052 octave_class::find_parent_class (const std::string& parent_class_name) |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1053 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1054 octave_base_value* retval = 0; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1055 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1056 if (parent_class_name == class_name ()) |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1057 retval = this; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1058 else |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1059 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1060 for (std::list<std::string>::iterator pit = parent_list.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1061 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1062 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1063 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1064 octave_map::const_iterator smap = map.seek (*pit); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1065 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1066 const Cell& tmp = map.contents (smap); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1067 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1068 octave_value vtmp = tmp(0); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1069 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1070 octave_base_value *obvp = vtmp.internal_rep (); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1071 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1072 retval = obvp->find_parent_class (parent_class_name); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1073 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1074 if (retval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1075 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1076 } |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1077 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1078 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1079 return retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1080 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
1081 |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1082 octave_base_value * |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1083 octave_class::unique_parent_class (const std::string& parent_class_name) |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1084 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1085 octave_base_value* retval = 0; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1086 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1087 if (parent_class_name == class_name ()) |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1088 retval = this; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1089 else |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1090 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1091 for (std::list<std::string>::iterator pit = parent_list.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1092 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1093 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1094 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1095 octave_map::iterator smap = map.seek (*pit); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1096 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1097 Cell& tmp = map.contents (smap); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1098 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1099 octave_value& vtmp = tmp(0); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1100 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1101 octave_base_value *obvp = vtmp.internal_rep (); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1102 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1103 // Use find_parent_class first to avoid uniquifying if not necessary. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1104 retval = obvp->find_parent_class (parent_class_name); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1105 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1106 if (retval) |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1107 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1108 vtmp.make_unique (); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1109 obvp = vtmp.internal_rep (); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1110 retval = obvp->unique_parent_class (parent_class_name); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1111 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1112 break; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1113 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1114 } |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1115 } |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1116 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1117 return retval; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1118 } |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
1119 |
13694
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1120 string_vector |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1121 octave_class::all_strings (bool pad) const |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1122 { |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1123 string_vector retval; |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1124 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1125 octave_value meth = symbol_table::find_method ("char", class_name ()); |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1126 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1127 if (meth.is_defined ()) |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1128 { |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1129 octave_value_list args; |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
1130 args(0) = octave_value (new octave_class (map, c_name, parent_list)); |
13694
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1131 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1132 octave_value_list tmp = feval (meth.function_value (), args, 1); |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1133 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1134 if (!error_state && tmp.length () >= 1) |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1135 { |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1136 if (tmp(0).is_string ()) |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1137 retval = tmp(0).all_strings (pad); |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1138 else |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1139 error ("cname/char method did not return a character string"); |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1140 } |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1141 } |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1142 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1143 error ("no char method defined for class %s", class_name ().c_str ()); |
13694
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1144 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1145 return retval; |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1146 } |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1147 |
441af0aa125a
char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents:
13241
diff
changeset
|
1148 |
7338 | 1149 void |
1150 octave_class::print (std::ostream& os, bool) const | |
1151 { | |
1152 print_raw (os); | |
1153 } | |
1154 | |
1155 void | |
1156 octave_class::print_raw (std::ostream& os, bool) const | |
1157 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1158 unwind_protect frame; |
7338 | 1159 |
1160 indent (os); | |
1161 os << " <class " << class_name () << ">"; | |
1162 newline (os); | |
1163 } | |
1164 | |
1165 bool | |
1166 octave_class::print_name_tag (std::ostream& os, const std::string& name) const | |
1167 { | |
1168 bool retval = false; | |
1169 | |
1170 indent (os); | |
1171 os << name << " ="; | |
1172 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12620
diff
changeset
|
1173 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12620
diff
changeset
|
1174 newline (os); |
7338 | 1175 |
1176 return retval; | |
1177 } | |
1178 | |
1179 void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1180 octave_class::print_with_name (std::ostream& os, const std::string& name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1181 bool) |
7338 | 1182 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1183 octave_value fcn = symbol_table::find_method ("display", class_name ()); |
7338 | 1184 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1185 if (fcn.is_defined ()) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1186 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1187 octave_value_list args; |
7338 | 1188 |
9521 | 1189 count++; |
1190 args(0) = octave_value (this); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1191 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1192 string_vector arg_names (1); |
7338 | 1193 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1194 arg_names[0] = name; |
7338 | 1195 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1196 args.stash_name_tags (arg_names); |
7338 | 1197 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1198 feval (fcn.function_value (), args); |
7338 | 1199 } |
10204
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1200 else |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1201 { |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1202 indent (os); |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1203 os << name << " = <class " << class_name () << ">"; |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1204 newline (os); |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1205 } |
7338 | 1206 } |
1207 | |
9190 | 1208 // Loading a class properly requires an exemplar map entry for success. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1209 // If we don't have one, we attempt to create one by calling the constructor |
9190 | 1210 // with no arguments. |
1211 bool | |
1212 octave_class::reconstruct_exemplar (void) | |
1213 { | |
1214 bool retval = false; | |
1215 | |
1216 octave_class::exemplar_const_iterator it | |
1217 = octave_class::exemplar_map.find (c_name); | |
1218 | |
1219 if (it != octave_class::exemplar_map.end ()) | |
1220 retval = true; | |
1221 else | |
1222 { | |
1223 octave_value ctor = symbol_table::find_method (c_name, c_name); | |
1224 | |
12178
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1225 bool have_ctor = false; |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1226 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1227 if (ctor.is_defined () && ctor.is_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1228 { |
12178
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1229 octave_function *fcn = ctor.function_value (); |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1230 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1231 if (fcn && fcn->is_class_constructor (c_name)) |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1232 have_ctor = true; |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1233 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1234 // Something has gone terribly wrong if |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1235 // symbol_table::find_method (c_name, c_name) does not return |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1236 // a class constructor for the class c_name... |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1237 assert (have_ctor); |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1238 } |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1239 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1240 if (have_ctor) |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1241 { |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1242 unwind_protect frame; |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1243 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1244 // Simulate try/catch. |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1245 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1246 interpreter_try (frame); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1247 |
12178
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1248 octave_value_list result |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1249 = ctor.do_multi_index_op (1, octave_value_list ()); |
9190 | 1250 |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1251 if (! error_state && result.length () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1252 retval = true; |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1253 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1254 error_state = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1255 } |
9190 | 1256 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1257 warning ("no constructor for class %s", c_name.c_str ()); |
9190 | 1258 } |
1259 | |
1260 return retval; | |
1261 } | |
1262 | |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1263 void |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1264 octave_class::clear_exemplar_map (void) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1265 { |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1266 exemplar_map.clear (); |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1267 } |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1268 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1269 // Load/save does not provide enough information to reconstruct the |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1270 // class inheritance structure. reconstruct_parents () attempts to |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1271 // do so. If successful, a "true" value is returned. |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1272 // |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1273 // Note that we don't check the loaded object structure against the |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1274 // class structure here so the user's loadobj method has a chance |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1275 // to do its magic. |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1276 bool |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1277 octave_class::reconstruct_parents (void) |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1278 { |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1279 bool retval = true, might_have_inheritance = false; |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1280 std::string dbgstr = "dork"; |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1281 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1282 // First, check to see if there might be an issue with inheritance. |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1283 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++) |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1284 { |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1285 std::string key = map.key (p); |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1286 Cell val = map.contents (p); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1287 if ( val(0).is_object () ) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1289 dbgstr = "blork"; |
15017
dd4ad69e4ab9
maint: Fix a few Octave coding convention violations.
Rik <rik@octave.org>
parents:
14861
diff
changeset
|
1290 if ( key == val(0).class_name () ) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1292 might_have_inheritance = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1293 dbgstr = "cork"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1294 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1295 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1296 } |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1297 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1298 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1299 if (might_have_inheritance) |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1300 { |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1301 octave_class::exemplar_const_iterator it |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1302 = octave_class::exemplar_map.find (c_name); |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1303 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1304 if (it == octave_class::exemplar_map.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1305 retval = false; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1306 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1308 octave_class::exemplar_info exmplr = it->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1309 parent_list = exmplr.parents (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1310 for (std::list<std::string>::iterator pit = parent_list.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1311 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1312 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1313 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1314 dbgstr = *pit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1315 bool dbgbool = map.contains (*pit); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1316 if (!dbgbool) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1317 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1318 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1319 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1320 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1321 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1322 } |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1323 } |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1324 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1325 return retval; |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1326 } |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1327 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1328 bool |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1329 octave_class::save_ascii (std::ostream& os) |
7338 | 1330 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1331 os << "# classname: " << class_name () << "\n"; |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1332 octave_map m; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1333 if (load_path::find_method (class_name (), "saveobj") != std::string ()) |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1334 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1335 octave_value in = new octave_class (*this); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1336 octave_value_list tmp = feval ("saveobj", in, 1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1337 if (! error_state) |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1338 m = tmp(0).map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1339 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1340 return false; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1341 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1342 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1343 m = map_value (); |
7338 | 1344 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1345 os << "# length: " << m.nfields () << "\n"; |
7338 | 1346 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1347 octave_map::iterator i = m.begin (); |
7338 | 1348 while (i != m.end ()) |
1349 { | |
1350 octave_value val = map.contents (i); | |
1351 | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1352 bool b = save_ascii_data (os, val, m.key (i), false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1353 |
7338 | 1354 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1355 return os; |
7338 | 1356 |
1357 i++; | |
1358 } | |
1359 | |
1360 return true; | |
1361 } | |
1362 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1363 bool |
7338 | 1364 octave_class::load_ascii (std::istream& is) |
1365 { | |
1366 octave_idx_type len = 0; | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1367 std::string classname; |
7338 | 1368 bool success = true; |
1369 | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1370 if (extract_keyword (is, "classname", classname) && classname != "") |
7338 | 1371 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1372 if (extract_keyword (is, "length", len) && len >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1373 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1374 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1375 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1376 octave_map m (map); |
7338 | 1377 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1378 for (octave_idx_type j = 0; j < len; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1379 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1380 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1381 bool dummy; |
7338 | 1382 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1383 // recurse to read cell elements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1384 std::string nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1385 = read_ascii_data (is, std::string (), dummy, t2, j); |
7338 | 1386 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1387 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1388 break; |
7338 | 1389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1390 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); |
7338 | 1391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1392 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1393 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1394 error ("load: internal error loading class elements"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1395 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1396 } |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1397 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1398 m.assign (nm, tcell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1399 } |
7338 | 1400 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1401 if (is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1403 c_name = classname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1404 reconstruct_exemplar (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1406 map = m; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1407 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1408 if (! reconstruct_parents ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1409 warning ("load: unable to reconstruct object inheritance"); |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1410 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1411 if (load_path::find_method (classname, "loadobj") |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1412 != std::string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1413 { |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1414 octave_value in = new octave_class (*this); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1415 octave_value_list tmp = feval ("loadobj", in, 1); |
7338 | 1416 |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1417 if (! error_state) |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1418 map = tmp(0).map_value (); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1419 else |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1420 success = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1421 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1422 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1423 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1424 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1425 error ("load: failed to load class"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1426 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1427 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1428 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1429 else if (len == 0 ) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1430 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1431 map = octave_map (dim_vector (1, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1432 c_name = classname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1433 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1434 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1435 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1436 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1437 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1438 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1439 error ("load: failed to extract number of elements in class"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1440 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1441 } |
7338 | 1442 } |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1443 else |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1444 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1445 error ("load: failed to extract name of class"); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1446 success = false; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1447 } |
7338 | 1448 |
1449 return success; | |
1450 } | |
1451 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1452 bool |
7338 | 1453 octave_class::save_binary (std::ostream& os, bool& save_as_floats) |
1454 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1455 int32_t classname_len = class_name ().length (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1456 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1457 os.write (reinterpret_cast<char *> (&classname_len), 4); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1458 os << class_name (); |
7338 | 1459 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1460 octave_map m; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1461 if (load_path::find_method (class_name (), "saveobj") != std::string ()) |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1462 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1463 octave_value in = new octave_class (*this); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1464 octave_value_list tmp = feval ("saveobj", in, 1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1465 if (! error_state) |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1466 m = tmp(0).map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1467 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1468 return false; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1469 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1470 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1471 m = map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1472 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1473 int32_t len = m.nfields (); |
7338 | 1474 os.write (reinterpret_cast<char *> (&len), 4); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1475 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1476 octave_map::iterator i = m.begin (); |
7338 | 1477 while (i != m.end ()) |
1478 { | |
1479 octave_value val = map.contents (i); | |
1480 | |
1481 bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1482 |
7338 | 1483 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1484 return os; |
7338 | 1485 |
1486 i++; | |
1487 } | |
1488 | |
1489 return true; | |
1490 } | |
1491 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1492 bool |
7338 | 1493 octave_class::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1494 oct_mach_info::float_format fmt) |
7338 | 1495 { |
1496 bool success = true; | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1497 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1498 int32_t classname_len; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1499 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1500 is.read (reinterpret_cast<char *> (&classname_len), 4); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1501 if (! is) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1502 return false; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1503 else if (swap) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1504 swap_bytes<4> (&classname_len); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1505 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1506 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1507 OCTAVE_LOCAL_BUFFER (char, classname, classname_len+1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1508 classname[classname_len] = '\0'; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1509 if (! is.read (reinterpret_cast<char *> (classname), classname_len)) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1510 return false; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1511 c_name = classname; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1512 } |
9190 | 1513 reconstruct_exemplar (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1514 |
7338 | 1515 int32_t len; |
1516 if (! is.read (reinterpret_cast<char *> (&len), 4)) | |
1517 return false; | |
1518 if (swap) | |
1519 swap_bytes<4> (&len); | |
1520 | |
1521 if (len > 0) | |
1522 { | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1523 octave_map m (map); |
7338 | 1524 |
1525 for (octave_idx_type j = 0; j < len; j++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1526 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1527 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1528 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1529 std::string doc; |
7338 | 1530 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1531 // recurse to read cell elements |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1532 std::string nm = read_binary_data (is, swap, fmt, std::string (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1533 dummy, t2, doc); |
7338 | 1534 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1535 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1536 break; |
7338 | 1537 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1538 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1539 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1540 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1541 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1542 error ("load: internal error loading class elements"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1543 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1544 } |
7338 | 1545 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1546 m.assign (nm, tcell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1547 } |
7338 | 1548 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1549 if (is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1550 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1551 map = m; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1552 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1553 if (! reconstruct_parents ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1554 warning ("load: unable to reconstruct object inheritance"); |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1555 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1556 if (load_path::find_method (c_name, "loadobj") != std::string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1557 { |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1558 octave_value in = new octave_class (*this); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1559 octave_value_list tmp = feval ("loadobj", in, 1); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1560 |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1561 if (! error_state) |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1562 map = tmp(0).map_value (); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1563 else |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1564 success = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1565 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1566 } |
7338 | 1567 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1568 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1569 warning ("load: failed to load class"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1570 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1571 } |
7338 | 1572 } |
1573 else if (len == 0 ) | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1574 map = octave_map (dim_vector (1, 1)); |
7338 | 1575 else |
1576 panic_impossible (); | |
1577 | |
1578 return success; | |
1579 } | |
1580 | |
1581 #if defined (HAVE_HDF5) | |
1582 | |
1583 bool | |
1584 octave_class::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
1585 { | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1586 hsize_t hdims[3]; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1587 hid_t group_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1588 hid_t type_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1589 hid_t space_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1590 hid_t class_hid = -1; |
7338 | 1591 hid_t data_hid = -1; |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1592 octave_map m; |
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1593 octave_map::iterator i; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1594 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1595 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1596 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1597 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1598 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1599 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1600 if (group_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1601 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1602 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1603 // Add the class name to the group |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1604 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid, c_name.length () + 1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1605 if (type_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1606 goto error_cleanup; |
7338 | 1607 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1608 hdims[0] = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1609 space_hid = H5Screate_simple (0 , hdims, 0); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1610 if (space_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1611 goto error_cleanup; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1612 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1613 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1614 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1615 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1616 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1617 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1618 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1619 if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1620 H5P_DEFAULT, c_name.c_str ()) < 0) |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1621 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1622 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1623 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1624 data_hid = H5Gcreate (group_hid, "value", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1625 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1626 data_hid = H5Gcreate (group_hid, "value", 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1627 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1628 if (data_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1629 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1630 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1631 if (load_path::find_method (class_name (), "saveobj") != std::string ()) |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1632 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1633 octave_value in = new octave_class (*this); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1634 octave_value_list tmp = feval ("saveobj", in, 1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1635 if (! error_state) |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1636 m = tmp(0).map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1637 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1638 goto error_cleanup; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1639 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1640 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1641 m = map_value (); |
7338 | 1642 |
1643 // recursively add each element of the class to this group | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1644 i = m.begin (); |
7338 | 1645 while (i != m.end ()) |
1646 { | |
1647 octave_value val = map.contents (i); | |
1648 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1649 bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1650 save_as_floats); |
7338 | 1651 |
1652 if (! retval2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1653 break; |
7338 | 1654 |
1655 i++; | |
1656 } | |
1657 | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1658 error_cleanup: |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1659 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1660 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1661 H5Gclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1662 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1663 if (class_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1664 H5Dclose (class_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1665 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1666 if (space_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1667 H5Sclose (space_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1668 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1669 if (type_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1670 H5Tclose (type_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1671 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1672 if (group_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1673 H5Gclose (group_hid); |
7338 | 1674 |
1675 return true; | |
1676 } | |
1677 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1678 bool |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9792
diff
changeset
|
1679 octave_class::load_hdf5 (hid_t loc_id, const char *name) |
7338 | 1680 { |
1681 bool retval = false; | |
1682 | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1683 hid_t group_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1684 hid_t data_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1685 hid_t type_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1686 hid_t type_class_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1687 hid_t space_hid = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1688 hid_t subgroup_hid = -1; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1689 hid_t st_id = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1690 |
7338 | 1691 hdf5_callback_data dsub; |
1692 | |
1693 herr_t retval2 = 0; | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1694 octave_map m (dim_vector (1, 1)); |
7338 | 1695 int current_item = 0; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1696 hsize_t num_obj = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1697 int slen = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1698 hsize_t rank = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1699 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1700 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1701 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1702 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1703 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1704 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1705 if (group_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1706 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1707 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1708 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1709 data_hid = H5Dopen (group_hid, "classname", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1710 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1711 data_hid = H5Dopen (group_hid, "classname"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1712 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1713 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1714 if (data_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1715 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1716 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1717 type_hid = H5Dget_type (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1718 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1719 type_class_hid = H5Tget_class (type_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1720 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1721 if (type_class_hid != H5T_STRING) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1722 goto error_cleanup; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1723 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1724 space_hid = H5Dget_space (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1725 rank = H5Sget_simple_extent_ndims (space_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1726 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1727 if (rank != 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1728 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1729 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1730 slen = H5Tget_size (type_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1731 if (slen < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1732 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1733 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1734 // do-while loop here to prevent goto crossing initialization of classname |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1735 do |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1736 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1737 OCTAVE_LOCAL_BUFFER (char, classname, slen); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1738 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1739 // create datatype for (null-terminated) string to read into: |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1740 st_id = H5Tcopy (H5T_C_S1); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1741 H5Tset_size (st_id, slen); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1742 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1743 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1744 classname) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1745 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1746 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1747 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1748 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1749 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1750 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1751 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1752 H5Tclose (st_id); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1753 H5Dclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1754 data_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1755 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1756 c_name = classname; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1757 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1758 while (0); |
9190 | 1759 reconstruct_exemplar (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1760 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1761 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1762 subgroup_hid = H5Gopen (group_hid, name, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1763 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1764 subgroup_hid = H5Gopen (group_hid, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1765 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1766 H5Gget_num_objs (subgroup_hid, &num_obj); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1767 H5Gclose (subgroup_hid); |
7338 | 1768 |
1769 while (current_item < static_cast<int> (num_obj) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1770 && (retval2 = H5Giterate (group_hid, name, ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1771 hdf5_read_next_data, &dsub)) > 0) |
7338 | 1772 { |
1773 octave_value t2 = dsub.tc; | |
1774 | |
1775 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1776 |
7338 | 1777 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1778 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1779 error ("load: internal error loading class elements"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1780 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1781 } |
7338 | 1782 |
1783 m.assign (dsub.name, tcell); | |
1784 | |
1785 } | |
1786 | |
1787 if (retval2 >= 0) | |
1788 { | |
1789 map = m; | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1790 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1791 if (!reconstruct_parents ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1792 warning ("load: unable to reconstruct object inheritance"); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1793 |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1794 if (load_path::find_method (c_name, "loadobj") != std::string ()) |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1795 { |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1796 octave_value in = new octave_class (*this); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1797 octave_value_list tmp = feval ("loadobj", in, 1); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1798 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1799 if (! error_state) |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1800 { |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1801 map = tmp(0).map_value (); |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1802 retval = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1803 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1804 else |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1805 retval = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1806 } |
7338 | 1807 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1808 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1809 error_cleanup: |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1810 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1811 H5Dclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1812 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1813 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1814 H5Gclose (group_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1815 |
7338 | 1816 return retval; |
1817 } | |
1818 | |
1819 #endif | |
1820 | |
1821 mxArray * | |
1822 octave_class::as_mxArray (void) const | |
1823 { | |
1824 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ()); | |
1825 | |
1826 return 0; | |
1827 } | |
1828 | |
1829 bool | |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9580
diff
changeset
|
1830 octave_class::in_class_method (void) |
7338 | 1831 { |
1832 octave_function *fcn = octave_call_stack::current (); | |
1833 | |
1834 return (fcn | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1835 && (fcn->is_class_method () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1836 || fcn->is_class_constructor () |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
1837 || fcn->is_anonymous_function_of_class () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1838 || fcn->is_private_function_of_class (class_name ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1839 && find_parent_class (fcn->dispatch_class ())); |
7338 | 1840 } |
1841 | |
9151 | 1842 octave_class::exemplar_info::exemplar_info (const octave_value& obj) |
1843 : field_names (), parent_class_names () | |
1844 { | |
1845 if (obj.is_object ()) | |
1846 { | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1847 octave_map m = obj.map_value (); |
9151 | 1848 field_names = m.keys (); |
1849 | |
1850 parent_class_names = obj.parent_class_name_list (); | |
1851 } | |
1852 else | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12178
diff
changeset
|
1853 error ("invalid call to exemplar_info constructor"); |
9151 | 1854 } |
1855 | |
1856 | |
1857 // A map from class names to lists of fields. | |
1858 std::map<std::string, octave_class::exemplar_info> octave_class::exemplar_map; | |
1859 | |
1860 bool | |
1861 octave_class::exemplar_info::compare (const octave_value& obj) const | |
1862 { | |
1863 bool retval = true; | |
1864 | |
1865 if (obj.is_object ()) | |
1866 { | |
1867 if (nfields () == obj.nfields ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1868 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1869 octave_map obj_map = obj.map_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1870 string_vector obj_fnames = obj_map.keys (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1871 string_vector fnames = fields (); |
9151 | 1872 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1873 for (octave_idx_type i = 0; i < nfields (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1874 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1875 if (obj_fnames[i] != fnames[i]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1877 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1878 error ("mismatch in field names"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1879 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1880 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1881 } |
9151 | 1882 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1883 if (nparents () == obj.nparents ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1885 std::list<std::string> obj_parents |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1886 = obj.parent_class_name_list (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1887 std::list<std::string> pnames = parents (); |
9151 | 1888 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1889 std::list<std::string>::const_iterator p = obj_parents.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1890 std::list<std::string>::const_iterator q = pnames.begin (); |
9151 | 1891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1892 while (p != obj_parents.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1894 if (*p++ != *q++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1895 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1896 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1897 error ("mismatch in parent classes"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1898 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1899 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1900 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1901 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1902 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1903 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1904 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1905 error ("mismatch in number of parent classes"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1906 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1907 } |
9151 | 1908 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1909 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1910 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1911 error ("mismatch in number of fields"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1912 } |
9151 | 1913 } |
1914 else | |
1915 { | |
1916 retval = false; | |
9206
5f36c6c9be13
Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9190
diff
changeset
|
1917 error ("invalid comparison of class exemplar to non-class object"); |
9151 | 1918 } |
1919 | |
1920 return retval; | |
1921 } | |
1922 | |
7338 | 1923 DEFUN (class, args, , |
1924 "-*- texinfo -*-\n\ | |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1925 @deftypefn {Function File} {@var{classname} =} class (@var{obj})\n\ |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1926 @deftypefnx {Function File} {} class (@var{s}, @var{id})\n\ |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1927 @deftypefnx {Function File} {} class (@var{s}, @var{id}, @var{p}, @dots{})\n\ |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1928 Return the class of the object @var{obj} or create a class with\n\ |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1929 fields from structure @var{s} and name (string) @var{id}. Additional\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1930 arguments name a list of parent classes from which the new class is\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1931 derived.\n\ |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1932 @seealso{typeinfo, isa}\n\ |
7338 | 1933 @end deftypefn") |
1934 { | |
1935 octave_value retval; | |
1936 | |
1937 int nargin = args.length (); | |
1938 | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1939 if (nargin == 0) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1940 print_usage (); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1941 else if (nargin == 1) |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1942 // Called for class of object |
15813
10d6ab9b1b4f
Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents:
15812
diff
changeset
|
1943 retval = args(0).class_name (); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1944 else |
7338 | 1945 { |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1946 // Called as class constructor |
10272
272179888089
Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents:
10204
diff
changeset
|
1947 octave_function *fcn = octave_call_stack::caller (); |
7338 | 1948 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1949 std::string id = args(1).string_value (); |
7338 | 1950 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1951 if (! error_state) |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1952 { |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1953 if (fcn) |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1954 { |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1955 if (fcn->is_class_constructor (id) || fcn->is_class_method (id)) |
10272
272179888089
Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents:
10204
diff
changeset
|
1956 { |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1957 octave_map m = args(0).map_value (); |
9151 | 1958 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1959 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1960 { |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1961 if (nargin == 2) |
13874
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
1962 retval |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
1963 = octave_value (new octave_class |
c1b754d93572
copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents:
13784
diff
changeset
|
1964 (m, id, std::list<std::string> ())); |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1965 else |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1966 { |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1967 octave_value_list parents = args.slice (2, nargin-2); |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1968 |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1969 retval |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1970 = octave_value (new octave_class (m, id, parents)); |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1971 } |
9151 | 1972 |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1973 if (! error_state) |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1974 { |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1975 octave_class::exemplar_const_iterator it |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1976 = octave_class::exemplar_map.find (id); |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1977 |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1978 if (it == octave_class::exemplar_map.end ()) |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1979 octave_class::exemplar_map[id] |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1980 = octave_class::exemplar_info (retval); |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1981 else if (! it->second.compare (retval)) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1982 error ("class: object of class '%s' does not match previously constructed objects", |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1983 id.c_str ()); |
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1984 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1985 } |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1986 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12178
diff
changeset
|
1987 error ("class: expecting structure S as first argument"); |
10272
272179888089
Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents:
10204
diff
changeset
|
1988 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1989 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1990 error ("class: '%s' is invalid as a class name in this context", |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1991 id.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1992 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1993 else |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1994 error ("class: invalid call from outside class constructor or method"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1995 } |
7338 | 1996 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12178
diff
changeset
|
1997 error ("class: ID (class name) must be a character string"); |
7338 | 1998 } |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1999 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2000 return retval; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2001 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2002 |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2003 /* |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2004 %!assert (class (1.1), "double"); |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2005 %!assert (class (single (1.1)), "single"); |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2006 %!assert (class (uint8 (1)), "uint8"); |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2007 %!testif HAVE_JAVA |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2008 %! jobj = javaObject ("java.lang.StringBuffer"); |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2009 %! assert (class (jobj), "java.lang.StringBuffer"); |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2010 |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2011 %% Test Input Validation |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2012 %!error class () |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2013 */ |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
2014 |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2015 DEFUN (__isa_parent__, args, , |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2016 "-*- texinfo -*-\n\ |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2017 @deftypefn {Built-in Function} {} __isa_parent__ (@var{class}, @var{name})\n\ |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2018 Undocumented internal function.\n\ |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2019 @end deftypefn") |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2020 { |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2021 octave_value retval = false; |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2022 |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2023 if (args.length () == 2) |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2024 { |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2025 octave_value cls = args(0); |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2026 octave_value nm = args(1); |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2027 |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2028 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2029 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2030 if (cls.find_parent_class (nm.string_value ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2031 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2032 } |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2033 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2034 error ("__isa_parent__: expecting arguments to be character strings"); |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2035 } |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2036 else |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2037 print_usage (); |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2038 |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2039 return retval; |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2040 } |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
2041 |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2042 DEFUN (__parent_classes__, args, , |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2043 "-*- texinfo -*-\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2044 @deftypefn {Built-in Function} {} __parent_classes__ (@var{x})\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2045 Undocumented internal function.\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2046 @end deftypefn") |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2047 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2048 octave_value retval = Cell (); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2049 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2050 if (args.length () == 1) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2051 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2052 octave_value arg = args(0); |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2053 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2054 if (arg.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2055 retval = Cell (arg.parent_class_names ()); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
2056 } |
7338 | 2057 else |
2058 print_usage (); | |
2059 | |
2060 return retval; | |
2061 } | |
2062 | |
2063 DEFUN (isobject, args, , | |
2064 "-*- texinfo -*-\n\ | |
2065 @deftypefn {Built-in Function} {} isobject (@var{x})\n\ | |
2066 Return true if @var{x} is a class object.\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11220
diff
changeset
|
2067 @seealso{class, typeinfo, isa, ismethod}\n\ |
7338 | 2068 @end deftypefn") |
2069 { | |
2070 octave_value retval; | |
2071 | |
2072 if (args.length () == 1) | |
2073 retval = args(0).is_object (); | |
2074 else | |
2075 print_usage (); | |
2076 | |
2077 return retval; | |
2078 } | |
2079 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2080 DEFUN (ismethod, args, , |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2081 "-*- texinfo -*-\n\ |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2082 @deftypefn {Built-in Function} {} ismethod (@var{x}, @var{method})\n\ |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2083 Return true if @var{x} is a class object and the string @var{method}\n\ |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2084 is a method of this class.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11220
diff
changeset
|
2085 @seealso{isobject}\n\ |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2086 @end deftypefn") |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2087 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2088 octave_value retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2089 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2090 if (args.length () == 2) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2091 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2092 octave_value arg = args(0); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2093 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2094 std::string class_name; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2095 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2096 if (arg.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2097 class_name = arg.class_name (); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2098 else if (arg.is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2099 class_name = arg.string_value (); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2100 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2101 error ("ismethod: expecting object or class name as first argument"); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2102 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2103 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2104 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2105 std::string method = args(1).string_value (); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2106 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2107 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2108 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2109 if (load_path::find_method (class_name, method) != std::string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2110 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2111 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2112 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2113 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2114 } |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2115 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2116 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2117 print_usage (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2118 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2119 return retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2120 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
2121 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2122 DEFUN (__methods__, args, , |
7338 | 2123 "-*- texinfo -*-\n\ |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2124 @deftypefn {Built-in Function} {} __methods__ (@var{x})\n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2125 @deftypefnx {Built-in Function} {} __methods__ (\"classname\")\n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2126 Internal function.\n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2127 \n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2128 Implements @code{methods} for Octave class objects and classnames.\n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2129 @seealso{methods}\n\ |
7338 | 2130 @end deftypefn") |
2131 { | |
2132 octave_value retval; | |
2133 | |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2134 // Input validation has already been done in methods.m. |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2135 octave_value arg = args(0); |
7338 | 2136 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2137 std::string class_name; |
7338 | 2138 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2139 if (arg.is_object ()) |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2140 class_name = arg.class_name (); |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2141 else if (arg.is_string ()) |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2142 class_name = arg.string_value (); |
7338 | 2143 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2144 if (! error_state) |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2145 { |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2146 string_vector sv = load_path::methods (class_name); |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2147 retval = Cell (sv); |
7338 | 2148 } |
2149 | |
2150 return retval; | |
2151 } | |
2152 | |
2153 static bool | |
2154 is_built_in_class (const std::string& cn) | |
2155 { | |
2156 static std::set<std::string> built_in_class_names; | |
2157 | |
2158 if (built_in_class_names.empty ()) | |
2159 { | |
2160 built_in_class_names.insert ("double"); | |
2161 built_in_class_names.insert ("single"); | |
2162 built_in_class_names.insert ("cell"); | |
2163 built_in_class_names.insert ("struct"); | |
2164 built_in_class_names.insert ("logical"); | |
2165 built_in_class_names.insert ("char"); | |
2166 built_in_class_names.insert ("function handle"); | |
2167 built_in_class_names.insert ("int8"); | |
2168 built_in_class_names.insert ("uint8"); | |
2169 built_in_class_names.insert ("int16"); | |
2170 built_in_class_names.insert ("uint16"); | |
2171 built_in_class_names.insert ("int32"); | |
2172 built_in_class_names.insert ("uint32"); | |
2173 built_in_class_names.insert ("int64"); | |
2174 built_in_class_names.insert ("uint64"); | |
2175 } | |
2176 | |
2177 return built_in_class_names.find (cn) != built_in_class_names.end (); | |
2178 } | |
2179 | |
2180 DEFUN (superiorto, args, , | |
2181 "-*- texinfo -*-\n\ | |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2182 @deftypefn {Built-in Function} {} superiorto (@var{class_name}, @dots{})\n\ |
7338 | 2183 When called from a class constructor, mark the object currently\n\ |
2184 constructed as having a higher precedence than @var{class_name}.\n\ | |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2185 More that one such class can be specified in a single call.\n\ |
7338 | 2186 This function may only be called from a class constructor.\n\ |
2187 @end deftypefn") | |
2188 { | |
2189 octave_value retval; | |
2190 | |
2191 octave_function *fcn = octave_call_stack::caller (); | |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2192 if ((! fcn) || (! fcn->is_class_constructor ())) |
7338 | 2193 { |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2194 error ("superiorto: invalid call from outside class constructor"); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2195 return retval; |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2196 } |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2197 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2198 for (int i = 0; i < args.length (); i++) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2199 { |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2200 std::string inf_class = args(i).string_value (); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2201 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2203 error ("superiorto: expecting argument to be class name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2204 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2205 } |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2206 |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2207 // User defined classes always have higher precedence |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2208 // than built-in classes |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2209 if (is_built_in_class (inf_class)) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2210 break; |
7338 | 2211 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2212 std::string sup_class = fcn->name (); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2213 if (! symbol_table::set_class_relationship (sup_class, inf_class)) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2214 { |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2215 error ("superiorto: opposite precedence already set for %s and %s", |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2216 sup_class.c_str (), inf_class.c_str ()); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2217 break; |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2218 } |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2219 } |
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2220 |
7338 | 2221 return retval; |
2222 } | |
2223 | |
2224 DEFUN (inferiorto, args, , | |
2225 "-*- texinfo -*-\n\ | |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2226 @deftypefn {Built-in Function} {} inferiorto (@var{class_name}, @dots{})\n\ |
7338 | 2227 When called from a class constructor, mark the object currently\n\ |
2228 constructed as having a lower precedence than @var{class_name}.\n\ | |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2229 More that one such class can be specified in a single call.\n\ |
7338 | 2230 This function may only be called from a class constructor.\n\ |
2231 @end deftypefn") | |
2232 { | |
2233 octave_value retval; | |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2234 |
7338 | 2235 octave_function *fcn = octave_call_stack::caller (); |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2236 if ((! fcn) || (! fcn->is_class_constructor ())) |
7338 | 2237 { |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2238 error ("inferiorto: invalid call from outside class constructor"); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2239 return retval; |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2240 } |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2241 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2242 for (int i = 0; i < args.length (); i++) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2243 { |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2244 std::string sup_class = args(i).string_value (); |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2245 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2246 { |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2247 error ("inferiorto: expecting argument to be class name"); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2248 break; |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2249 } |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2250 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2251 if (is_built_in_class (sup_class)) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2252 { |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2253 error ("inferiorto: cannot give user-defined class lower " |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2254 "precedence than built-in class"); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2255 break; |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2256 } |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2257 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2258 std::string inf_class = fcn->name (); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2259 if (! symbol_table::set_class_relationship (sup_class, inf_class)) |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2260 { |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2261 error ("inferiorto: opposite precedence already set for %s and %s", |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2262 inf_class.c_str (), sup_class.c_str ()); |
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2263 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
2264 } |
7338 | 2265 } |
2266 | |
2267 return retval; | |
2268 } |