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