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