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