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