2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
4970
|
28 #include "data-conv.h" |
|
29 #include "quit.h" |
2942
|
30 #include "str-vec.h" |
2376
|
31 |
2974
|
32 #include "oct-obj.h" |
4944
|
33 #include "oct-stream.h" |
2376
|
34 #include "ov.h" |
|
35 #include "ov-base.h" |
2825
|
36 #include "ov-bool.h" |
|
37 #include "ov-bool-mat.h" |
3351
|
38 #include "ov-cell.h" |
2376
|
39 #include "ov-scalar.h" |
|
40 #include "ov-re-mat.h" |
5164
|
41 #include "ov-bool-sparse.h" |
|
42 #include "ov-cx-sparse.h" |
|
43 #include "ov-re-sparse.h" |
4901
|
44 #include "ov-int8.h" |
|
45 #include "ov-int16.h" |
|
46 #include "ov-int32.h" |
|
47 #include "ov-int64.h" |
|
48 #include "ov-uint8.h" |
|
49 #include "ov-uint16.h" |
|
50 #include "ov-uint32.h" |
|
51 #include "ov-uint64.h" |
2376
|
52 #include "ov-complex.h" |
|
53 #include "ov-cx-mat.h" |
|
54 #include "ov-ch-mat.h" |
|
55 #include "ov-str-mat.h" |
|
56 #include "ov-range.h" |
|
57 #include "ov-struct.h" |
4643
|
58 #include "ov-streamoff.h" |
2880
|
59 #include "ov-list.h" |
3977
|
60 #include "ov-cs-list.h" |
2376
|
61 #include "ov-colon.h" |
2974
|
62 #include "ov-builtin.h" |
|
63 #include "ov-mapper.h" |
4649
|
64 #include "ov-dld-fcn.h" |
2974
|
65 #include "ov-usr-fcn.h" |
4342
|
66 #include "ov-fcn-handle.h" |
4966
|
67 #include "ov-fcn-inline.h" |
2376
|
68 #include "ov-typeinfo.h" |
|
69 |
|
70 #include "defun.h" |
2880
|
71 #include "error.h" |
2376
|
72 #include "gripes.h" |
|
73 #include "pager.h" |
4005
|
74 #include "parse.h" |
2376
|
75 #include "pr-output.h" |
|
76 #include "utils.h" |
|
77 #include "variables.h" |
|
78 |
2477
|
79 // We are likely to have a lot of octave_value objects to allocate, so |
|
80 // make the grow_size large. |
3219
|
81 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477
|
82 |
5775
|
83 // FIXME |
2880
|
84 |
2376
|
85 // Octave's value type. |
|
86 |
3536
|
87 std::string |
3203
|
88 octave_value::unary_op_as_string (unary_op op) |
|
89 { |
3523
|
90 std::string retval; |
3203
|
91 |
|
92 switch (op) |
|
93 { |
3533
|
94 case op_not: |
3203
|
95 retval = "!"; |
|
96 break; |
|
97 |
4965
|
98 case op_uplus: |
|
99 retval = "+"; |
|
100 break; |
|
101 |
3533
|
102 case op_uminus: |
3203
|
103 retval = "-"; |
|
104 break; |
|
105 |
3533
|
106 case op_transpose: |
3203
|
107 retval = ".'"; |
|
108 break; |
|
109 |
3533
|
110 case op_hermitian: |
3203
|
111 retval = "'"; |
|
112 break; |
|
113 |
3533
|
114 case op_incr: |
3203
|
115 retval = "++"; |
|
116 break; |
|
117 |
3533
|
118 case op_decr: |
3203
|
119 retval = "--"; |
|
120 break; |
|
121 |
|
122 default: |
|
123 retval = "<unknown>"; |
|
124 } |
|
125 |
|
126 return retval; |
|
127 } |
|
128 |
3536
|
129 std::string |
2376
|
130 octave_value::binary_op_as_string (binary_op op) |
|
131 { |
3523
|
132 std::string retval; |
2376
|
133 |
|
134 switch (op) |
|
135 { |
3533
|
136 case op_add: |
2376
|
137 retval = "+"; |
|
138 break; |
|
139 |
3533
|
140 case op_sub: |
2376
|
141 retval = "-"; |
|
142 break; |
|
143 |
3533
|
144 case op_mul: |
2376
|
145 retval = "*"; |
|
146 break; |
|
147 |
3533
|
148 case op_div: |
2376
|
149 retval = "/"; |
|
150 break; |
|
151 |
3533
|
152 case op_pow: |
2376
|
153 retval = "^"; |
|
154 break; |
|
155 |
3533
|
156 case op_ldiv: |
2376
|
157 retval = "\\"; |
|
158 break; |
|
159 |
3533
|
160 case op_lshift: |
2903
|
161 retval = "<<"; |
|
162 break; |
|
163 |
3533
|
164 case op_rshift: |
2903
|
165 retval = ">>"; |
|
166 break; |
|
167 |
3533
|
168 case op_lt: |
2376
|
169 retval = "<"; |
|
170 break; |
|
171 |
3533
|
172 case op_le: |
2376
|
173 retval = "<="; |
|
174 break; |
|
175 |
3533
|
176 case op_eq: |
2376
|
177 retval = "=="; |
|
178 break; |
|
179 |
3533
|
180 case op_ge: |
2376
|
181 retval = ">="; |
|
182 break; |
|
183 |
3533
|
184 case op_gt: |
2376
|
185 retval = ">"; |
|
186 break; |
|
187 |
3533
|
188 case op_ne: |
2376
|
189 retval = "!="; |
|
190 break; |
|
191 |
3533
|
192 case op_el_mul: |
2376
|
193 retval = ".*"; |
|
194 break; |
|
195 |
3533
|
196 case op_el_div: |
2376
|
197 retval = "./"; |
|
198 break; |
|
199 |
3533
|
200 case op_el_pow: |
2376
|
201 retval = ".^"; |
|
202 break; |
|
203 |
3533
|
204 case op_el_ldiv: |
2376
|
205 retval = ".\\"; |
|
206 break; |
|
207 |
3533
|
208 case op_el_and: |
2376
|
209 retval = "&"; |
|
210 break; |
|
211 |
3533
|
212 case op_el_or: |
2376
|
213 retval = "|"; |
|
214 break; |
|
215 |
3533
|
216 case op_struct_ref: |
2376
|
217 retval = "."; |
|
218 break; |
|
219 |
|
220 default: |
|
221 retval = "<unknown>"; |
|
222 } |
|
223 |
|
224 return retval; |
|
225 } |
|
226 |
3536
|
227 std::string |
2880
|
228 octave_value::assign_op_as_string (assign_op op) |
|
229 { |
3523
|
230 std::string retval; |
2880
|
231 |
|
232 switch (op) |
|
233 { |
3533
|
234 case op_asn_eq: |
2880
|
235 retval = "="; |
|
236 break; |
|
237 |
3533
|
238 case op_add_eq: |
2880
|
239 retval = "+="; |
|
240 break; |
|
241 |
3533
|
242 case op_sub_eq: |
2880
|
243 retval = "-="; |
|
244 break; |
|
245 |
3533
|
246 case op_mul_eq: |
2880
|
247 retval = "*="; |
|
248 break; |
|
249 |
3533
|
250 case op_div_eq: |
2880
|
251 retval = "/="; |
|
252 break; |
|
253 |
3533
|
254 case op_ldiv_eq: |
3204
|
255 retval = "\\="; |
|
256 break; |
|
257 |
4018
|
258 case op_pow_eq: |
|
259 retval = "^="; |
|
260 break; |
|
261 |
3533
|
262 case op_lshift_eq: |
2903
|
263 retval = "<<="; |
|
264 break; |
|
265 |
3533
|
266 case op_rshift_eq: |
2903
|
267 retval = ">>="; |
|
268 break; |
|
269 |
3533
|
270 case op_el_mul_eq: |
2880
|
271 retval = ".*="; |
|
272 break; |
|
273 |
3533
|
274 case op_el_div_eq: |
2880
|
275 retval = "./="; |
|
276 break; |
|
277 |
3533
|
278 case op_el_ldiv_eq: |
3204
|
279 retval = ".\\="; |
|
280 break; |
|
281 |
4018
|
282 case op_el_pow_eq: |
|
283 retval = ".^="; |
|
284 break; |
|
285 |
3533
|
286 case op_el_and_eq: |
2880
|
287 retval = "&="; |
|
288 break; |
|
289 |
3533
|
290 case op_el_or_eq: |
2880
|
291 retval = "|="; |
|
292 break; |
|
293 |
|
294 default: |
|
295 retval = "<unknown>"; |
|
296 } |
|
297 |
|
298 return retval; |
|
299 } |
|
300 |
5759
|
301 octave_value::octave_value (void) |
|
302 : rep (new octave_base_value ()) |
4513
|
303 { |
2825
|
304 } |
2376
|
305 |
4254
|
306 octave_value::octave_value (short int i) |
|
307 : rep (new octave_scalar (i)) |
|
308 { |
|
309 } |
|
310 |
|
311 octave_value::octave_value (unsigned short int i) |
|
312 : rep (new octave_scalar (i)) |
|
313 { |
|
314 } |
|
315 |
4233
|
316 octave_value::octave_value (int i) |
|
317 : rep (new octave_scalar (i)) |
|
318 { |
|
319 } |
|
320 |
4254
|
321 octave_value::octave_value (unsigned int i) |
|
322 : rep (new octave_scalar (i)) |
|
323 { |
|
324 } |
|
325 |
|
326 octave_value::octave_value (long int i) |
|
327 : rep (new octave_scalar (i)) |
|
328 { |
|
329 } |
|
330 |
|
331 octave_value::octave_value (unsigned long int i) |
|
332 : rep (new octave_scalar (i)) |
|
333 { |
|
334 } |
|
335 |
4353
|
336 #if defined (HAVE_LONG_LONG_INT) |
|
337 octave_value::octave_value (long long int i) |
|
338 : rep (new octave_scalar (i)) |
|
339 { |
|
340 } |
|
341 #endif |
|
342 |
4355
|
343 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353
|
344 octave_value::octave_value (unsigned long long int i) |
|
345 : rep (new octave_scalar (i)) |
|
346 { |
|
347 } |
|
348 #endif |
|
349 |
4254
|
350 octave_value::octave_value (octave_time t) |
|
351 : rep (new octave_scalar (t)) |
|
352 { |
|
353 } |
|
354 |
2376
|
355 octave_value::octave_value (double d) |
2825
|
356 : rep (new octave_scalar (d)) |
|
357 { |
|
358 } |
2376
|
359 |
4587
|
360 octave_value::octave_value (const Cell& c, bool is_csl) |
5477
|
361 : rep (is_csl |
5759
|
362 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c)) |
|
363 : dynamic_cast<octave_base_value *> (new octave_cell (c))) |
3351
|
364 { |
|
365 } |
|
366 |
5147
|
367 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
5477
|
368 : rep (is_csl |
5759
|
369 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a))) |
|
370 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a)))) |
5147
|
371 { |
|
372 } |
|
373 |
5785
|
374 octave_value::octave_value (const Matrix& m, const MatrixType& t) |
|
375 : rep (new octave_matrix (m, t)) |
2423
|
376 { |
|
377 maybe_mutate (); |
|
378 } |
2376
|
379 |
4507
|
380 octave_value::octave_value (const NDArray& a) |
4513
|
381 : rep (new octave_matrix (a)) |
4478
|
382 { |
|
383 maybe_mutate (); |
|
384 } |
|
385 |
4911
|
386 octave_value::octave_value (const ArrayN<double>& a) |
|
387 : rep (new octave_matrix (a)) |
|
388 { |
|
389 maybe_mutate (); |
|
390 } |
|
391 |
2376
|
392 octave_value::octave_value (const DiagMatrix& d) |
2423
|
393 : rep (new octave_matrix (d)) |
|
394 { |
|
395 maybe_mutate (); |
|
396 } |
2376
|
397 |
3418
|
398 octave_value::octave_value (const RowVector& v) |
|
399 : rep (new octave_matrix (v)) |
2423
|
400 { |
|
401 maybe_mutate (); |
|
402 } |
2376
|
403 |
3418
|
404 octave_value::octave_value (const ColumnVector& v) |
|
405 : rep (new octave_matrix (v)) |
2423
|
406 { |
|
407 maybe_mutate (); |
|
408 } |
2376
|
409 |
|
410 octave_value::octave_value (const Complex& C) |
2423
|
411 : rep (new octave_complex (C)) |
|
412 { |
|
413 maybe_mutate (); |
|
414 } |
2376
|
415 |
5785
|
416 octave_value::octave_value (const ComplexMatrix& m, const MatrixType& t) |
|
417 : rep (new octave_complex_matrix (m, t)) |
2423
|
418 { |
|
419 maybe_mutate (); |
|
420 } |
2376
|
421 |
4513
|
422 octave_value::octave_value (const ComplexNDArray& a) |
|
423 : rep (new octave_complex_matrix (a)) |
4478
|
424 { |
|
425 maybe_mutate (); |
|
426 } |
|
427 |
4911
|
428 octave_value::octave_value (const ArrayN<Complex>& a) |
|
429 : rep (new octave_complex_matrix (a)) |
|
430 { |
|
431 maybe_mutate (); |
|
432 } |
|
433 |
2376
|
434 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423
|
435 : rep (new octave_complex_matrix (d)) |
|
436 { |
|
437 maybe_mutate (); |
|
438 } |
2376
|
439 |
3418
|
440 octave_value::octave_value (const ComplexRowVector& v) |
|
441 : rep (new octave_complex_matrix (v)) |
2423
|
442 { |
|
443 maybe_mutate (); |
|
444 } |
2376
|
445 |
3418
|
446 octave_value::octave_value (const ComplexColumnVector& v) |
|
447 : rep (new octave_complex_matrix (v)) |
2423
|
448 { |
|
449 maybe_mutate (); |
|
450 } |
2376
|
451 |
2825
|
452 octave_value::octave_value (bool b) |
|
453 : rep (new octave_bool (b)) |
|
454 { |
|
455 } |
|
456 |
5785
|
457 octave_value::octave_value (const boolMatrix& bm, const MatrixType& t) |
|
458 : rep (new octave_bool_matrix (bm, t)) |
2825
|
459 { |
|
460 maybe_mutate (); |
|
461 } |
|
462 |
4513
|
463 octave_value::octave_value (const boolNDArray& bnda) |
|
464 : rep (new octave_bool_matrix (bnda)) |
|
465 { |
|
466 maybe_mutate (); |
|
467 } |
|
468 |
5279
|
469 octave_value::octave_value (char c, char type) |
|
470 : rep (type == '"' |
|
471 ? new octave_char_matrix_dq_str (c) |
|
472 : new octave_char_matrix_sq_str (c)) |
3189
|
473 { |
|
474 maybe_mutate (); |
|
475 } |
|
476 |
5279
|
477 octave_value::octave_value (const char *s, char type) |
|
478 : rep (type == '"' |
|
479 ? new octave_char_matrix_dq_str (s) |
|
480 : new octave_char_matrix_sq_str (s)) |
2423
|
481 { |
|
482 maybe_mutate (); |
|
483 } |
2376
|
484 |
5279
|
485 octave_value::octave_value (const std::string& s, char type) |
|
486 : rep (type == '"' |
|
487 ? new octave_char_matrix_dq_str (s) |
|
488 : new octave_char_matrix_sq_str (s)) |
2423
|
489 { |
|
490 maybe_mutate (); |
|
491 } |
2376
|
492 |
5279
|
493 octave_value::octave_value (const string_vector& s, char type) |
|
494 : rep (type == '"' |
|
495 ? new octave_char_matrix_dq_str (s) |
|
496 : new octave_char_matrix_sq_str (s)) |
2423
|
497 { |
|
498 maybe_mutate (); |
|
499 } |
2376
|
500 |
5279
|
501 octave_value::octave_value (const charMatrix& chm, bool is_str, char type) |
4587
|
502 : rep (is_str |
5279
|
503 ? (type == '"' |
|
504 ? new octave_char_matrix_dq_str (chm) |
|
505 : new octave_char_matrix_sq_str (chm)) |
4513
|
506 : new octave_char_matrix (chm)) |
2409
|
507 { |
4513
|
508 maybe_mutate (); |
|
509 } |
2376
|
510 |
5279
|
511 octave_value::octave_value (const charNDArray& chm, bool is_str, char type) |
4587
|
512 : rep (is_str |
5279
|
513 ? (type == '"' |
|
514 ? new octave_char_matrix_dq_str (chm) |
|
515 : new octave_char_matrix_sq_str (chm)) |
4513
|
516 : new octave_char_matrix (chm)) |
|
517 { |
2423
|
518 maybe_mutate (); |
2409
|
519 } |
2376
|
520 |
5279
|
521 octave_value::octave_value (const ArrayN<char>& chm, bool is_str, char type) |
4997
|
522 : rep (is_str |
5279
|
523 ? (type == '"' |
|
524 ? new octave_char_matrix_dq_str (chm) |
|
525 : new octave_char_matrix_sq_str (chm)) |
4997
|
526 : new octave_char_matrix (chm)) |
|
527 { |
|
528 maybe_mutate (); |
|
529 } |
|
530 |
5785
|
531 octave_value::octave_value (const SparseMatrix& m, const MatrixType &t) |
5164
|
532 : rep (new octave_sparse_matrix (m, t)) |
|
533 { |
|
534 maybe_mutate (); |
|
535 } |
|
536 |
6863
|
537 octave_value::octave_value (const Sparse<double>& m, const MatrixType &t) |
|
538 : rep (new octave_sparse_matrix (m, t)) |
|
539 { |
|
540 maybe_mutate (); |
|
541 } |
|
542 |
5785
|
543 octave_value::octave_value (const SparseComplexMatrix& m, const MatrixType &t) |
5164
|
544 : rep (new octave_sparse_complex_matrix (m, t)) |
|
545 { |
|
546 maybe_mutate (); |
|
547 } |
|
548 |
6863
|
549 octave_value::octave_value (const Sparse<Complex>& m, const MatrixType &t) |
|
550 : rep (new octave_sparse_complex_matrix (m, t)) |
|
551 { |
|
552 maybe_mutate (); |
|
553 } |
|
554 |
5785
|
555 octave_value::octave_value (const SparseBoolMatrix& bm, const MatrixType &t) |
5164
|
556 : rep (new octave_sparse_bool_matrix (bm, t)) |
|
557 { |
|
558 maybe_mutate (); |
|
559 } |
|
560 |
4901
|
561 octave_value::octave_value (const octave_int8& i) |
|
562 : rep (new octave_int8_scalar (i)) |
|
563 { |
|
564 maybe_mutate (); |
|
565 } |
|
566 |
|
567 octave_value::octave_value (const octave_uint8& i) |
|
568 : rep (new octave_uint8_scalar (i)) |
|
569 { |
|
570 maybe_mutate (); |
|
571 } |
|
572 |
|
573 octave_value::octave_value (const octave_int16& i) |
|
574 : rep (new octave_int16_scalar (i)) |
|
575 { |
|
576 maybe_mutate (); |
|
577 } |
|
578 |
|
579 octave_value::octave_value (const octave_uint16& i) |
|
580 : rep (new octave_uint16_scalar (i)) |
|
581 { |
|
582 maybe_mutate (); |
|
583 } |
|
584 |
|
585 octave_value::octave_value (const octave_int32& i) |
|
586 : rep (new octave_int32_scalar (i)) |
|
587 { |
|
588 maybe_mutate (); |
|
589 } |
|
590 |
|
591 octave_value::octave_value (const octave_uint32& i) |
|
592 : rep (new octave_uint32_scalar (i)) |
|
593 { |
|
594 maybe_mutate (); |
|
595 } |
|
596 |
|
597 octave_value::octave_value (const octave_int64& i) |
|
598 : rep (new octave_int64_scalar (i)) |
|
599 { |
|
600 maybe_mutate (); |
|
601 } |
|
602 |
|
603 octave_value::octave_value (const octave_uint64& i) |
|
604 : rep (new octave_uint64_scalar (i)) |
|
605 { |
|
606 maybe_mutate (); |
|
607 } |
|
608 |
|
609 octave_value::octave_value (const int8NDArray& inda) |
|
610 : rep (new octave_int8_matrix (inda)) |
|
611 { |
|
612 maybe_mutate (); |
|
613 } |
|
614 |
|
615 octave_value::octave_value (const uint8NDArray& inda) |
|
616 : rep (new octave_uint8_matrix (inda)) |
|
617 { |
|
618 maybe_mutate (); |
|
619 } |
|
620 |
|
621 octave_value::octave_value (const int16NDArray& inda) |
|
622 : rep (new octave_int16_matrix (inda)) |
|
623 { |
|
624 maybe_mutate (); |
|
625 } |
|
626 |
|
627 octave_value::octave_value (const uint16NDArray& inda) |
|
628 : rep (new octave_uint16_matrix (inda)) |
|
629 { |
|
630 maybe_mutate (); |
|
631 } |
|
632 |
|
633 octave_value::octave_value (const int32NDArray& inda) |
|
634 : rep (new octave_int32_matrix (inda)) |
|
635 { |
|
636 maybe_mutate (); |
|
637 } |
|
638 |
|
639 octave_value::octave_value (const uint32NDArray& inda) |
|
640 : rep (new octave_uint32_matrix (inda)) |
|
641 { |
|
642 maybe_mutate (); |
|
643 } |
|
644 |
|
645 octave_value::octave_value (const int64NDArray& inda) |
|
646 : rep (new octave_int64_matrix (inda)) |
|
647 { |
|
648 maybe_mutate (); |
|
649 } |
|
650 |
|
651 octave_value::octave_value (const uint64NDArray& inda) |
|
652 : rep (new octave_uint64_matrix (inda)) |
|
653 { |
|
654 maybe_mutate (); |
|
655 } |
|
656 |
2376
|
657 octave_value::octave_value (double base, double limit, double inc) |
2423
|
658 : rep (new octave_range (base, limit, inc)) |
|
659 { |
|
660 maybe_mutate (); |
|
661 } |
2376
|
662 |
|
663 octave_value::octave_value (const Range& r) |
2423
|
664 : rep (new octave_range (r)) |
|
665 { |
|
666 maybe_mutate (); |
|
667 } |
2376
|
668 |
|
669 octave_value::octave_value (const Octave_map& m) |
2825
|
670 : rep (new octave_struct (m)) |
|
671 { |
2880
|
672 } |
|
673 |
4643
|
674 octave_value::octave_value (const streamoff_array& off) |
|
675 : rep (new octave_streamoff (off)) |
|
676 { |
|
677 } |
|
678 |
4587
|
679 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
5477
|
680 : rep (is_csl |
5759
|
681 ? dynamic_cast<octave_base_value *> (new octave_cs_list (l)) |
|
682 : dynamic_cast<octave_base_value *> (new octave_list (l))) |
2880
|
683 { |
|
684 } |
2376
|
685 |
|
686 octave_value::octave_value (octave_value::magic_colon) |
2825
|
687 : rep (new octave_magic_colon ()) |
|
688 { |
|
689 } |
2376
|
690 |
5759
|
691 octave_value::octave_value (octave_base_value *new_rep) |
2825
|
692 : rep (new_rep) |
|
693 { |
|
694 } |
2376
|
695 |
5759
|
696 octave_base_value * |
3933
|
697 octave_value::clone (void) const |
2880
|
698 { |
|
699 panic_impossible (); |
3546
|
700 return 0; |
2880
|
701 } |
|
702 |
2409
|
703 void |
|
704 octave_value::maybe_mutate (void) |
|
705 { |
5759
|
706 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409
|
707 |
|
708 if (tmp && tmp != rep) |
|
709 { |
|
710 if (--rep->count == 0) |
|
711 delete rep; |
|
712 |
|
713 rep = tmp; |
|
714 } |
|
715 } |
|
716 |
4247
|
717 octave_value |
4271
|
718 octave_value::single_subsref (const std::string& type, |
|
719 const octave_value_list& idx) |
4247
|
720 { |
|
721 std::list<octave_value_list> i; |
|
722 |
|
723 i.push_back (idx); |
|
724 |
|
725 return rep->subsref (type, i); |
|
726 } |
|
727 |
2974
|
728 octave_value_list |
4247
|
729 octave_value::subsref (const std::string& type, |
4219
|
730 const std::list<octave_value_list>& idx, int nargout) |
3933
|
731 { |
|
732 if (is_constant ()) |
|
733 return rep->subsref (type, idx); |
|
734 else |
|
735 return rep->subsref (type, idx, nargout); |
|
736 } |
|
737 |
|
738 octave_value |
4247
|
739 octave_value::next_subsref (const std::string& type, |
4219
|
740 const std::list<octave_value_list>& idx, |
4233
|
741 size_t skip) |
3933
|
742 { |
4582
|
743 if (! error_state && idx.size () > skip) |
3933
|
744 { |
4219
|
745 std::list<octave_value_list> new_idx (idx); |
4233
|
746 for (size_t i = 0; i < skip; i++) |
4219
|
747 new_idx.erase (new_idx.begin ()); |
3933
|
748 return subsref (type.substr (skip), new_idx); |
|
749 } |
|
750 else |
|
751 return *this; |
|
752 } |
|
753 |
|
754 octave_value_list |
4994
|
755 octave_value::next_subsref (int nargout, const std::string& type, |
|
756 const std::list<octave_value_list>& idx, |
|
757 size_t skip) |
|
758 { |
|
759 if (! error_state && idx.size () > skip) |
|
760 { |
|
761 std::list<octave_value_list> new_idx (idx); |
|
762 for (size_t i = 0; i < skip; i++) |
|
763 new_idx.erase (new_idx.begin ()); |
|
764 return subsref (type.substr (skip), new_idx, nargout); |
|
765 } |
|
766 else |
|
767 return *this; |
|
768 } |
|
769 |
|
770 octave_value_list |
3544
|
771 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974
|
772 { |
3544
|
773 return rep->do_multi_index_op (nargout, idx); |
2974
|
774 } |
|
775 |
3933
|
776 #if 0 |
3204
|
777 static void |
3933
|
778 gripe_assign_failed (const std::string& on, const std::string& tn1, |
|
779 const std::string& tn2) |
3204
|
780 { |
|
781 error ("assignment failed for `%s %s %s'", |
|
782 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
783 } |
3933
|
784 #endif |
3204
|
785 |
|
786 static void |
3933
|
787 gripe_assign_failed_or_no_method (const std::string& on, |
|
788 const std::string& tn1, |
3523
|
789 const std::string& tn2) |
3204
|
790 { |
|
791 error ("assignment failed, or no method for `%s %s %s'", |
|
792 tn1.c_str (), on.c_str (), tn2.c_str ()); |
|
793 } |
|
794 |
3933
|
795 octave_value |
4247
|
796 octave_value::subsasgn (const std::string& type, |
4219
|
797 const std::list<octave_value_list>& idx, |
3933
|
798 const octave_value& rhs) |
|
799 { |
|
800 return rep->subsasgn (type, idx, rhs); |
|
801 } |
|
802 |
|
803 octave_value |
4247
|
804 octave_value::assign (assign_op op, const std::string& type, |
4219
|
805 const std::list<octave_value_list>& idx, |
3933
|
806 const octave_value& rhs) |
|
807 { |
|
808 octave_value retval; |
|
809 |
|
810 make_unique (); |
|
811 |
|
812 octave_value t_rhs = rhs; |
|
813 |
|
814 if (op != op_asn_eq) |
|
815 { |
5775
|
816 // FIXME -- only do the following stuff if we can't find |
3933
|
817 // a specific function to call to handle the op= operation for |
|
818 // the types we have. |
|
819 |
5001
|
820 octave_value t; |
|
821 if (is_constant ()) |
|
822 t = subsref (type, idx); |
|
823 else |
|
824 { |
|
825 octave_value_list tl = subsref (type, idx, 1); |
|
826 if (tl.length () > 0) |
|
827 t = tl(0); |
|
828 } |
3933
|
829 |
|
830 if (! error_state) |
|
831 { |
|
832 binary_op binop = op_eq_to_binary_op (op); |
|
833 |
|
834 if (! error_state) |
|
835 t_rhs = do_binary_op (binop, t, rhs); |
|
836 } |
|
837 } |
|
838 |
|
839 if (! error_state) |
|
840 { |
|
841 if (type[0] == '.' && ! is_map ()) |
|
842 { |
|
843 octave_value tmp = Octave_map (); |
|
844 retval = tmp.subsasgn (type, idx, t_rhs); |
|
845 } |
|
846 else |
|
847 retval = subsasgn (type, idx, t_rhs); |
|
848 } |
|
849 |
|
850 if (error_state) |
|
851 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
852 type_name (), rhs.type_name ()); |
|
853 |
|
854 return retval; |
|
855 } |
|
856 |
|
857 const octave_value& |
3203
|
858 octave_value::assign (assign_op op, const octave_value& rhs) |
2880
|
859 { |
3533
|
860 if (op == op_asn_eq) |
3203
|
861 operator = (rhs); |
|
862 else |
|
863 { |
5775
|
864 // FIXME -- only do the following stuff if we can't find |
3204
|
865 // a specific function to call to handle the op= operation for |
|
866 // the types we have. |
|
867 |
|
868 binary_op binop = op_eq_to_binary_op (op); |
|
869 |
|
870 if (! error_state) |
|
871 { |
|
872 octave_value t = do_binary_op (binop, *this, rhs); |
|
873 |
|
874 if (! error_state) |
|
875 operator = (t); |
|
876 } |
|
877 |
|
878 if (error_state) |
|
879 gripe_assign_failed_or_no_method (assign_op_as_string (op), |
|
880 type_name (), rhs.type_name ()); |
|
881 } |
|
882 |
3933
|
883 return *this; |
2376
|
884 } |
|
885 |
5275
|
886 octave_idx_type |
4563
|
887 octave_value::length (void) const |
|
888 { |
|
889 int retval = 0; |
|
890 |
|
891 dim_vector dv = dims (); |
4584
|
892 |
4563
|
893 for (int i = 0; i < dv.length (); i++) |
|
894 { |
|
895 if (dv(i) < 0) |
|
896 { |
|
897 retval = -1; |
|
898 break; |
|
899 } |
|
900 |
4584
|
901 if (dv(i) == 0) |
|
902 { |
|
903 retval = 0; |
|
904 break; |
|
905 } |
|
906 |
4563
|
907 if (dv(i) > retval) |
|
908 retval = dv(i); |
|
909 } |
|
910 |
|
911 return retval; |
|
912 } |
|
913 |
5659
|
914 Matrix |
|
915 octave_value::size (void) const |
|
916 { |
|
917 dim_vector dv = dims (); |
|
918 |
|
919 int n_dims = dv.length (); |
|
920 |
|
921 Matrix retval (1, n_dims); |
|
922 |
|
923 while (n_dims--) |
|
924 retval(n_dims) = dv(n_dims); |
|
925 |
|
926 return retval; |
|
927 } |
|
928 |
3351
|
929 Cell |
|
930 octave_value::cell_value (void) const |
|
931 { |
|
932 return rep->cell_value (); |
|
933 } |
|
934 |
2376
|
935 Octave_map |
|
936 octave_value::map_value (void) const |
|
937 { |
|
938 return rep->map_value (); |
|
939 } |
|
940 |
4645
|
941 std::streamoff |
4643
|
942 octave_value::streamoff_value (void) const |
|
943 { |
|
944 return rep->streamoff_value (); |
|
945 } |
|
946 |
4645
|
947 streamoff_array |
|
948 octave_value::streamoff_array_value (void) const |
|
949 { |
|
950 return rep->streamoff_array_value (); |
|
951 } |
|
952 |
2974
|
953 octave_function * |
|
954 octave_value::function_value (bool silent) |
|
955 { |
|
956 return rep->function_value (silent); |
|
957 } |
|
958 |
4700
|
959 octave_user_function * |
|
960 octave_value::user_function_value (bool silent) |
|
961 { |
|
962 return rep->user_function_value (silent); |
|
963 } |
|
964 |
4346
|
965 octave_fcn_handle * |
4343
|
966 octave_value::fcn_handle_value (bool silent) |
|
967 { |
|
968 return rep->fcn_handle_value (silent); |
|
969 } |
|
970 |
4933
|
971 octave_fcn_inline * |
|
972 octave_value::fcn_inline_value (bool silent) |
|
973 { |
|
974 return rep->fcn_inline_value (silent); |
|
975 } |
|
976 |
2880
|
977 octave_value_list |
|
978 octave_value::list_value (void) const |
|
979 { |
|
980 return rep->list_value (); |
|
981 } |
|
982 |
2376
|
983 ColumnVector |
3419
|
984 octave_value::column_vector_value (bool force_string_conv, |
4661
|
985 bool /* frc_vec_conv */) const |
3419
|
986 { |
|
987 ColumnVector retval; |
|
988 |
|
989 Matrix m = matrix_value (force_string_conv); |
|
990 |
|
991 if (error_state) |
|
992 return retval; |
|
993 |
5275
|
994 octave_idx_type nr = m.rows (); |
|
995 octave_idx_type nc = m.columns (); |
3419
|
996 |
|
997 if (nc == 1) |
|
998 { |
|
999 retval.resize (nr); |
5275
|
1000 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1001 retval (i) = m (i, 0); |
|
1002 } |
|
1003 else |
|
1004 { |
3523
|
1005 std::string tn = type_name (); |
3419
|
1006 gripe_invalid_conversion (tn.c_str (), "real column vector"); |
|
1007 } |
|
1008 |
|
1009 return retval; |
|
1010 } |
|
1011 |
|
1012 ComplexColumnVector |
|
1013 octave_value::complex_column_vector_value (bool force_string_conv, |
4661
|
1014 bool /* frc_vec_conv */) const |
3419
|
1015 { |
|
1016 ComplexColumnVector retval; |
|
1017 |
|
1018 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1019 |
|
1020 if (error_state) |
|
1021 return retval; |
|
1022 |
5275
|
1023 octave_idx_type nr = m.rows (); |
|
1024 octave_idx_type nc = m.columns (); |
3419
|
1025 |
|
1026 if (nc == 1) |
|
1027 { |
3465
|
1028 retval.resize (nr); |
5275
|
1029 for (octave_idx_type i = 0; i < nr; i++) |
3419
|
1030 retval (i) = m (i, 0); |
|
1031 } |
|
1032 else |
|
1033 { |
3523
|
1034 std::string tn = type_name (); |
3419
|
1035 gripe_invalid_conversion (tn.c_str (), "complex column vector"); |
|
1036 } |
|
1037 |
|
1038 return retval; |
|
1039 } |
|
1040 |
|
1041 RowVector |
|
1042 octave_value::row_vector_value (bool force_string_conv, |
4661
|
1043 bool /* frc_vec_conv */) const |
3419
|
1044 { |
|
1045 RowVector retval; |
|
1046 |
|
1047 Matrix m = matrix_value (force_string_conv); |
|
1048 |
|
1049 if (error_state) |
|
1050 return retval; |
|
1051 |
5275
|
1052 octave_idx_type nr = m.rows (); |
|
1053 octave_idx_type nc = m.columns (); |
3419
|
1054 |
|
1055 if (nr == 1) |
|
1056 { |
|
1057 retval.resize (nc); |
5275
|
1058 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1059 retval (i) = m (0, i); |
|
1060 } |
|
1061 else |
|
1062 { |
3523
|
1063 std::string tn = type_name (); |
3419
|
1064 gripe_invalid_conversion (tn.c_str (), "real row vector"); |
|
1065 } |
|
1066 |
|
1067 return retval; |
|
1068 } |
|
1069 |
|
1070 ComplexRowVector |
|
1071 octave_value::complex_row_vector_value (bool force_string_conv, |
4661
|
1072 bool /* frc_vec_conv */) const |
3419
|
1073 { |
|
1074 ComplexRowVector retval; |
|
1075 |
|
1076 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1077 |
|
1078 if (error_state) |
|
1079 return retval; |
|
1080 |
5275
|
1081 octave_idx_type nr = m.rows (); |
|
1082 octave_idx_type nc = m.columns (); |
3419
|
1083 |
|
1084 if (nr == 1) |
|
1085 { |
|
1086 retval.resize (nc); |
5275
|
1087 for (octave_idx_type i = 0; i < nc; i++) |
3419
|
1088 retval (i) = m (0, i); |
|
1089 } |
|
1090 else |
|
1091 { |
3523
|
1092 std::string tn = type_name (); |
3419
|
1093 gripe_invalid_conversion (tn.c_str (), "complex row vector"); |
|
1094 } |
|
1095 |
|
1096 return retval; |
|
1097 } |
|
1098 |
|
1099 // Sloppy... |
|
1100 |
|
1101 Array<double> |
2376
|
1102 octave_value::vector_value (bool force_string_conv, |
|
1103 bool force_vector_conversion) const |
|
1104 { |
3419
|
1105 Array<double> retval; |
2376
|
1106 |
|
1107 Matrix m = matrix_value (force_string_conv); |
|
1108 |
|
1109 if (error_state) |
|
1110 return retval; |
|
1111 |
5275
|
1112 octave_idx_type nr = m.rows (); |
|
1113 octave_idx_type nc = m.columns (); |
2376
|
1114 |
|
1115 if (nr == 1) |
|
1116 { |
|
1117 retval.resize (nc); |
5275
|
1118 for (octave_idx_type i = 0; i < nc; i++) |
2376
|
1119 retval (i) = m (0, i); |
|
1120 } |
|
1121 else if (nc == 1) |
|
1122 { |
|
1123 retval.resize (nr); |
5275
|
1124 for (octave_idx_type i = 0; i < nr; i++) |
2376
|
1125 retval (i) = m (i, 0); |
|
1126 } |
4455
|
1127 else if (nr > 0 && nc > 0) |
2376
|
1128 { |
5781
|
1129 if (! force_vector_conversion) |
|
1130 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1131 type_name (), "real vector"); |
4455
|
1132 |
2376
|
1133 retval.resize (nr * nc); |
5275
|
1134 octave_idx_type k = 0; |
|
1135 for (octave_idx_type j = 0; j < nc; j++) |
|
1136 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1137 { |
|
1138 OCTAVE_QUIT; |
|
1139 |
|
1140 retval (k++) = m (i, j); |
|
1141 } |
2376
|
1142 } |
|
1143 else |
|
1144 { |
3523
|
1145 std::string tn = type_name (); |
2376
|
1146 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1147 } |
|
1148 |
|
1149 return retval; |
|
1150 } |
|
1151 |
4044
|
1152 Array<int> |
|
1153 octave_value::int_vector_value (bool force_string_conv, bool require_int, |
|
1154 bool force_vector_conversion) const |
|
1155 { |
|
1156 Array<int> retval; |
|
1157 |
|
1158 Matrix m = matrix_value (force_string_conv); |
|
1159 |
|
1160 if (error_state) |
|
1161 return retval; |
|
1162 |
5275
|
1163 octave_idx_type nr = m.rows (); |
|
1164 octave_idx_type nc = m.columns (); |
4044
|
1165 |
|
1166 if (nr == 1) |
|
1167 { |
|
1168 retval.resize (nc); |
5275
|
1169 for (octave_idx_type i = 0; i < nc; i++) |
4044
|
1170 { |
4153
|
1171 OCTAVE_QUIT; |
|
1172 |
4044
|
1173 double d = m (0, i); |
|
1174 |
|
1175 if (require_int && D_NINT (d) != d) |
|
1176 { |
|
1177 error ("conversion to integer value failed"); |
|
1178 return retval; |
|
1179 } |
|
1180 |
|
1181 retval (i) = static_cast<int> (d); |
|
1182 } |
|
1183 } |
|
1184 else if (nc == 1) |
|
1185 { |
|
1186 retval.resize (nr); |
5275
|
1187 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1188 { |
4153
|
1189 OCTAVE_QUIT; |
|
1190 |
4044
|
1191 double d = m (i, 0); |
|
1192 |
|
1193 if (require_int && D_NINT (d) != d) |
|
1194 { |
|
1195 error ("conversion to integer value failed"); |
|
1196 return retval; |
|
1197 } |
|
1198 |
|
1199 retval (i) = static_cast<int> (d); |
|
1200 } |
|
1201 } |
4455
|
1202 else if (nr > 0 && nc > 0) |
4044
|
1203 { |
5781
|
1204 if (! force_vector_conversion) |
|
1205 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1206 type_name (), "real vector"); |
4455
|
1207 |
4044
|
1208 retval.resize (nr * nc); |
5275
|
1209 octave_idx_type k = 0; |
|
1210 for (octave_idx_type j = 0; j < nc; j++) |
4044
|
1211 { |
5275
|
1212 for (octave_idx_type i = 0; i < nr; i++) |
4044
|
1213 { |
4153
|
1214 OCTAVE_QUIT; |
|
1215 |
4044
|
1216 double d = m (i, j); |
|
1217 |
|
1218 if (require_int && D_NINT (d) != d) |
|
1219 { |
|
1220 error ("conversion to integer value failed"); |
|
1221 return retval; |
|
1222 } |
|
1223 |
|
1224 retval (k++) = static_cast<int> (d); |
|
1225 } |
|
1226 } |
|
1227 } |
|
1228 else |
|
1229 { |
|
1230 std::string tn = type_name (); |
|
1231 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
1232 } |
|
1233 |
|
1234 return retval; |
|
1235 } |
|
1236 |
3419
|
1237 Array<Complex> |
2376
|
1238 octave_value::complex_vector_value (bool force_string_conv, |
|
1239 bool force_vector_conversion) const |
|
1240 { |
3419
|
1241 Array<Complex> retval; |
2376
|
1242 |
|
1243 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
1244 |
|
1245 if (error_state) |
|
1246 return retval; |
|
1247 |
5275
|
1248 octave_idx_type nr = m.rows (); |
|
1249 octave_idx_type nc = m.columns (); |
2376
|
1250 |
|
1251 if (nr == 1) |
|
1252 { |
|
1253 retval.resize (nc); |
5275
|
1254 for (octave_idx_type i = 0; i < nc; i++) |
4153
|
1255 { |
|
1256 OCTAVE_QUIT; |
|
1257 retval (i) = m (0, i); |
|
1258 } |
2376
|
1259 } |
|
1260 else if (nc == 1) |
|
1261 { |
|
1262 retval.resize (nr); |
5275
|
1263 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1264 { |
|
1265 OCTAVE_QUIT; |
|
1266 retval (i) = m (i, 0); |
|
1267 } |
2376
|
1268 } |
4455
|
1269 else if (nr > 0 && nc > 0) |
2376
|
1270 { |
5781
|
1271 if (! force_vector_conversion) |
|
1272 gripe_implicit_conversion ("Octave:array-as-vector", |
|
1273 type_name (), "complex vector"); |
4455
|
1274 |
2376
|
1275 retval.resize (nr * nc); |
5275
|
1276 octave_idx_type k = 0; |
|
1277 for (octave_idx_type j = 0; j < nc; j++) |
|
1278 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
1279 { |
|
1280 OCTAVE_QUIT; |
|
1281 retval (k++) = m (i, j); |
|
1282 } |
2376
|
1283 } |
|
1284 else |
|
1285 { |
3523
|
1286 std::string tn = type_name (); |
2376
|
1287 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
1288 } |
|
1289 |
|
1290 return retval; |
|
1291 } |
|
1292 |
4944
|
1293 int |
|
1294 octave_value::write (octave_stream& os, int block_size, |
|
1295 oct_data_conv::data_type output_type, int skip, |
|
1296 oct_mach_info::float_format flt_fmt) const |
|
1297 { |
|
1298 return rep->write (os, block_size, output_type, skip, flt_fmt); |
|
1299 } |
|
1300 |
2413
|
1301 static void |
3933
|
1302 gripe_binary_op (const std::string& on, const std::string& tn1, |
|
1303 const std::string& tn2) |
2376
|
1304 { |
2903
|
1305 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376
|
1306 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
1307 } |
|
1308 |
3203
|
1309 static void |
3523
|
1310 gripe_binary_op_conv (const std::string& on) |
3203
|
1311 { |
|
1312 error ("type conversion failed for binary operator `%s'", on.c_str ()); |
|
1313 } |
|
1314 |
2376
|
1315 octave_value |
3933
|
1316 do_binary_op (octave_value::binary_op op, |
|
1317 const octave_value& v1, const octave_value& v2) |
2376
|
1318 { |
|
1319 octave_value retval; |
|
1320 |
|
1321 int t1 = v1.type_id (); |
|
1322 int t2 = v2.type_id (); |
|
1323 |
5759
|
1324 octave_value_typeinfo::binary_op_fcn f |
|
1325 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1326 |
|
1327 if (f) |
|
1328 retval = f (*v1.rep, *v2.rep); |
|
1329 else |
|
1330 { |
|
1331 octave_value tv1; |
5759
|
1332 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
1333 |
|
1334 if (cf1) |
|
1335 { |
5759
|
1336 octave_base_value *tmp = cf1 (*v1.rep); |
3203
|
1337 |
|
1338 if (tmp) |
|
1339 { |
|
1340 tv1 = octave_value (tmp); |
|
1341 t1 = tv1.type_id (); |
|
1342 } |
|
1343 else |
|
1344 { |
|
1345 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1346 return retval; |
|
1347 } |
2376
|
1348 } |
|
1349 else |
|
1350 tv1 = v1; |
|
1351 |
|
1352 octave_value tv2; |
5759
|
1353 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
1354 |
|
1355 if (cf2) |
|
1356 { |
5759
|
1357 octave_base_value *tmp = cf2 (*v2.rep); |
3203
|
1358 |
|
1359 if (tmp) |
|
1360 { |
|
1361 tv2 = octave_value (tmp); |
|
1362 t2 = tv2.type_id (); |
|
1363 } |
|
1364 else |
|
1365 { |
|
1366 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
|
1367 return retval; |
|
1368 } |
2376
|
1369 } |
|
1370 else |
|
1371 tv2 = v2; |
|
1372 |
|
1373 if (cf1 || cf2) |
|
1374 { |
4587
|
1375 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
2376
|
1376 |
|
1377 if (f) |
|
1378 retval = f (*tv1.rep, *tv2.rep); |
|
1379 else |
|
1380 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1381 v1.type_name (), v2.type_name ()); |
|
1382 } |
|
1383 else |
|
1384 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
1385 v1.type_name (), v2.type_name ()); |
|
1386 } |
|
1387 |
|
1388 return retval; |
|
1389 } |
|
1390 |
4915
|
1391 static void |
|
1392 gripe_cat_op (const std::string& tn1, const std::string& tn2) |
|
1393 { |
|
1394 error ("concatenation operator not implemented for `%s' by `%s' operations", |
|
1395 tn1.c_str (), tn2.c_str ()); |
|
1396 } |
|
1397 |
|
1398 static void |
|
1399 gripe_cat_op_conv (void) |
|
1400 { |
|
1401 error ("type conversion failed for concatenation operator"); |
|
1402 } |
|
1403 |
|
1404 octave_value |
|
1405 do_cat_op (const octave_value& v1, const octave_value& v2, |
6867
|
1406 const Array<octave_idx_type>& ra_idx) |
4915
|
1407 { |
|
1408 octave_value retval; |
|
1409 |
5164
|
1410 // Rapid return for concatenation with an empty object. Dimension |
|
1411 // checking handled elsewhere. |
|
1412 if (v1.all_zero_dims ()) |
|
1413 return v2; |
|
1414 if (v2.all_zero_dims ()) |
|
1415 return v1; |
|
1416 |
4915
|
1417 int t1 = v1.type_id (); |
|
1418 int t2 = v2.type_id (); |
|
1419 |
5759
|
1420 octave_value_typeinfo::cat_op_fcn f |
|
1421 = octave_value_typeinfo::lookup_cat_op (t1, t2); |
4915
|
1422 |
|
1423 if (f) |
|
1424 retval = f (*v1.rep, *v2.rep, ra_idx); |
|
1425 else |
|
1426 { |
|
1427 octave_value tv1; |
5759
|
1428 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
4915
|
1429 |
|
1430 if (cf1) |
|
1431 { |
5759
|
1432 octave_base_value *tmp = cf1 (*v1.rep); |
4915
|
1433 |
|
1434 if (tmp) |
|
1435 { |
|
1436 tv1 = octave_value (tmp); |
|
1437 t1 = tv1.type_id (); |
|
1438 } |
|
1439 else |
|
1440 { |
|
1441 gripe_cat_op_conv (); |
|
1442 return retval; |
|
1443 } |
|
1444 } |
|
1445 else |
|
1446 tv1 = v1; |
|
1447 |
|
1448 octave_value tv2; |
5759
|
1449 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
4915
|
1450 |
|
1451 if (cf2) |
|
1452 { |
5759
|
1453 octave_base_value *tmp = cf2 (*v2.rep); |
4915
|
1454 |
|
1455 if (tmp) |
|
1456 { |
|
1457 tv2 = octave_value (tmp); |
|
1458 t2 = tv2.type_id (); |
|
1459 } |
|
1460 else |
|
1461 { |
|
1462 gripe_cat_op_conv (); |
|
1463 return retval; |
|
1464 } |
|
1465 } |
|
1466 else |
|
1467 tv2 = v2; |
|
1468 |
|
1469 if (cf1 || cf2) |
|
1470 { |
|
1471 f = octave_value_typeinfo::lookup_cat_op (t1, t2); |
|
1472 |
|
1473 if (f) |
|
1474 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
|
1475 else |
|
1476 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1477 } |
|
1478 else |
|
1479 gripe_cat_op (v1.type_name (), v2.type_name ()); |
|
1480 } |
|
1481 |
|
1482 return retval; |
|
1483 } |
|
1484 |
3933
|
1485 void |
|
1486 octave_value::print_info (std::ostream& os, const std::string& prefix) const |
|
1487 { |
|
1488 os << prefix << "type_name: " << type_name () << "\n" |
|
1489 << prefix << "count: " << get_count () << "\n" |
|
1490 << prefix << "rep info: "; |
|
1491 |
|
1492 rep->print_info (os, prefix + " "); |
|
1493 } |
|
1494 |
3203
|
1495 static void |
3523
|
1496 gripe_unary_op (const std::string& on, const std::string& tn) |
3203
|
1497 { |
|
1498 error ("unary operator `%s' not implemented for `%s' operands", |
|
1499 on.c_str (), tn.c_str ()); |
|
1500 } |
|
1501 |
|
1502 static void |
3523
|
1503 gripe_unary_op_conv (const std::string& on) |
3203
|
1504 { |
|
1505 error ("type conversion failed for unary operator `%s'", on.c_str ()); |
|
1506 } |
|
1507 |
|
1508 octave_value |
|
1509 do_unary_op (octave_value::unary_op op, const octave_value& v) |
|
1510 { |
|
1511 octave_value retval; |
|
1512 |
|
1513 int t = v.type_id (); |
|
1514 |
5759
|
1515 octave_value_typeinfo::unary_op_fcn f |
|
1516 = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1517 |
|
1518 if (f) |
|
1519 retval = f (*v.rep); |
|
1520 else |
|
1521 { |
|
1522 octave_value tv; |
5759
|
1523 octave_base_value::type_conv_fcn cf = v.numeric_conversion_function (); |
3203
|
1524 |
|
1525 if (cf) |
|
1526 { |
5759
|
1527 octave_base_value *tmp = cf (*v.rep); |
3203
|
1528 |
|
1529 if (tmp) |
|
1530 { |
|
1531 tv = octave_value (tmp); |
|
1532 t = tv.type_id (); |
|
1533 |
4587
|
1534 f = octave_value_typeinfo::lookup_unary_op (op, t); |
3203
|
1535 |
|
1536 if (f) |
|
1537 retval = f (*tv.rep); |
|
1538 else |
|
1539 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1540 v.type_name ()); |
|
1541 } |
|
1542 else |
|
1543 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
|
1544 } |
|
1545 else |
|
1546 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1547 v.type_name ()); |
|
1548 } |
|
1549 |
|
1550 return retval; |
|
1551 } |
|
1552 |
|
1553 static void |
3933
|
1554 gripe_unary_op_conversion_failed (const std::string& op, |
|
1555 const std::string& tn) |
3203
|
1556 { |
|
1557 error ("operator %s: type conversion for `%s' failed", |
|
1558 op.c_str (), tn.c_str ()); |
|
1559 } |
|
1560 |
3933
|
1561 const octave_value& |
|
1562 octave_value::do_non_const_unary_op (unary_op op) |
3203
|
1563 { |
|
1564 octave_value retval; |
|
1565 |
|
1566 int t = type_id (); |
|
1567 |
5759
|
1568 octave_value_typeinfo::non_const_unary_op_fcn f |
3203
|
1569 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1570 |
|
1571 if (f) |
|
1572 { |
|
1573 make_unique (); |
|
1574 |
|
1575 f (*rep); |
|
1576 } |
|
1577 else |
|
1578 { |
5759
|
1579 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203
|
1580 |
|
1581 if (cf) |
|
1582 { |
5759
|
1583 octave_base_value *tmp = cf (*rep); |
3203
|
1584 |
|
1585 if (tmp) |
|
1586 { |
5759
|
1587 octave_base_value *old_rep = rep; |
3203
|
1588 rep = tmp; |
|
1589 |
|
1590 t = type_id (); |
|
1591 |
|
1592 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
|
1593 |
|
1594 if (f) |
|
1595 { |
|
1596 f (*rep); |
|
1597 |
|
1598 if (old_rep && --old_rep->count == 0) |
|
1599 delete old_rep; |
|
1600 } |
|
1601 else |
|
1602 { |
|
1603 if (old_rep) |
|
1604 { |
|
1605 if (--rep->count == 0) |
|
1606 delete rep; |
|
1607 |
|
1608 rep = old_rep; |
|
1609 } |
|
1610 |
|
1611 gripe_unary_op (octave_value::unary_op_as_string (op), |
|
1612 type_name ()); |
|
1613 } |
|
1614 } |
|
1615 else |
|
1616 gripe_unary_op_conversion_failed |
|
1617 (octave_value::unary_op_as_string (op), type_name ()); |
|
1618 } |
|
1619 else |
|
1620 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); |
|
1621 } |
3933
|
1622 |
|
1623 return *this; |
3203
|
1624 } |
|
1625 |
3933
|
1626 #if 0 |
3205
|
1627 static void |
3933
|
1628 gripe_unary_op_failed_or_no_method (const std::string& on, |
|
1629 const std::string& tn) |
3205
|
1630 { |
|
1631 error ("operator %s: no method, or unable to evaluate for %s operand", |
|
1632 on.c_str (), tn.c_str ()); |
|
1633 } |
3933
|
1634 #endif |
3205
|
1635 |
|
1636 void |
4661
|
1637 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205
|
1638 { |
3933
|
1639 abort (); |
|
1640 } |
|
1641 |
|
1642 octave_value |
4247
|
1643 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219
|
1644 const std::list<octave_value_list>& idx) |
3933
|
1645 { |
|
1646 octave_value retval; |
|
1647 |
|
1648 if (idx.empty ()) |
|
1649 { |
|
1650 do_non_const_unary_op (op); |
3205
|
1651 |
3933
|
1652 retval = *this; |
|
1653 } |
|
1654 else |
|
1655 { |
5775
|
1656 // FIXME -- only do the following stuff if we can't find a |
3933
|
1657 // specific function to call to handle the op= operation for the |
|
1658 // types we have. |
3205
|
1659 |
3933
|
1660 assign_op assop = unary_op_to_assign_op (op); |
|
1661 |
|
1662 retval = assign (assop, type, idx, 1.0); |
|
1663 } |
|
1664 |
|
1665 return retval; |
3205
|
1666 } |
|
1667 |
|
1668 octave_value::assign_op |
|
1669 octave_value::unary_op_to_assign_op (unary_op op) |
|
1670 { |
|
1671 assign_op binop = unknown_assign_op; |
|
1672 |
|
1673 switch (op) |
|
1674 { |
3533
|
1675 case op_incr: |
|
1676 binop = op_add_eq; |
3205
|
1677 break; |
|
1678 |
3533
|
1679 case op_decr: |
|
1680 binop = op_sub_eq; |
3205
|
1681 break; |
|
1682 |
|
1683 default: |
|
1684 { |
3523
|
1685 std::string on = unary_op_as_string (op); |
3205
|
1686 error ("operator %s: no assign operator found", on.c_str ()); |
|
1687 } |
|
1688 } |
|
1689 |
|
1690 return binop; |
|
1691 } |
|
1692 |
3204
|
1693 octave_value::binary_op |
|
1694 octave_value::op_eq_to_binary_op (assign_op op) |
|
1695 { |
|
1696 binary_op binop = unknown_binary_op; |
|
1697 |
|
1698 switch (op) |
|
1699 { |
3533
|
1700 case op_add_eq: |
|
1701 binop = op_add; |
3204
|
1702 break; |
|
1703 |
3533
|
1704 case op_sub_eq: |
|
1705 binop = op_sub; |
3204
|
1706 break; |
|
1707 |
3533
|
1708 case op_mul_eq: |
|
1709 binop = op_mul; |
3204
|
1710 break; |
|
1711 |
3533
|
1712 case op_div_eq: |
|
1713 binop = op_div; |
3204
|
1714 break; |
|
1715 |
3533
|
1716 case op_ldiv_eq: |
|
1717 binop = op_ldiv; |
3204
|
1718 break; |
|
1719 |
4018
|
1720 case op_pow_eq: |
|
1721 binop = op_pow; |
|
1722 break; |
|
1723 |
3533
|
1724 case op_lshift_eq: |
|
1725 binop = op_lshift; |
3204
|
1726 break; |
|
1727 |
3533
|
1728 case op_rshift_eq: |
|
1729 binop = op_rshift; |
3204
|
1730 break; |
|
1731 |
3533
|
1732 case op_el_mul_eq: |
|
1733 binop = op_el_mul; |
3204
|
1734 break; |
|
1735 |
3533
|
1736 case op_el_div_eq: |
|
1737 binop = op_el_div; |
3204
|
1738 break; |
|
1739 |
3533
|
1740 case op_el_ldiv_eq: |
|
1741 binop = op_el_ldiv; |
3204
|
1742 break; |
|
1743 |
4018
|
1744 case op_el_pow_eq: |
|
1745 binop = op_el_pow; |
|
1746 break; |
|
1747 |
3533
|
1748 case op_el_and_eq: |
|
1749 binop = op_el_and; |
3204
|
1750 break; |
|
1751 |
3533
|
1752 case op_el_or_eq: |
|
1753 binop = op_el_or; |
3204
|
1754 break; |
|
1755 |
|
1756 default: |
|
1757 { |
3523
|
1758 std::string on = assign_op_as_string (op); |
3204
|
1759 error ("operator %s: no binary operator found", on.c_str ()); |
|
1760 } |
|
1761 } |
|
1762 |
|
1763 return binop; |
|
1764 } |
|
1765 |
3933
|
1766 octave_value |
|
1767 octave_value::empty_conv (const std::string& type, const octave_value& rhs) |
|
1768 { |
|
1769 octave_value retval; |
|
1770 |
|
1771 if (type.length () > 0) |
|
1772 { |
|
1773 switch (type[0]) |
|
1774 { |
|
1775 case '(': |
|
1776 { |
|
1777 if (type.length () > 1 && type[1] == '.') |
|
1778 retval = Octave_map (); |
|
1779 else |
|
1780 retval = octave_value (rhs.empty_clone ()); |
|
1781 } |
|
1782 break; |
|
1783 |
|
1784 case '{': |
|
1785 retval = Cell (); |
|
1786 break; |
|
1787 |
|
1788 case '.': |
|
1789 retval = Octave_map (); |
|
1790 break; |
|
1791 |
|
1792 default: |
|
1793 panic_impossible (); |
|
1794 } |
|
1795 } |
|
1796 else |
|
1797 retval = octave_value (rhs.empty_clone ()); |
|
1798 |
|
1799 return retval; |
|
1800 } |
|
1801 |
2376
|
1802 void |
|
1803 install_types (void) |
|
1804 { |
|
1805 octave_base_value::register_type (); |
3928
|
1806 octave_cell::register_type (); |
2376
|
1807 octave_scalar::register_type (); |
|
1808 octave_complex::register_type (); |
|
1809 octave_matrix::register_type (); |
|
1810 octave_complex_matrix::register_type (); |
|
1811 octave_range::register_type (); |
2825
|
1812 octave_bool::register_type (); |
|
1813 octave_bool_matrix::register_type (); |
2376
|
1814 octave_char_matrix::register_type (); |
|
1815 octave_char_matrix_str::register_type (); |
5279
|
1816 octave_char_matrix_sq_str::register_type (); |
4901
|
1817 octave_int8_scalar::register_type (); |
|
1818 octave_int16_scalar::register_type (); |
|
1819 octave_int32_scalar::register_type (); |
|
1820 octave_int64_scalar::register_type (); |
|
1821 octave_uint8_scalar::register_type (); |
|
1822 octave_uint16_scalar::register_type (); |
|
1823 octave_uint32_scalar::register_type (); |
|
1824 octave_uint64_scalar::register_type (); |
|
1825 octave_int8_matrix::register_type (); |
|
1826 octave_int16_matrix::register_type (); |
|
1827 octave_int32_matrix::register_type (); |
|
1828 octave_int64_matrix::register_type (); |
|
1829 octave_uint8_matrix::register_type (); |
|
1830 octave_uint16_matrix::register_type (); |
|
1831 octave_uint32_matrix::register_type (); |
|
1832 octave_uint64_matrix::register_type (); |
5164
|
1833 octave_sparse_bool_matrix::register_type (); |
|
1834 octave_sparse_matrix::register_type (); |
|
1835 octave_sparse_complex_matrix::register_type (); |
2376
|
1836 octave_struct::register_type (); |
2880
|
1837 octave_list::register_type (); |
3977
|
1838 octave_cs_list::register_type (); |
2376
|
1839 octave_magic_colon::register_type (); |
2974
|
1840 octave_builtin::register_type (); |
|
1841 octave_mapper::register_type (); |
|
1842 octave_user_function::register_type (); |
4649
|
1843 octave_dld_function::register_type (); |
4643
|
1844 octave_fcn_handle::register_type (); |
4966
|
1845 octave_fcn_inline::register_type (); |
4643
|
1846 octave_streamoff::register_type (); |
2376
|
1847 } |
|
1848 |
4970
|
1849 #if 0 |
|
1850 DEFUN (cast, args, , |
|
1851 "-*- texinfo -*-\n\ |
|
1852 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ |
|
1853 Convert @var{val} to the new data type @var{type}.\n\ |
5642
|
1854 @seealso{class, typeinfo}\n\ |
|
1855 @end deftypefn") |
4970
|
1856 { |
|
1857 octave_value retval; |
|
1858 |
|
1859 if (args.length () == 2) |
|
1860 error ("cast: not implemented"); |
|
1861 else |
5823
|
1862 print_usage (); |
4970
|
1863 |
|
1864 return retval; |
|
1865 } |
|
1866 #endif |
|
1867 |
4791
|
1868 DEFUN (sizeof, args, , |
|
1869 "-*- texinfo -*-\n\ |
|
1870 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ |
|
1871 Return the size of @var{val} in bytes\n\ |
|
1872 @end deftypefn") |
|
1873 { |
|
1874 octave_value retval; |
|
1875 |
|
1876 if (args.length () == 1) |
|
1877 retval = args(0).byte_size (); |
|
1878 else |
5823
|
1879 print_usage (); |
4791
|
1880 |
|
1881 return retval; |
|
1882 } |
|
1883 |
6153
|
1884 static void |
|
1885 decode_subscripts (const char* name, const octave_value& arg, |
|
1886 std::string& type_string, |
|
1887 std::list<octave_value_list>& idx) |
|
1888 { |
|
1889 Octave_map m = arg.map_value (); |
|
1890 |
|
1891 if (! error_state |
6639
|
1892 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153
|
1893 { |
|
1894 Cell& type = m.contents ("type"); |
|
1895 Cell& subs = m.contents ("subs"); |
|
1896 |
|
1897 type_string = std::string (type.length(), '\0'); |
|
1898 |
|
1899 for (int k = 0; k < type.length (); k++) |
|
1900 { |
|
1901 std::string item = type(k).string_value (); |
|
1902 |
|
1903 if (! error_state) |
|
1904 { |
|
1905 if (item == "{}") |
|
1906 type_string[k] = '{'; |
|
1907 else if (item == "()") |
|
1908 type_string[k] = '('; |
|
1909 else if (item == ".") |
|
1910 type_string[k] = '.'; |
|
1911 else |
|
1912 { |
|
1913 error("%s: invalid indexing type `%s'", name, item.c_str ()); |
|
1914 return; |
|
1915 } |
|
1916 } |
|
1917 else |
|
1918 { |
|
1919 error ("%s: expecting type(%d) to be a character string", |
|
1920 name, k+1); |
|
1921 return; |
|
1922 } |
|
1923 |
|
1924 octave_value_list idx_item; |
|
1925 |
|
1926 if (subs(k).is_string ()) |
|
1927 idx_item(0) = subs(k); |
|
1928 else if (subs(k).is_cell ()) |
|
1929 { |
|
1930 Cell subs_cell = subs(k).cell_value (); |
|
1931 |
|
1932 for (int n = 0; n < subs_cell.length (); n++) |
|
1933 { |
|
1934 if (subs_cell(n).is_string () |
|
1935 && subs_cell(n).string_value () == ":") |
|
1936 idx_item(n) = octave_value(octave_value::magic_colon_t); |
|
1937 else |
|
1938 idx_item(n) = subs_cell(n); |
|
1939 } |
|
1940 } |
|
1941 else |
|
1942 { |
|
1943 error ("%s: expecting subs(%d) to be a character string or cell array", |
|
1944 name, k+1); |
|
1945 return; |
|
1946 } |
|
1947 |
|
1948 idx.push_back (idx_item); |
|
1949 } |
|
1950 } |
|
1951 else |
|
1952 error ("%s: second argument must be a structure with fields `type' and `subs'", name); |
|
1953 } |
|
1954 |
|
1955 DEFUN (subsref, args, nargout, |
|
1956 "-*- texinfo -*-\n\ |
|
1957 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ |
|
1958 Perform the subscripted element selection operation according to\n\ |
|
1959 the subscript specified by @var{idx}.\n\ |
|
1960 \n\ |
|
1961 The subscript @var{idx} is expected to be a structure array with\n\ |
|
1962 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ |
6550
|
1963 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153
|
1964 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
|
1965 of index values.\n\ |
6631
|
1966 \n\ |
|
1967 The following example shows how to extract the two first columns of\n\ |
|
1968 a matrix\n\ |
|
1969 \n\ |
|
1970 @example\n\ |
|
1971 val = magic(3)\n\ |
|
1972 @result{} val = [ 8 1 6\n\ |
|
1973 3 5 7\n\ |
|
1974 4 9 2 ]\n\ |
|
1975 idx.type = \"()\";\n\ |
|
1976 idx.subs = @{\":\", 1:2@};\n\ |
|
1977 subsref(val, idx)\n\ |
|
1978 @result{} [ 8 1 \n\ |
|
1979 3 5 \n\ |
|
1980 4 9 ]\n\ |
|
1981 @end example\n\ |
|
1982 \n\ |
|
1983 @noindent\n\ |
|
1984 Note that this is the same as writing @code{val(:,1:2)}.\n\ |
6157
|
1985 @seealso{subsasgn, substruct}\n\ |
6153
|
1986 @end deftypefn") |
|
1987 { |
|
1988 octave_value_list retval; |
|
1989 |
|
1990 if (args.length () == 2) |
|
1991 { |
|
1992 std::string type; |
|
1993 std::list<octave_value_list> idx; |
|
1994 |
|
1995 decode_subscripts ("subsref", args(1), type, idx); |
|
1996 |
|
1997 if (! error_state) |
|
1998 retval = args(0).subsref (type, idx, nargout); |
|
1999 } |
|
2000 else |
|
2001 print_usage (); |
|
2002 |
|
2003 return retval; |
|
2004 } |
|
2005 |
|
2006 DEFUN (subsasgn, args, , |
|
2007 "-*- texinfo -*-\n\ |
|
2008 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ |
|
2009 Perform the subscripted assignment operation according to\n\ |
|
2010 the subscript specified by @var{idx}.\n\ |
|
2011 \n\ |
|
2012 The subscript @var{idx} is expected to be a structure array with\n\ |
|
2013 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ |
6248
|
2014 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153
|
2015 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
|
2016 of index values.\n\ |
6631
|
2017 \n\ |
|
2018 The following example shows how to set the two first columns of a\n\ |
|
2019 3-by-3 matrix to zero.\n\ |
|
2020 \n\ |
|
2021 @example\n\ |
|
2022 val = magic(3);\n\ |
|
2023 idx.type = \"()\";\n\ |
|
2024 idx.subs = @{\":\", 1:2@};\n\ |
|
2025 subsasgn (val, idx, 0)\n\ |
|
2026 @result{} [ 0 0 6\n\ |
|
2027 0 0 7\n\ |
|
2028 0 0 2 ]\n\ |
|
2029 @end example\n\ |
|
2030 \n\ |
|
2031 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ |
6157
|
2032 @seealso{subsref, substruct}\n\ |
6153
|
2033 @end deftypefn") |
|
2034 { |
|
2035 octave_value retval; |
|
2036 |
|
2037 if (args.length () == 3) |
|
2038 { |
|
2039 std::string type; |
|
2040 std::list<octave_value_list> idx; |
|
2041 |
|
2042 decode_subscripts ("subsasgn", args(1), type, idx); |
|
2043 |
|
2044 if (! error_state) |
|
2045 retval = args(0).subsasgn (type, idx, args(2)); |
|
2046 } |
|
2047 else |
|
2048 print_usage (); |
|
2049 |
|
2050 return retval; |
|
2051 } |
|
2052 |
2376
|
2053 /* |
|
2054 ;;; Local Variables: *** |
|
2055 ;;; mode: C++ *** |
|
2056 ;;; End: *** |
|
2057 */ |