Mercurial > octave
annotate libinterp/octave-value/ov-class.cc @ 20962:3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
* cellfun.cc, data.cc, debug.cc, dirfns.cc, dynamic-ld.cc, file-io.cc,
gl2ps-renderer.cc, graphics.cc, graphics.in.h, hex2num.cc, load-save.cc,
ls-mat-ascii.cc, ls-oct-text.cc, oct-hist.cc, oct-lvalue.cc, oct-map.cc,
toplev.cc, __init_fltk__.cc, ov-base-int.cc, ov-bool-mat.cc, ov-cell.cc,
ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc,
ov-usr-fcn.cc, ov.cc, pt-arg-list.cc, pt-assign.cc, pt-colon.cc, pt-eval.cc,
pt-exp.cc:
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 22 Dec 2015 10:29:22 -0800 |
parents | 77f5591878bf |
children | 0963ed389012 |
rev | line source |
---|---|
7338 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 2007-2015 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" | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
42 #include "ls-oct-text.h" |
7338 | 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" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
47 #include "oct-hdf5.h" |
7338 | 48 #include "ov-class.h" |
15812
83bf6fd9e46d
ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents:
15811
diff
changeset
|
49 #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
|
50 #include "ov-java.h" |
15812
83bf6fd9e46d
ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents:
15811
diff
changeset
|
51 #endif |
7338 | 52 #include "ov-fcn.h" |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
53 #include "ov-usr-fcn.h" |
7338 | 54 #include "pager.h" |
55 #include "parse.h" | |
56 #include "pr-output.h" | |
57 #include "toplev.h" | |
58 #include "unwind-prot.h" | |
59 #include "variables.h" | |
60 | |
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 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 (octave_class::t_name, "<unknown>", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 octave_value (new octave_class ())); |
7338 | 72 } |
73 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 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
|
75 const octave_value_list& parents) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
76 : 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
|
77 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
78 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
|
79 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
80 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
|
81 { |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
82 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
|
83 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
84 if (! parent.is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
85 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
|
86 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
87 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
88 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
|
89 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
90 if (find_parent_class (pcnm)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
91 error ("duplicate class in parent tree"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
92 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
93 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
94 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
|
95 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
96 octave_idx_type nel = map.numel (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
97 octave_idx_type p_nel = parent.numel (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
98 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
99 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
|
100 { |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
101 if (p_nel == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
102 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
103 // No elements in MAP or the parent class object, |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
104 // so just add the field name. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
105 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
106 map.assign (pcnm, Cell (map.dims ())); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
107 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
108 else if (p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
109 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
110 if (map.nfields () == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
111 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
112 // No elements or fields in MAP, but the |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
113 // parent is class object with one element. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
114 // Resize to match size of parent class and |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
115 // make the parent a field in MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
116 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
117 map.resize (parent.dims ()); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
118 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
119 map.assign (pcnm, parent); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
120 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
121 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
122 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
123 // No elements in MAP, but we have at least |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
124 // one field. So don't resize, just add the |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
125 // 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
|
126 |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
127 map.assign (pcnm, Cell (map.dims ())); |
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 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
130 else if (map.nfields () == 0) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
131 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
132 // 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
|
133 // element in the parent class object, so we can |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
134 // resize MAP to match parent dimsenions, then |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
135 // distribute the elements of the parent object to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
136 // the elements of MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
137 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
138 dim_vector parent_dims = parent.dims (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
139 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
140 map.resize (parent_dims); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
141 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
142 Cell c (parent_dims); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
143 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
144 octave_map pmap = parent.map_value (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
145 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
146 std::list<std::string> plist |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
147 = parent.parent_class_name_list (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
148 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
149 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
|
150 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
|
151 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
152 map.assign (pcnm, c); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
153 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
154 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
155 error ("class: parent class dimension mismatch"); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
156 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
157 else if (nel == 1 && p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
158 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
159 // Simple assignment. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
160 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
161 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
|
162 } |
c7fac37a2afc
class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents:
13695
diff
changeset
|
163 else |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
164 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
165 if (p_nel == 1) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
166 { |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
167 // Broadcast the scalar parent class object to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
168 // each element of MAP. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
169 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
170 Cell pcell (map.dims (), parent); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
171 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
172 map.assign (pcnm, pcell); |
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 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
175 else if (nel == p_nel) |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
176 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 // FIXME: is there a better way to do this? |
13781
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
178 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
179 // The parent class object has the same number of |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
180 // 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
|
181 // new object, so distribute those elements to |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
182 // each element of the new object by first |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
183 // splitting the elements of the parent class |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
184 // object into a cell array with one element per |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
185 // cell. Then do the assignment all at once. |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
186 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
187 Cell c (parent.dims ()); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
188 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
189 octave_map pmap = parent.map_value (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
190 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
191 std::list<std::string> plist |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
192 = parent.parent_class_name_list (); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
193 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
194 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
|
195 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
|
196 |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
197 map.assign (pcnm, c); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
198 } |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
199 else |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
200 error ("class: parent class dimension mismatch"); |
1cb3ae93578d
correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents:
13711
diff
changeset
|
201 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
202 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
203 } |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
204 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
205 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
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 |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
264 Cell |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
265 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
|
266 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
267 Cell retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
268 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
269 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
|
270 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
271 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
|
272 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
273 // 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
|
274 // 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
|
275 |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
276 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
|
277 |
10926
f687bd17ce21
fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
278 if (obvp == 0) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
279 error ("malformed class"); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
280 |
10932
3a778233e4fb
fix typo in 10926:f687bd17ce21
Jaroslav Hajek <highegg@gmail.com>
parents:
10926
diff
changeset
|
281 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
|
282 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
283 std::string nm = idx(0).xstring_value ("invalid index for class"); |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
284 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
285 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
|
286 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
287 if (p != my_map.end ()) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
288 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
|
289 else |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
290 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
|
291 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
292 return retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
293 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
294 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
295 Matrix |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
296 octave_class::size (void) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
297 { |
9792
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
298 if (in_class_method () || called_from_builtin ()) |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
299 return octave_base_value::size (); |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
300 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
301 Matrix retval (1, 2, 1.0); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
302 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
|
303 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
304 if (meth.is_defined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
305 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
306 count++; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
307 octave_value_list args (1, octave_value (this)); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
308 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
309 octave_value_list lv = feval (meth.function_value (), args, 1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
310 if (lv.length () > 0 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
311 && 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
|
312 retval = lv(0).matrix_value (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
313 else |
9775
9d9f858849c7
Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents:
9774
diff
changeset
|
314 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
|
315 } |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
316 else |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
317 { |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
318 dim_vector dv = dims (); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
319 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
320 int nd = dv.length (); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
321 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
322 retval.resize (1, nd); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
323 |
13784
0bbe319bf26b
octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents:
13781
diff
changeset
|
324 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
|
325 retval(i) = dv(i); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13694
diff
changeset
|
326 } |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
327 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
328 return retval; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
329 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
330 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
331 octave_idx_type |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
332 octave_class::numel (const octave_value_list& idx) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
333 { |
9792
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
334 if (in_class_method () || called_from_builtin ()) |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
335 return octave_base_value::numel (idx); |
384616240a8f
fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9775
diff
changeset
|
336 |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
337 octave_idx_type retval = -1; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
338 const std::string cn = class_name (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
339 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
340 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
|
341 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
342 if (meth.is_defined ()) |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
343 { |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
344 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
|
345 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
346 count++; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
347 args(0) = octave_value (this); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
348 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
349 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
|
350 args(i+1) = idx(i); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
351 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
352 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
|
353 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
|
354 retval = lv(0).idx_type_value (true); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
355 else |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
356 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
|
357 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
358 else |
10106
edbe47bc0f88
make numel query more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
359 retval = octave_base_value::numel (idx); |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
360 |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
361 return retval; |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
362 } |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9240
diff
changeset
|
363 |
7338 | 364 octave_value_list |
365 octave_class::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
366 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
367 int nargout) |
7338 | 368 { |
369 octave_value_list retval; | |
370 | |
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
|
371 if (in_class_method () || called_from_builtin ()) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
372 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
373 // FIXME: this block of code is the same as the body of |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
374 // octave_struct::subsref. Maybe it could be shared instead of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
375 // duplicated. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
376 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
377 int skip = 1; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
378 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
379 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
380 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
381 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
383 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
384 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
385 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
|
386 octave_value_list key_idx = *++p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
388 Cell tmp = dotref (key_idx); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
389 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
390 Cell t = tmp.index (idx.front ()); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
391 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
392 retval(0) = (t.numel () == 1) ? t(0) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
393 : octave_value (t, true); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
394 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
395 // We handled two index elements, so tell |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
396 // next_subsref to skip both of them. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
397 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
398 skip++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
399 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
400 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
401 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
|
402 c_name, parent_list); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
404 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
406 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
407 { |
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
|
408 if (map.numel () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
409 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
410 Cell t = dotref (idx.front ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
411 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
412 retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
413 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
414 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
415 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
416 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
417 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
418 gripe_invalid_index_type (type_name (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
419 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
420 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
421 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
422 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
423 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
424 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
425 // FIXME: perhaps there should be an |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
426 // octave_value_list::next_subsref member function? See also |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
427 // octave_user_function::subsref. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
428 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
429 if (idx.size () > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
430 retval = retval(0).next_subsref (nargout, type, idx, skip); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
431 } |
7338 | 432 else |
433 { | |
434 octave_value meth = symbol_table::find_method ("subsref", class_name ()); | |
435 | |
436 if (meth.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
437 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
438 octave_value_list args; |
7338 | 439 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
440 args(1) = make_idx_args (type, idx, "subsref"); |
7338 | 441 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
442 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
443 args(0) = octave_value (this); |
7338 | 444 |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
445 // 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
|
446 // 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
|
447 // 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
|
448 // 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
|
449 // 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
|
450 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
|
451 || (type.length () > 1 && type[0] == '(' |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
452 && type[1] == '.')); |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
453 |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
454 int true_nargout = nargout; |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
455 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
456 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
|
457 { |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
458 // 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
|
459 octave_value_list tmp; |
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
460 if (type[0] != '.') tmp = idx.front (); |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
461 true_nargout = numel (tmp); |
9331
a76f391a3d02
set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
462 } |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
463 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
464 retval = feval (meth.function_value (), args, true_nargout); |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
465 |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
466 // 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
|
467 // 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
|
468 // rvalue1 calls. |
9691
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
469 if (retval.length () > 1) |
318e0cdd31bd
improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents:
9581
diff
changeset
|
470 retval = octave_value (retval, true); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
471 } |
7338 | 472 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
473 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
474 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
|
475 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
|
476 parent_list); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
477 else |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
478 gripe_invalid_index1 (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
479 } |
7338 | 480 } |
481 | |
482 return retval; | |
483 } | |
484 | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
485 octave_value |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
486 octave_class::numeric_conv (const Cell& val, const std::string& type) |
7338 | 487 { |
488 octave_value retval; | |
489 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
490 if (val.numel () == 1) |
7338 | 491 { |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
492 retval = val(0); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
493 |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
494 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
|
495 retval = octave_map (); |
7338 | 496 } |
497 else | |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
498 gripe_invalid_index_for_assignment (); |
7338 | 499 |
500 return retval; | |
501 } | |
502 | |
503 octave_value | |
504 octave_class::subsasgn (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
505 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
506 const octave_value& rhs) |
7338 | 507 { |
12171
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
508 count++; |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
509 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
|
510 } |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
511 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
512 octave_value |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 { |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
517 // 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
|
518 // 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
|
519 // undefined. |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
520 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
521 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
|
522 } |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
523 |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
524 octave_value |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 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
|
529 { |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
530 octave_value retval; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
531 |
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
|
532 if (! (in_class_method () || called_from_builtin ())) |
7338 | 533 { |
534 octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); | |
535 | |
536 if (meth.is_defined ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
537 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
538 octave_value_list args; |
7338 | 539 |
9333
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
540 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
|
541 { |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 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
|
546 } |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
547 else |
3930f8ce6430
Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents:
9331
diff
changeset
|
548 args(2) = rhs; |
7338 | 549 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
550 args(1) = make_idx_args (type, idx, "subsasgn"); |
12171
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
12127
diff
changeset
|
551 args(0) = obj; |
7338 | 552 |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
553 // Now comes the magic. Count copies with me: |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
554 // 1. myself (obsolete) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
555 // 2. the copy inside args (obsolete) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
556 // 3. the copy in method's symbol table (working) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
557 // ... possibly more (not obsolete). |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
558 // |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
559 // 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
|
560 // 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
|
561 // to the optimization. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
562 // 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
|
563 // 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
|
564 // optimization won't work. |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
565 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
566 octave_value_list tmp; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
567 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
568 if (obsolete_copies == 0 && meth.is_user_function () |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
569 && meth.user_function_value ()->subsasgn_optimization_ok ()) |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
570 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
571 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
572 frame.protect_var (obsolete_copies); |
9522
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
573 obsolete_copies = 2; |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
574 |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
575 tmp = feval (meth.function_value (), args); |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
576 } |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
577 else |
e79470be3ecb
implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents:
9521
diff
changeset
|
578 tmp = feval (meth.function_value (), args); |
7338 | 579 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
580 // FIXME: Should the subsasgn method be able to return |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
581 // more than one value? |
7338 | 582 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
583 if (tmp.length () > 1) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
584 error ("@%s/subsasgn returned more than one value", |
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
|
585 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
|
586 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
587 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
588 retval = tmp(0); |
7338 | 589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
590 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
591 } |
8785
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8782
diff
changeset
|
592 } |
70f5a0375afd
oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents:
8782
diff
changeset
|
593 |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
594 // 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
|
595 // attempting to do the indexed assignment. |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
596 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
597 std::string method_class = get_current_method_class (); |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
598 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
599 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
|
600 if (obvp != this) |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
601 { |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
602 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
603 if (! obvp) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
604 error ("malformed class"); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
605 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
606 obvp->subsasgn (type, idx, rhs); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
607 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
608 count++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
609 retval = octave_value (this); |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
610 |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
611 return retval; |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
612 } |
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
613 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 // FIXME: this block of code is the same as the body of |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
615 // octave_struct::subsasgn. Maybe it could be shared instead of |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
616 // duplicated. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
617 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
618 int n = type.length (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
619 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
620 octave_value t_rhs = rhs; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
621 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
622 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
623 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
624 switch (type[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
625 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
626 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
627 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
628 if (type.length () > 1 && type[1] == '.') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
629 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
630 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
|
631 octave_value_list t_idx = *p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
632 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
633 octave_value_list key_idx = *++p; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
634 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
635 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
636 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
637 std::string key = key_idx(0).xstring_value ("invalid index for class assignment"); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
638 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
639 octave_value u; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
640 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
641 if (! map.contains (key)) |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
642 u = octave_value::empty_conv (type.substr (2), rhs); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
643 else |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
644 { |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
645 Cell map_val = map.contents (key); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
646 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
647 Cell map_elt = map_val.index (idx.front (), true); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
648 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
649 u = numeric_conv (map_elt, type.substr (2)); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
650 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
651 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
652 std::list<octave_value_list> next_idx (idx); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
653 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
654 // We handled two index elements, so subsasgn to |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
655 // needs to skip both of them. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
656 |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
657 next_idx.erase (next_idx.begin ()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
658 next_idx.erase (next_idx.begin ()); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
659 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
660 u.make_unique (); |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
661 |
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
662 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
663 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
664 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
665 gripe_invalid_index_for_assignment (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
666 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
667 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
668 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
669 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
670 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
671 octave_value_list key_idx = idx.front (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
672 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
673 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
674 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
675 std::string key = key_idx(0).string_value (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
676 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
677 std::list<octave_value_list> next_idx (idx); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
678 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
679 next_idx.erase (next_idx.begin ()); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
680 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
681 std::string next_type = type.substr (1); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
682 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
683 Cell tmpc (1, 1); |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
684 octave_map::iterator pkey = map.seek (key); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
685 if (pkey != map.end ()) |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
686 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
687 map.contents (pkey).make_unique (); |
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
688 tmpc = map.contents (pkey); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
689 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
690 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
691 // FIXME: better code reuse? |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
692 if (tmpc.numel () == 1) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
693 { |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
694 octave_value& tmp = tmpc(0); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
695 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
696 if (! tmp.is_defined () || tmp.is_zero_by_zero ()) |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
697 { |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
698 tmp = octave_value::empty_conv (next_type, rhs); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
699 tmp.make_unique (); // probably a no-op. |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
700 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
701 else |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
702 // optimization: ignore copy still stored inside our map. |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
703 tmp.make_unique (1); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
704 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
705 t_rhs = tmp.subsasgn (next_type, next_idx, rhs); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
706 } |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
707 else |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
708 gripe_indexed_cs_list (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
709 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
710 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
711 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
712 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
713 gripe_invalid_index_type (type_name (), type[0]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
714 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
715 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
716 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
717 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
718 } |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
719 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
720 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
721 switch (type[0]) |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
722 { |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
723 case '(': |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
724 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
725 if (n > 1 && type[1] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
726 { |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
727 std::list<octave_value_list>::const_iterator p = idx.begin (); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
728 octave_value_list key_idx = *++p; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
729 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
730 assert (key_idx.length () == 1); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
731 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
732 std::string key = key_idx(0).xstring_value ("assignment to class element failed"); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
733 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
734 map.assign (idx.front (), key, t_rhs); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
735 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
736 count++; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
737 retval = octave_value (this); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
738 } |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
739 else |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
740 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
741 if (t_rhs.is_object () || t_rhs.is_map ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
742 { |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
743 octave_map rhs_map = t_rhs.xmap_value ("invalid class assignment"); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
744 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
745 map.assign (idx.front (), rhs_map); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
746 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
747 count++; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
748 retval = octave_value (this); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
749 } |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
750 else |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
751 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
752 if (! t_rhs.is_empty ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
753 error ("invalid class assignment"); |
20679
19d6f94c21cb
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20584
diff
changeset
|
754 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
755 map.delete_elements (idx.front ()); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
756 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
757 count++; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
758 retval = octave_value (this); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
759 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
760 } |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
761 } |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
762 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
763 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
764 case '.': |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
765 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
766 octave_value_list key_idx = idx.front (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
767 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
768 assert (key_idx.length () == 1); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
769 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
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 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
772 if (t_rhs.is_cs_list ()) |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
773 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
774 Cell tmp_cell = Cell (t_rhs.list_value ()); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
775 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
776 // The shape of the RHS is irrelevant, we just want |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
777 // the number of elements to agree and to preserve the |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
778 // shape of the left hand side of the assignment. |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
779 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
780 if (numel () == tmp_cell.numel ()) |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
781 tmp_cell = tmp_cell.reshape (dims ()); |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
782 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
783 map.setfield (key, tmp_cell); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
784 } |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
785 else |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
786 { |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
787 Cell tmp_cell(1, 1); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
788 tmp_cell(0) = t_rhs.storable_value (); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
789 map.setfield (key, tmp_cell); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
790 } |
12127
b83162e8f402
fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents:
11586
diff
changeset
|
791 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
792 count++; |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
793 retval = octave_value (this); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
794 } |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
795 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
796 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
797 case '{': |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
798 gripe_invalid_index_type (type_name (), type[0]); |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
799 break; |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
800 |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
801 default: |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
802 panic_impossible (); |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
803 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
804 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
805 return retval; |
7338 | 806 } |
807 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
808 idx_vector |
18130
e473c4853afc
enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents:
18033
diff
changeset
|
809 octave_class::index_vector (bool require_integers) const |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
810 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
811 idx_vector retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
812 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
813 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
|
814 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
815 if (! meth.is_defined ()) |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
816 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
|
817 class_name ().c_str ()); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
818 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
819 octave_value_list args; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
820 args(0) = octave_value (new octave_class (map, c_name, parent_list)); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
821 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
822 octave_value_list tmp = feval (meth.function_value (), args, 1); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
823 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
824 if (tmp(0).is_object ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
825 error ("subsindex function must return a valid index vector"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
826 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
827 // Index vector returned by subsindex is zero based |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
828 // (why this inconsistency Mathworks?), and so we must |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
829 // add one to the value returned as the index_vector method |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
830 // expects it to be one based. |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
831 retval = do_binary_op (octave_value::op_add, tmp (0), |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
832 octave_value (1.0)).index_vector (require_integers); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
833 |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
834 return retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
835 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
836 |
9529
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
837 size_t |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
838 octave_class::byte_size (void) const |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
839 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
840 // Neglect the size of the fieldnames. |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
841 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
842 size_t retval = 0; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
843 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
844 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
|
845 { |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
846 std::string key = map.key (p); |
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 octave_value val = octave_value (map.contents (p)); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
849 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
850 retval += val.byte_size (); |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
851 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
852 |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
853 return retval; |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
854 } |
8e5009334661
partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents:
9522
diff
changeset
|
855 |
7338 | 856 string_vector |
857 octave_class::map_keys (void) const | |
858 { | |
859 string_vector retval; | |
860 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ()); | |
861 return retval; | |
862 } | |
863 | |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
864 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
|
865 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
|
866 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
867 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
|
868 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
869 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
|
870 retval = this; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
871 else |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
872 { |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
873 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
|
874 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
875 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
876 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
877 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
|
878 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
879 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
|
880 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
881 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
|
882 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
883 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
|
884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
885 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
|
886 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
887 if (retval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
888 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
889 } |
9148
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
890 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
891 |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
892 return retval; |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
893 } |
69e6bbfef8c2
ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents:
9147
diff
changeset
|
894 |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
895 octave_base_value * |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
896 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
|
897 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
898 octave_base_value* retval = 0; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
899 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
900 if (parent_class_name == class_name ()) |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
901 retval = this; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
902 else |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
903 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
904 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
|
905 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
906 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
907 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
908 octave_map::iterator smap = map.seek (*pit); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
909 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
910 Cell& tmp = map.contents (smap); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
911 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
912 octave_value& vtmp = tmp(0); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
913 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
914 octave_base_value *obvp = vtmp.internal_rep (); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
915 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
916 // 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
|
917 retval = obvp->find_parent_class (parent_class_name); |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
918 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
919 if (retval) |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
920 { |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
921 vtmp.make_unique (); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
922 obvp = vtmp.internal_rep (); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
923 retval = obvp->unique_parent_class (parent_class_name); |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
924 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
925 break; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
926 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
927 } |
9767
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
928 } |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
929 |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
930 return retval; |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
931 } |
0df32e0b2074
fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9691
diff
changeset
|
932 |
19103
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
933 bool |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
934 octave_class::is_instance_of (const std::string& cls_name) const |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
935 { |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
936 bool retval = false; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
937 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
938 if (cls_name == class_name ()) |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
939 retval = true; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
940 else |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
941 { |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
942 for (std::list<std::string>::const_iterator pit = parent_list.begin (); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
943 pit != parent_list.end (); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
944 pit++) |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
945 { |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
946 octave_map::const_iterator smap = map.seek (*pit); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
947 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
948 const Cell& tmp = map.contents (smap); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
949 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
950 const octave_value& vtmp = tmp(0); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
951 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
952 retval = vtmp.is_instance_of (cls_name); |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
953 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
954 if (retval) |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
955 break; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
956 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
957 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
958 |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
959 return retval; |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
960 } |
56bc1464ec59
Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18881
diff
changeset
|
961 |
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
|
962 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
|
963 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
|
964 { |
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
|
965 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
|
966 |
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
|
967 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
|
968 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
969 if (! meth.is_defined ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
970 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
|
971 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
972 octave_value_list args; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
973 args(0) = octave_value (new octave_class (map, c_name, parent_list)); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
974 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
975 octave_value_list tmp = feval (meth.function_value (), args, 1); |
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
|
976 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
977 if (tmp.length () >= 1) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
978 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
979 if (tmp(0).is_string ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
980 retval = tmp(0).all_strings (pad); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
981 else |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
982 error ("cname/char method did not return a string"); |
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
|
983 } |
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
|
984 |
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
|
985 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
|
986 } |
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
|
987 |
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
|
988 |
7338 | 989 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
990 octave_class::print (std::ostream& os, bool) |
7338 | 991 { |
992 print_raw (os); | |
993 } | |
994 | |
995 void | |
996 octave_class::print_raw (std::ostream& os, bool) const | |
997 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
998 unwind_protect frame; |
7338 | 999 |
1000 indent (os); | |
1001 os << " <class " << class_name () << ">"; | |
1002 newline (os); | |
1003 } | |
1004 | |
1005 bool | |
1006 octave_class::print_name_tag (std::ostream& os, const std::string& name) const | |
1007 { | |
1008 bool retval = false; | |
1009 | |
1010 indent (os); | |
1011 os << name << " ="; | |
1012 newline (os); | |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12620
diff
changeset
|
1013 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12620
diff
changeset
|
1014 newline (os); |
7338 | 1015 |
1016 return retval; | |
1017 } | |
1018 | |
1019 void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1020 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
|
1021 bool) |
7338 | 1022 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1023 octave_value fcn = symbol_table::find_method ("display", class_name ()); |
7338 | 1024 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1025 if (fcn.is_defined ()) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1026 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1027 octave_value_list args; |
7338 | 1028 |
9521 | 1029 count++; |
1030 args(0) = octave_value (this); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1031 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1032 string_vector arg_names (1); |
7338 | 1033 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1034 arg_names[0] = name; |
7338 | 1035 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1036 args.stash_name_tags (arg_names); |
7338 | 1037 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1038 feval (fcn.function_value (), args); |
7338 | 1039 } |
10204
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1040 else |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1041 { |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1042 indent (os); |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1043 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
|
1044 newline (os); |
1d430a849f3c
print class name for classes that don't define a display method
jstorrs@gmail.com
parents:
10160
diff
changeset
|
1045 } |
7338 | 1046 } |
1047 | |
9190 | 1048 // 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
|
1049 // If we don't have one, we attempt to create one by calling the constructor |
9190 | 1050 // with no arguments. |
1051 bool | |
1052 octave_class::reconstruct_exemplar (void) | |
1053 { | |
1054 bool retval = false; | |
1055 | |
1056 octave_class::exemplar_const_iterator it | |
1057 = octave_class::exemplar_map.find (c_name); | |
1058 | |
1059 if (it != octave_class::exemplar_map.end ()) | |
1060 retval = true; | |
1061 else | |
1062 { | |
1063 octave_value ctor = symbol_table::find_method (c_name, c_name); | |
1064 | |
12178
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1065 bool have_ctor = false; |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1066 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1067 if (ctor.is_defined () && ctor.is_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1068 { |
12178
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1069 octave_function *fcn = ctor.function_value (); |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1070 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1071 if (fcn && fcn->is_class_constructor (c_name)) |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1072 have_ctor = true; |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1073 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1074 // Something has gone terribly wrong if |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1075 // 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
|
1076 // a class constructor for the class c_name... |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1077 assert (have_ctor); |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1078 } |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1079 |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1080 if (have_ctor) |
a71c1aa9823e
fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents:
12171
diff
changeset
|
1081 { |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1082 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
|
1083 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1084 // 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
|
1085 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1086 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
|
1087 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1088 bool execution_error = false; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1089 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1090 octave_value_list result; |
9190 | 1091 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1092 try |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1093 { |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1094 result = ctor.do_multi_index_op (1, octave_value_list ()); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1095 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1096 catch (const octave_execution_exception&) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1097 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1098 recover_from_exception (); |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20747
diff
changeset
|
1099 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1100 execution_error = true; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1101 } |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1102 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20495
diff
changeset
|
1103 if (! execution_error && result.length () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1104 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1105 } |
9190 | 1106 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1107 warning ("no constructor for class %s", c_name.c_str ()); |
9190 | 1108 } |
1109 | |
1110 return retval; | |
1111 } | |
1112 | |
9240
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1113 void |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1114 octave_class::clear_exemplar_map (void) |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1115 { |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1116 exemplar_map.clear (); |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1117 } |
f27a8c07f0b2
clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents:
9206
diff
changeset
|
1118 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1119 // 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
|
1120 // class inheritance structure. reconstruct_parents () attempts to |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1121 // 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
|
1122 // |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1123 // 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
|
1124 // 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
|
1125 // to do its magic. |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1126 bool |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1127 octave_class::reconstruct_parents (void) |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1128 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18033
diff
changeset
|
1129 bool retval = true; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18033
diff
changeset
|
1130 bool might_have_inheritance = false; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1131 std::string dbgstr = "dork"; |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1132 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1133 // 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
|
1134 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
|
1135 { |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1136 std::string key = map.key (p); |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1137 Cell val = map.contents (p); |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18637
diff
changeset
|
1138 if (val(0).is_object ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1139 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1140 dbgstr = "blork"; |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18637
diff
changeset
|
1141 if (key == val(0).class_name ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1142 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1143 might_have_inheritance = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1144 dbgstr = "cork"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1145 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1146 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1147 } |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1148 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1149 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1150 if (might_have_inheritance) |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1151 { |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1152 octave_class::exemplar_const_iterator it |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1153 = 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
|
1154 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1155 if (it == octave_class::exemplar_map.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1156 retval = false; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1157 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1159 octave_class::exemplar_info exmplr = it->second; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1160 parent_list = exmplr.parents (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1161 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
|
1162 pit != parent_list.end (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1163 pit++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1164 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1165 dbgstr = *pit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1166 bool dbgbool = map.contains (*pit); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
1167 if (! dbgbool) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1168 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1169 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1170 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1171 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1172 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1173 } |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1174 } |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1175 |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1176 return retval; |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1177 } |
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1178 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1179 bool |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1180 octave_class::save_ascii (std::ostream& os) |
7338 | 1181 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1182 os << "# classname: " << class_name () << "\n"; |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1183 octave_map m; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1184 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
|
1185 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1186 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
|
1187 octave_value_list tmp = feval ("saveobj", in, 1); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1188 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1189 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
|
1190 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1191 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1192 m = map_value (); |
7338 | 1193 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1194 os << "# length: " << m.nfields () << "\n"; |
7338 | 1195 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1196 octave_map::iterator i = m.begin (); |
7338 | 1197 while (i != m.end ()) |
1198 { | |
1199 octave_value val = map.contents (i); | |
1200 | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1201 bool b = save_text_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
|
1202 |
7338 | 1203 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
1204 return ! os.fail (); |
7338 | 1205 |
1206 i++; | |
1207 } | |
1208 | |
1209 return true; | |
1210 } | |
1211 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1212 bool |
7338 | 1213 octave_class::load_ascii (std::istream& is) |
1214 { | |
1215 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
|
1216 std::string classname; |
7338 | 1217 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1218 if (extract_keyword (is, "classname", classname) && classname != "") |
7338 | 1219 { |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1220 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
|
1221 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1222 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1223 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1224 octave_map m (map); |
7338 | 1225 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1226 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
|
1227 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1228 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1229 bool dummy; |
7338 | 1230 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1231 // recurse to read cell elements |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1232 std::string nm |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
1233 = read_text_data (is, std::string (), dummy, t2, j); |
7338 | 1234 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1235 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1236 break; |
7338 | 1237 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1238 Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1239 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1240 m.assign (nm, tcell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1241 } |
7338 | 1242 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1243 if (! is) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1244 error ("load: failed to load class"); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1245 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1246 c_name = classname; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1247 reconstruct_exemplar (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1248 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1249 map = m; |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1250 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1251 if (! reconstruct_parents ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1252 warning ("load: unable to reconstruct object inheritance"); |
7338 | 1253 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1254 if (load_path::find_method (classname, "loadobj") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1255 != std::string ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1256 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1257 octave_value in = new octave_class (*this); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1258 octave_value_list tmp = feval ("loadobj", in, 1); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1259 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1260 map = tmp(0).map_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1262 } |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18637
diff
changeset
|
1263 else if (len == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1264 { |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1265 map = octave_map (dim_vector (1, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1266 c_name = classname; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1268 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1269 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1270 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1271 else |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
1272 error ("load: failed to extract number of elements in class"); |
7338 | 1273 } |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1274 else |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
1275 error ("load: failed to extract name of class"); |
7338 | 1276 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
1277 return true; |
7338 | 1278 } |
1279 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1280 bool |
7338 | 1281 octave_class::save_binary (std::ostream& os, bool& save_as_floats) |
1282 { | |
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
|
1283 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
|
1284 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1285 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
|
1286 os << class_name (); |
7338 | 1287 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1288 octave_map m; |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1289 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
|
1290 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1291 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
|
1292 octave_value_list tmp = feval ("saveobj", in, 1); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1293 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1294 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
|
1295 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1296 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1297 m = map_value (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1298 |
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
|
1299 int32_t len = m.nfields (); |
7338 | 1300 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
|
1301 |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1302 octave_map::iterator i = m.begin (); |
7338 | 1303 while (i != m.end ()) |
1304 { | |
1305 octave_value val = map.contents (i); | |
1306 | |
1307 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
|
1308 |
7338 | 1309 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
1310 return ! os.fail (); |
7338 | 1311 |
1312 i++; | |
1313 } | |
1314 | |
1315 return true; | |
1316 } | |
1317 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1318 bool |
7338 | 1319 octave_class::load_binary (std::istream& is, bool swap, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1320 oct_mach_info::float_format fmt) |
7338 | 1321 { |
1322 bool success = true; | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1323 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1324 int32_t classname_len; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1325 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1326 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
|
1327 if (! is) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1328 return false; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1329 else if (swap) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1330 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
|
1331 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1332 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1333 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
|
1334 classname[classname_len] = '\0'; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1335 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
|
1336 return false; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1337 c_name = classname; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1338 } |
9190 | 1339 reconstruct_exemplar (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1340 |
7338 | 1341 int32_t len; |
1342 if (! is.read (reinterpret_cast<char *> (&len), 4)) | |
1343 return false; | |
1344 if (swap) | |
1345 swap_bytes<4> (&len); | |
1346 | |
1347 if (len > 0) | |
1348 { | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1349 octave_map m (map); |
7338 | 1350 |
1351 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
|
1352 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1353 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1354 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1355 std::string doc; |
7338 | 1356 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1357 // recurse to read cell elements |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1358 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
|
1359 dummy, t2, doc); |
7338 | 1360 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1361 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1362 break; |
7338 | 1363 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1364 Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); |
7338 | 1365 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1366 m.assign (nm, tcell); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1367 } |
7338 | 1368 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1369 if (is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1370 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1371 map = m; |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1372 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1373 if (! reconstruct_parents ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1374 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
|
1375 |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1376 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
|
1377 { |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1378 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
|
1379 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
|
1380 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1381 map = tmp(0).map_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1382 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1383 } |
7338 | 1384 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1385 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1386 warning ("load: failed to load class"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1387 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1388 } |
7338 | 1389 } |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18637
diff
changeset
|
1390 else if (len == 0) |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1391 map = octave_map (dim_vector (1, 1)); |
7338 | 1392 else |
1393 panic_impossible (); | |
1394 | |
1395 return success; | |
1396 } | |
1397 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1398 bool |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1399 octave_class::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1400 { |
7338 | 1401 #if defined (HAVE_HDF5) |
1402 | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1403 hsize_t hdims[3]; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1404 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
|
1405 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
|
1406 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
|
1407 hid_t class_hid = -1; |
7338 | 1408 hid_t data_hid = -1; |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1409 octave_map m; |
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1410 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
|
1411 |
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
|
1412 #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
|
1413 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
|
1414 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1415 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
|
1416 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1417 if (group_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1418 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1419 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1420 // 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
|
1421 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
|
1422 if (type_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1423 goto error_cleanup; |
7338 | 1424 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1425 hdims[0] = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1426 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
|
1427 if (space_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1428 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
|
1429 #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
|
1430 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
|
1431 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
|
1432 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1433 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
|
1434 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
|
1435 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1436 if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1437 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
|
1438 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1439 |
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
|
1440 #if HAVE_HDF5_18 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1441 data_hid = H5Gcreate (group_hid, "value", H5P_DEFAULT, H5P_DEFAULT, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1442 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
|
1443 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1444 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
|
1445 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1446 if (data_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1447 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1448 |
9182
23af5910e5f5
make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents:
9156
diff
changeset
|
1449 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
|
1450 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1451 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
|
1452 octave_value_list tmp = feval ("saveobj", in, 1); |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1453 |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1454 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
|
1455 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1456 else |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1457 m = map_value (); |
7338 | 1458 |
1459 // 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
|
1460 i = m.begin (); |
7338 | 1461 while (i != m.end ()) |
1462 { | |
1463 octave_value val = map.contents (i); | |
1464 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1465 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
|
1466 save_as_floats); |
7338 | 1467 |
1468 if (! retval2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1469 break; |
7338 | 1470 |
1471 i++; | |
1472 } | |
1473 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1474 error_cleanup: |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1475 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1476 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1477 H5Gclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1478 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1479 if (class_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1480 H5Dclose (class_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1481 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1482 if (space_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1483 H5Sclose (space_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1484 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1485 if (type_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1486 H5Tclose (type_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1487 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1488 if (group_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1489 H5Gclose (group_hid); |
7338 | 1490 |
1491 return true; | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1492 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1493 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1494 gripe_save ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1495 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1496 #endif |
7338 | 1497 } |
1498 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1499 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1500 octave_class::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
7338 | 1501 { |
1502 bool retval = false; | |
1503 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1504 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1505 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1506 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
|
1507 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
|
1508 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
|
1509 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
|
1510 hid_t space_hid = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1511 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
|
1512 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
|
1513 |
7338 | 1514 hdf5_callback_data dsub; |
1515 | |
1516 herr_t retval2 = 0; | |
10768
8a868004a437
use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
1517 octave_map m (dim_vector (1, 1)); |
7338 | 1518 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
|
1519 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
|
1520 int slen = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1521 hsize_t rank = 0; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1522 |
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
|
1523 #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
|
1524 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
|
1525 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1526 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
|
1527 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1528 if (group_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1529 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1530 |
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
|
1531 #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
|
1532 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
|
1533 #else |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1534 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
|
1535 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1536 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1537 if (data_hid < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1538 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1539 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1540 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
|
1541 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1542 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
|
1543 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1544 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
|
1545 goto error_cleanup; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1546 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1547 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
|
1548 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
|
1549 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1550 if (rank != 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1551 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1552 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1553 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
|
1554 if (slen < 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1555 goto error_cleanup; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1556 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1557 // 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
|
1558 do |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1559 { |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1560 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
|
1561 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1562 // 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
|
1563 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
|
1564 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
|
1565 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1566 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
|
1567 classname) < 0) |
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 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1570 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1571 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1572 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1573 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1574 |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1575 H5Tclose (st_id); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1576 H5Dclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1577 data_hid = -1; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1578 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1579 c_name = classname; |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1580 } |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1581 while (0); |
9190 | 1582 reconstruct_exemplar (); |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1583 |
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
|
1584 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1585 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
|
1586 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1587 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
|
1588 #endif |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1589 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
|
1590 H5Gclose (subgroup_hid); |
7338 | 1591 |
1592 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
|
1593 && (retval2 = H5Giterate (group_hid, name, ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1594 hdf5_read_next_data, &dsub)) > 0) |
7338 | 1595 { |
1596 octave_value t2 = dsub.tc; | |
1597 | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1598 Cell tcell = t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2); |
7338 | 1599 |
1600 m.assign (dsub.name, tcell); | |
1601 | |
1602 } | |
1603 | |
1604 if (retval2 >= 0) | |
1605 { | |
1606 map = m; | |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1607 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
1608 if (! reconstruct_parents ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1609 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
|
1610 |
17473
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1611 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
|
1612 { |
9849075a5da6
allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents:
16071
diff
changeset
|
1613 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
|
1614 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
|
1615 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1616 map = tmp(0).map_value (); |
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1617 retval = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1618 } |
7338 | 1619 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1620 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1621 error_cleanup: |
8212
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1622 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1623 H5Dclose (data_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1624 |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1625 if (data_hid > 0) |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1626 H5Gclose (group_hid); |
ebf6f6a0f9a7
Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents:
8154
diff
changeset
|
1627 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1628 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1629 gripe_load ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1630 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
1631 |
7338 | 1632 return retval; |
1633 } | |
1634 | |
1635 mxArray * | |
1636 octave_class::as_mxArray (void) const | |
1637 { | |
1638 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ()); | |
1639 | |
1640 return 0; | |
1641 } | |
1642 | |
1643 bool | |
9581
3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents:
9580
diff
changeset
|
1644 octave_class::in_class_method (void) |
7338 | 1645 { |
1646 octave_function *fcn = octave_call_stack::current (); | |
1647 | |
1648 return (fcn | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1649 && (fcn->is_class_method () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1650 || fcn->is_class_constructor () |
13241
2a8dcb5b3a00
improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents:
13112
diff
changeset
|
1651 || fcn->is_anonymous_function_of_class () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1652 || fcn->is_private_function_of_class (class_name ())) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1653 && find_parent_class (fcn->dispatch_class ())); |
7338 | 1654 } |
1655 | |
9151 | 1656 octave_class::exemplar_info::exemplar_info (const octave_value& obj) |
1657 : field_names (), parent_class_names () | |
1658 { | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1659 if (! obj.is_object ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1660 error ("invalid call to exemplar_info constructor"); |
9151 | 1661 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1662 octave_map m = obj.map_value (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1663 field_names = m.keys (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1664 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1665 parent_class_names = obj.parent_class_name_list (); |
9151 | 1666 } |
1667 | |
1668 | |
1669 // A map from class names to lists of fields. | |
1670 std::map<std::string, octave_class::exemplar_info> octave_class::exemplar_map; | |
1671 | |
1672 bool | |
1673 octave_class::exemplar_info::compare (const octave_value& obj) const | |
1674 { | |
1675 | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1676 if (! obj.is_object ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1677 error ("invalid comparison of class exemplar to non-class object"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1678 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1679 if (nfields () == obj.nfields ()) |
9151 | 1680 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1681 octave_map obj_map = obj.map_value (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1682 string_vector obj_fnames = obj_map.keys (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1683 string_vector fnames = fields (); |
9151 | 1684 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1685 for (octave_idx_type i = 0; i < nfields (); i++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1686 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1687 if (obj_fnames[i] != fnames[i]) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1688 error ("mismatch in field names"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1689 } |
9151 | 1690 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1691 if (nparents () == obj.nparents ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1692 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1693 std::list<std::string> obj_parents |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1694 = obj.parent_class_name_list (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1695 std::list<std::string> pnames = parents (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1696 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1697 std::list<std::string>::const_iterator p = obj_parents.begin (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1698 std::list<std::string>::const_iterator q = pnames.begin (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1699 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1700 while (p != obj_parents.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1701 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1702 if (*p++ != *q++) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1703 error ("mismatch in parent classes"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1704 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1705 } |
9151 | 1706 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1707 error ("mismatch in number of parent classes"); |
9151 | 1708 } |
1709 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1710 error ("mismatch in number of fields"); |
9151 | 1711 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
1712 return true; |
9151 | 1713 } |
1714 | |
7338 | 1715 DEFUN (class, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1716 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1717 @deftypefn {} {@var{classname} =} class (@var{obj})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1718 @deftypefnx {} {} class (@var{s}, @var{id})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1719 @deftypefnx {} {} class (@var{s}, @var{id}, @var{p}, @dots{})\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
1720 Return the class of the object @var{obj}, or create a class with\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
1721 fields from structure @var{s} and name (string) @var{id}.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
1722 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
1723 Additional arguments name a list of parent classes from which the new class\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
1724 is derived.\n\ |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1725 @seealso{typeinfo, isa}\n\ |
7338 | 1726 @end deftypefn") |
1727 { | |
1728 int nargin = args.length (); | |
1729 | |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1730 if (nargin == 0) |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1731 print_usage (); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1732 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1733 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1734 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1735 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
|
1736 // 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
|
1737 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
|
1738 else |
7338 | 1739 { |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1740 // Called as class constructor |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1741 std::string id = args(1).xstring_value ("class: ID (class name) must be a string"); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
1742 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1743 octave_function *fcn = octave_call_stack::caller (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1744 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1745 if (! fcn) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1746 error ("class: invalid call from outside class constructor or method"); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20561
diff
changeset
|
1747 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1748 if (! fcn->is_class_constructor (id) && ! fcn->is_class_method (id)) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1749 error ("class: '%s' is invalid as a class name in this context", |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1750 id.c_str ()); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1751 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1752 octave_map m = args(0).xmap_value ("class: S must be a valid structure"); |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1753 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1754 if (nargin == 2) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1755 retval |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1756 = octave_value (new octave_class (m, id, std::list<std::string> ())); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1757 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1758 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1759 octave_value_list parents = args.slice (2, nargin-2); |
11220
883b9308353c
allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents:
10932
diff
changeset
|
1760 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1761 retval = octave_value (new octave_class (m, id, parents)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10272
diff
changeset
|
1762 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1763 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1764 octave_class::exemplar_const_iterator it |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1765 = octave_class::exemplar_map.find (id); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1766 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1767 if (it == octave_class::exemplar_map.end ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1768 octave_class::exemplar_map[id] = octave_class::exemplar_info (retval); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1769 else if (! it->second.compare (retval)) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1770 error ("class: object of class '%s' does not match previously constructed objects", |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1771 id.c_str ()); |
7338 | 1772 } |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1773 |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1774 return retval; |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1775 } |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1776 |
15811
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1777 /* |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1778 %!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
|
1779 %!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
|
1780 %!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
|
1781 %!testif HAVE_JAVA |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1782 %! 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
|
1783 %! 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
|
1784 |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1785 %% Test Input Validation |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1786 %!error class () |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1787 */ |
317f4857c1e1
Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents:
15785
diff
changeset
|
1788 |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1789 DEFUN (isa, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1790 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1791 @deftypefn {} {} isa (@var{obj}, @var{classname})\n\ |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1792 Return true if @var{obj} is an object from the class @var{classname}.\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1793 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1794 @var{classname} may also be one of the following class categories:\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1795 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1796 @table @asis\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1797 @item @qcode{\"float\"}\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1798 Floating point value comprising classes @qcode{\"double\"} and\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1799 @qcode{\"single\"}.\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1800 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1801 @item @qcode{\"integer\"}\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1802 Integer value comprising classes (u)int8, (u)int16, (u)int32, (u)int64.\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1803 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1804 @item @qcode{\"numeric\"}\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1805 Numeric value comprising either a floating point or integer value.\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1806 @end table\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1807 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1808 If @var{classname} is a cell array of string, a logical array of the same\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1809 size is returned, containing true for each class to which @var{obj}\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1810 belongs to.\n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1811 \n\ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1812 @seealso{class, typeinfo}\n\ |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1813 @end deftypefn") |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1814 { |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1815 if (args.length () != 2) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1816 print_usage (); |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1817 |
20495 | 1818 octave_value obj = args(0); // not const because of find_parent_class () |
1819 std::string obj_cls = obj.class_name (); | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
1820 Array<std::string> clsnames = args(1).xcellstr_value ("isa: CLASSNAME must be a string or cell array of strings"); |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1821 |
20495 | 1822 boolNDArray matches (clsnames.dims (), false); |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1823 |
20495 | 1824 for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++) |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1825 { |
20495 | 1826 std::string cls = clsnames(idx); |
1827 if (obj_cls == cls | |
1828 || (cls == "float" && obj.is_float_type ()) | |
1829 || (cls == "integer" && obj.is_integer_type ()) | |
1830 || (cls == "numeric" && obj.is_numeric_type ()) | |
1831 || obj.is_instance_of (cls)) | |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1832 matches(idx) = true; |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1833 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1834 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1835 return ovl (matches); |
9147
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1836 } |
5579998f8acf
Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents:
9010
diff
changeset
|
1837 |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1838 /* |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1839 %!assert (isa ("char", "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1840 %!assert (isa (logical (1), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1841 %!assert (isa (double (13), "float"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1842 %!assert (isa (single (13), "float"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1843 %!assert (isa (int8 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1844 %!assert (isa (int16 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1845 %!assert (isa (int32 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1846 %!assert (isa (int64 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1847 %!assert (isa (uint8 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1848 %!assert (isa (uint16 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1849 %!assert (isa (uint32 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1850 %!assert (isa (uint64 (13), "float"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1851 %!assert (isa ("char", "numeric"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1852 %!assert (isa (logical (1), "numeric"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1853 %!assert (isa (double (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1854 %!assert (isa (single (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1855 %!assert (isa (int8 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1856 %!assert (isa (int16 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1857 %!assert (isa (int32 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1858 %!assert (isa (int64 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1859 %!assert (isa (uint8 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1860 %!assert (isa (uint16 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1861 %!assert (isa (uint32 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1862 %!assert (isa (uint64 (13), "numeric"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1863 %!assert (isa (uint8 (13), "integer"), true) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1864 %!assert (isa (double (13), "integer"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1865 %!assert (isa (single (13), "integer"), false) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1866 %!assert (isa (single (13), {"integer", "float", "single"}), [false true true]) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1867 |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1868 %!assert (isa (double (13), "double")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1869 %!assert (isa (single (13), "single")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1870 %!assert (isa (int8 (13), "int8")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1871 %!assert (isa (int16 (13), "int16")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1872 %!assert (isa (int32 (13), "int32")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1873 %!assert (isa (int64 (13), "int64")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1874 %!assert (isa (uint8 (13), "uint8")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1875 %!assert (isa (uint16 (13), "uint16")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1876 %!assert (isa (uint32 (13), "uint32")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1877 %!assert (isa (uint64 (13), "uint64")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1878 %!assert (isa ("string", "char")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1879 %!assert (isa (true, "logical")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1880 %!assert (isa (false, "logical")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1881 %!assert (isa ({1, 2}, "cell")) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1882 %!assert (isa ({1, 2}, {"numeric", "integer", "cell"}), [false false true]) |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1883 |
20028
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1884 %!testif HAVE_JAVA |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1885 %! ## The first and last assert() are equal on purpose. The assert() in |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1886 %! ## the middle with an invalid class name will cause the java code to |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1887 %! ## throw exceptions which we then must clear properly (or all other calls |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1888 %! ## will fail). So we test this too. |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1889 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number")) |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1890 %! assert (isa (javaObject ("java.lang.Double", 10), "not_a_class"), false) |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1891 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number")) |
107130a0490c
isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents:
19864
diff
changeset
|
1892 |
18033
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1893 %!test |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1894 %! a.b = 1; |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1895 %! assert (isa (a, "struct")); |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1896 */ |
2627aeca5032
isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents:
17787
diff
changeset
|
1897 |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1898 DEFUN (__parent_classes__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1899 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1900 @deftypefn {} {} __parent_classes__ (@var{x})\n\ |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1901 Undocumented internal function.\n\ |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1902 @end deftypefn") |
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1903 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1904 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1905 print_usage (); |
9010
f914834836e7
Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents:
8920
diff
changeset
|
1906 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1907 octave_value arg = args(0); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1908 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1909 if (arg.is_object ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1910 return ovl (Cell (arg.parent_class_names ())); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1911 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1912 return ovl (Cell ()); |
7338 | 1913 } |
1914 | |
1915 DEFUN (isobject, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1916 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1917 @deftypefn {} {} isobject (@var{x})\n\ |
7338 | 1918 Return true if @var{x} is a class object.\n\ |
18637
2631484789cf
doc: Improve docstrings for isobject, ismethod, isprop.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
1919 @seealso{class, typeinfo, isa, ismethod, isprop}\n\ |
7338 | 1920 @end deftypefn") |
1921 { | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1922 if (args.length () != 1) |
7338 | 1923 print_usage (); |
1924 | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1925 return ovl (args(0).is_object ()); |
7338 | 1926 } |
1927 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1928 DEFUN (ismethod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1929 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1930 @deftypefn {} {} ismethod (@var{obj}, @var{method})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1931 @deftypefnx {} {} ismethod (@var{clsname}, @var{method})\n\ |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
1932 Return true if the string @var{method} is a valid method of the object\n\ |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
1933 @var{obj} or of the class @var{clsname}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
1934 @seealso{isprop, isobject}\n\ |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1935 @end deftypefn") |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1936 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1937 if (args.length () != 2) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1938 print_usage (); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1939 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1940 octave_value arg = args(0); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1941 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1942 std::string class_name; |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1943 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1944 if (arg.is_object ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1945 class_name = arg.class_name (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1946 else if (arg.is_string ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1947 class_name = arg.string_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1948 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1949 error ("ismethod: first argument must be object or class name"); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1950 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1951 std::string method = args(1).string_value (); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1952 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1953 if (load_path::find_method (class_name, method) != std::string ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1954 return ovl (true); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1955 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1956 return ovl (false); |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1957 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1958 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1959 DEFUN (__methods__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1960 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1961 @deftypefn {} {} __methods__ (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
1962 @deftypefnx {} {} __methods__ (\"classname\")\n\ |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1963 Internal function.\n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1964 \n\ |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1965 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
|
1966 @seealso{methods}\n\ |
7338 | 1967 @end deftypefn") |
1968 { | |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1969 // 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
|
1970 octave_value arg = args(0); |
7338 | 1971 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1972 std::string class_name; |
7338 | 1973 |
15785
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1974 if (arg.is_object ()) |
42cff4396de4
Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1975 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
|
1976 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
|
1977 class_name = arg.string_value (); |
7338 | 1978 |
20561
c41595061186
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
1979 string_vector sv = load_path::methods (class_name); |
7338 | 1980 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1981 return ovl (Cell (sv)); |
7338 | 1982 } |
1983 | |
1984 static bool | |
1985 is_built_in_class (const std::string& cn) | |
1986 { | |
1987 static std::set<std::string> built_in_class_names; | |
1988 | |
1989 if (built_in_class_names.empty ()) | |
1990 { | |
1991 built_in_class_names.insert ("double"); | |
1992 built_in_class_names.insert ("single"); | |
1993 built_in_class_names.insert ("cell"); | |
1994 built_in_class_names.insert ("struct"); | |
1995 built_in_class_names.insert ("logical"); | |
1996 built_in_class_names.insert ("char"); | |
1997 built_in_class_names.insert ("function handle"); | |
1998 built_in_class_names.insert ("int8"); | |
1999 built_in_class_names.insert ("uint8"); | |
2000 built_in_class_names.insert ("int16"); | |
2001 built_in_class_names.insert ("uint16"); | |
2002 built_in_class_names.insert ("int32"); | |
2003 built_in_class_names.insert ("uint32"); | |
2004 built_in_class_names.insert ("int64"); | |
2005 built_in_class_names.insert ("uint64"); | |
2006 } | |
2007 | |
2008 return built_in_class_names.find (cn) != built_in_class_names.end (); | |
2009 } | |
2010 | |
2011 DEFUN (superiorto, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2012 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
2013 @deftypefn {} {} superiorto (@var{class_name}, @dots{})\n\ |
7338 | 2014 When called from a class constructor, mark the object currently\n\ |
2015 constructed as having a higher precedence than @var{class_name}.\n\ | |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
2016 \n\ |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2017 More that one such class can be specified in a single call.\n\ |
7338 | 2018 This function may only be called from a class constructor.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
2019 @seealso{inferiorto}\n\ |
7338 | 2020 @end deftypefn") |
2021 { | |
2022 octave_function *fcn = octave_call_stack::caller (); | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
2023 if (! fcn || ! fcn->is_class_constructor ()) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2024 error ("superiorto: invalid call from outside class constructor"); |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2025 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2026 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
|
2027 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
2028 std::string inf_class = args(i).xstring_value ("superiorto: CLASS_NAME must be a string"); |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2029 |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2030 // 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
|
2031 // 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
|
2032 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
|
2033 break; |
7338 | 2034 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2035 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
|
2036 if (! symbol_table::set_class_relationship (sup_class, inf_class)) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2037 error ("superiorto: opposite precedence already set for %s and %s", |
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2038 sup_class.c_str (), inf_class.c_str ()); |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2039 } |
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2040 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2041 return octave_value (); |
7338 | 2042 } |
2043 | |
2044 DEFUN (inferiorto, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2045 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20797
diff
changeset
|
2046 @deftypefn {} {} inferiorto (@var{class_name}, @dots{})\n\ |
7338 | 2047 When called from a class constructor, mark the object currently\n\ |
2048 constructed as having a lower precedence than @var{class_name}.\n\ | |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20028
diff
changeset
|
2049 \n\ |
8219
f8a885ccd5b4
allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents:
8212
diff
changeset
|
2050 More that one such class can be specified in a single call.\n\ |
7338 | 2051 This function may only be called from a class constructor.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
18384
diff
changeset
|
2052 @seealso{superiorto}\n\ |
7338 | 2053 @end deftypefn") |
2054 { | |
2055 octave_function *fcn = octave_call_stack::caller (); | |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
2056 if (! fcn || ! fcn->is_class_constructor ()) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2057 error ("inferiorto: invalid call from outside class constructor"); |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2058 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2059 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
|
2060 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
2061 std::string sup_class = args(i).xstring_value ("inferiorto: CLASS_NAME must be a string"); |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2062 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2063 if (is_built_in_class (sup_class)) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2064 error ("inferiorto: cannot give user-defined class lower " |
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2065 "precedence than built-in class"); |
16071
94e95309710c
Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
16070
diff
changeset
|
2066 |
16070
e603ce23f20c
Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents:
15813
diff
changeset
|
2067 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
|
2068 if (! symbol_table::set_class_relationship (sup_class, inf_class)) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2069 error ("inferiorto: opposite precedence already set for %s and %s", |
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2070 inf_class.c_str (), sup_class.c_str ()); |
7338 | 2071 } |
2072 | |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
2073 return octave_value(); |
7338 | 2074 } |